From 9c6ccfcbc17736559181ca214e711bc493944e8a Mon Sep 17 00:00:00 2001 From: Nathan McCarty Date: Mon, 15 May 2023 16:47:00 -0400 Subject: [PATCH] Refactor dependency handling Also fix openssl and pkg-config not being included in the deps for the project --- flake.nix | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/flake.nix b/flake.nix index fd74290..280b040 100644 --- a/flake.nix +++ b/flake.nix @@ -69,13 +69,13 @@ rustc = rust; cargo = rust; }; + buildInputs = (sharedDeps system) ++ (with pkgs; [ openssl ]); + nativeBuildInputs = (sharedNativeDeps system) + ++ (with pkgs; [ pkg-config cmake ]); devBase = with pkgs; [ # Build tools - openssl - pkg-config rust-analyzer - cmake gnuplot # git tooling gitFull @@ -85,28 +85,29 @@ # Formatters nixfmt python311Packages.mdformat - ] ++ map (x: self.packages.${system}.${x}) rustPackageNames; + ] ++ buildInputs ++ nativeBuildInputs + ++ map (x: self.packages.${system}.${x}) rustPackageNames; in rec { # Main binary packages.${crateName} = naersk-lib.buildPackage { pname = "${crateName}"; - buildInputs = sharedDeps system; - nativeBuildInputs = sharedNativeDeps system; + inherit buildInputs; + inherit nativeBuildInputs; root = src; }; # binary + tests packages.tests.${crateName} = naersk-lib.buildPackage { pname = "${crateName}"; - buildInputs = sharedDeps system; - nativeBuildInputs = sharedNativeDeps system; + inherit buildInputs; + inherit nativeBuildInputs; root = src; doCheck = true; }; # Docs packages.docs.${crateName} = naersk-lib.buildPackage { pname = "${crateName}"; - buildInputs = sharedDeps system; - nativeBuildInputs = sharedNativeDeps system; + inherit buildInputs; + inherit nativeBuildInputs; root = src; dontBuild = true; doDoc = true; @@ -123,10 +124,10 @@ stdenv.mkDerivation { name = "format lint"; src = src; + inherit buildInputs; nativeBuildInputs = with pkgs; - [ rust-bin.stable.latest.default ] - ++ (sharedNativeDeps system); - buildInputs = sharedDeps system; + [ rust-bin.stable.latest.default ] ++ nativeBuildInputs; + dontConfigure = true; buildPhase = "cargo fmt -- --check"; installPhase = "mkdir -p $out; echo 'done'"; }; @@ -135,10 +136,10 @@ stdenv.mkDerivation { name = "audit lint"; src = src; + inherit buildInputs; nativeBuildInputs = with pkgs; - [ rust-bin.stable.latest.default cargo-audit ] - ++ (sharedNativeDeps system); - buildInputs = sharedDeps system; + [ rust-bin.stable.latest.default ] ++ nativeBuildInputs; + dontConfigure = true; buildPhase = '' export HOME=$TMP mkdir -p ~/.cargo @@ -151,8 +152,8 @@ clippy.${crateName} = naersk-lib.buildPackage { pname = "${crateName}"; root = src; - buildInputs = sharedDeps system; - nativeBuildInputs = sharedNativeDeps system; + inherit buildInputs; + inherit nativeBuildInputs; cargoTestCommands = (old: [ "cargo $cargo_options clippy" ]); doCheck = true; dontBuild = true; @@ -162,8 +163,8 @@ # Development environments devShell = pkgs.mkShell { inputsFrom = builtins.attrValues packages; - buildInputs = [ rust ] ++ devBase ++ (sharedDeps system) - ++ (sharedNativeDeps system); + buildInputs = [ rust ] ++ devBase ++ buildInputs + ++ nativeBuildInputs; }; });