diff options
Diffstat (limited to 'src/x509-info/flake.nix')
| -rw-r--r-- | src/x509-info/flake.nix | 85 |
1 files changed, 61 insertions, 24 deletions
diff --git a/src/x509-info/flake.nix b/src/x509-info/flake.nix index 0dbaee0..6061f08 100644 --- a/src/x509-info/flake.nix +++ b/src/x509-info/flake.nix @@ -4,53 +4,89 @@ inputs = { flake-utils.url = "github:numtide/flake-utils"; nixpkgs.url = "github:NixOS/nixpkgs"; - rust-overlay.url = "github:oxalica/rust-overlay"; - naersk.url = "github:nmattia/naersk"; + rust-overlay = { + url = "github:oxalica/rust-overlay"; + inputs = { + flake-utils.follows = "flake-utils"; + nixpkgs.follows = "nixpkgs"; + }; + }; + pre-commit-hooks = { + url = "github:cachix/pre-commit-hooks.nix"; + inputs = { + flake-utils.follows = "flake-utils"; + nixpkgs.follows = "nixpkgs"; + }; + }; }; outputs = { self , flake-utils , nixpkgs - , naersk , rust-overlay + , pre-commit-hooks }: + let + # Borrow project metadata from the Rust config + meta = (builtins.fromTOML (builtins.readFile ./Cargo.toml)).package; + inherit (meta) name version; + overlays = [ + # Rust helpers + (import rust-overlay) + # Build Rust toolchain using helpers from rust-overlay + (self: super: { + # This supplies cargo, rustc, rustfmt, etc. + rustToolchain = super.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; + }) + ]; + in flake-utils.lib.eachDefaultSystem (system: let - overlays = [ (import rust-overlay) ]; - pkgs = import nixpkgs { inherit system overlays; }; - rust-toolchain = - (pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml).override { - extensions = [ "rust-src" ]; - }; - naersk-lib = naersk.lib."${system}".override { - rustc = rust-toolchain; - }; + pkgs = import nixpkgs { inherit overlays system; }; in - rec { - packages.x509-info = naersk-lib.buildPackage { - pname = "x509-info"; - root = ./.; - buildInputs = with pkgs; [ ]; + packages = rec { + default = x509-info; + x509-info = pkgs.rustPlatform.buildRustPackage { + pname = name; + inherit version; + src = ./.; + release = true; + cargoLock.lockFile = ./Cargo.lock; + }; }; - defaultPackage = packages.x509-info; + checks = { + pre-commit = pre-commit-hooks.lib.${system}.run { + src = ./.; + hooks = { + clippy = { + enable = true; + entry = pkgs.lib.mkForce "cargo clippy -- -D warnings"; + }; + nixpkgs-fmt = { + enable = true; + }; + rustfmt = { + enable = true; + entry = pkgs.lib.mkForce "cargo fmt -- --check --color always"; + }; + }; + }; + }; devShell = pkgs.mkShell { nativeBuildInputs = with pkgs; [ - rust-toolchain + rustToolchain cargo-audit cargo-deny - cargo-cross rust-analyzer - ] ++ pkgs.lib.optionals (pkgs.stdenv.isLinux) (with pkgs; [ cargo-watch ]); + ]; - shellHook = '' - cargo --version - ''; + inherit (self.checks.${system}.pre-commit) shellHook; }; }) // { @@ -59,3 +95,4 @@ }; }; } + |
