From 913ca065126624aa17f5a03fb76c592ae9cb46a8 Mon Sep 17 00:00:00 2001 From: Nikolaos Karaolidis Date: Tue, 14 Oct 2025 23:42:18 +0100 Subject: [PATCH] chore: add flake Signed-off-by: Nikolaos Karaolidis --- .envrc | 2 +- .gitignore | 10 ++++++ flake.lock | 72 +++++++++++++++++++++++++++++++++++++++++ flake.nix | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++++ treefmt.nix | 15 +++++++++ 5 files changed, 190 insertions(+), 1 deletion(-) create mode 100644 flake.lock create mode 100755 flake.nix create mode 100755 treefmt.nix diff --git a/.envrc b/.envrc index 481a7b6..3550a30 100644 --- a/.envrc +++ b/.envrc @@ -1 +1 @@ -use flake self#rust +use flake diff --git a/.gitignore b/.gitignore index 0b188bc..83b4608 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,13 @@ target/ # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ + +# ---> Nix +# Ignore build outputs from performing a nix-build or `nix build` command +result +result-* + +# Ignore automatically generated direnv output +.direnv + +.cargo/ diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..8015687 --- /dev/null +++ b/flake.lock @@ -0,0 +1,72 @@ +{ + "nodes": { + "lib": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ], + "treefmt-nix": [ + "treefmt-nix" + ] + }, + "locked": { + "lastModified": 1758632667, + "narHash": "sha256-C0aBPv8vqTI1QNVhygZxL0f49UERx2UejVdtyz67jhs=", + "ref": "refs/heads/main", + "rev": "5e0737c20f3c265dbff604170a6433cc1e1a4b41", + "revCount": 8, + "type": "git", + "url": "https://git.karaolidis.com/karaolidis/nix-lib.git" + }, + "original": { + "type": "git", + "url": "https://git.karaolidis.com/karaolidis/nix-lib.git" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1760284886, + "narHash": "sha256-TK9Kr0BYBQ/1P5kAsnNQhmWWKgmZXwUQr4ZMjCzWf2c=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "cf3f5c4def3c7b5f1fc012b3d839575dbe552d43", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "lib": "lib", + "nixpkgs": "nixpkgs", + "treefmt-nix": "treefmt-nix" + } + }, + "treefmt-nix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1760120816, + "narHash": "sha256-gq9rdocpmRZCwLS5vsHozwB6b5nrOBDNc2kkEaTXHfg=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "761ae7aff00907b607125b2f57338b74177697ed", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100755 index 0000000..d2703eb --- /dev/null +++ b/flake.nix @@ -0,0 +1,92 @@ +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + + treefmt-nix = { + url = "github:numtide/treefmt-nix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + + lib = { + # FIXME: https://github.com/NixOS/nix/issues/12281 + url = "git+https://git.karaolidis.com/karaolidis/nix-lib.git"; + inputs = { + nixpkgs.follows = "nixpkgs"; + treefmt-nix.follows = "treefmt-nix"; + }; + }; + }; + + outputs = + inputs: + { + overlays.default = + final: prev: + let + pkgs = final; + in + { + fujicli = pkgs.rustPlatform.buildRustPackage { + pname = "fujicli"; + version = "0.1.0"; + + src = ./.; + cargoLock.lockFile = ./Cargo.lock; + }; + }; + } + // ( + let + system = "x86_64-linux"; + + pkgs = import inputs.nixpkgs { + inherit system; + config.allowUnfree = true; + overlays = [ + inputs.lib.overlays.default + inputs.self.overlays.default + ]; + }; + + treefmt = inputs.treefmt-nix.lib.evalModule pkgs ./treefmt.nix; + in + { + devShells.${system}.default = pkgs.mkShell { + packages = with pkgs; [ + cargo + rustc + rustfmt + clippy + cargo-udeps + cargo-outdated + ]; + + shellHook = '' + TOP="$(git rev-parse --show-toplevel)" + export CARGO_HOME="$TOP/.cargo" + ''; + }; + + packages.${system} = with pkgs; { + default = fujicli; + inherit fujicli; + }; + + formatter.${system} = treefmt.config.build.wrapper; + + checks.${system} = + let + packages = pkgs.lib.mapAttrs' ( + name: pkgs.lib.nameValuePair "package-${name}" + ) inputs.self.packages.${system}; + + devShells = pkgs.lib.mapAttrs' ( + name: pkgs.lib.nameValuePair "devShell-${name}" + ) inputs.self.devShells.${system}; + + formatter.formatting = treefmt.config.build.check inputs.self; + in + packages // devShells // formatter; + } + ); +} diff --git a/treefmt.nix b/treefmt.nix new file mode 100755 index 0000000..c896556 --- /dev/null +++ b/treefmt.nix @@ -0,0 +1,15 @@ +{ ... }: +{ + projectRootFile = "flake.nix"; + + programs = { + nixfmt = { + enable = true; + strict = true; + }; + + rustfmt.enable = true; + }; + + settings.global.excludes = [ ".envrc" ]; +}