From a82bd9137ee9ea02160e5f3bed696174003f576d Mon Sep 17 00:00:00 2001 From: Brian Olsen Date: Tue, 22 Jul 2025 17:14:42 +0200 Subject: [PATCH] chore: Refactor common cargo build derivations into own function This creates a mkCargoBuild function of the shared bits from clippy and rust-docs uses it for those targets. Change-Id: I44f9f2b319ea4ef1d1236feabdf726f0256d5d70 Reviewed-on: https://cl.snix.dev/c/snix/+/30647 Reviewed-by: Florian Klink Autosubmit: Brian Olsen Tested-by: besadii --- snix/default.nix | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/snix/default.nix b/snix/default.nix index d4a6bfb53..f175d4a3b 100644 --- a/snix/default.nix +++ b/snix/default.nix @@ -36,9 +36,22 @@ let ]; }; + mkCargoBuild = args: pkgs.stdenv.mkDerivation ({ + inherit cargoDeps src; + PROTO_ROOT = protos; + SNIX_BUILD_SANDBOX_SHELL = "/homeless-shelter"; + + nativeBuildInputs = with pkgs; [ + cargo + pkg-config + protobuf + rustc + rustPlatform.cargoSetupHook + ] ++ (args.nativeBuildInputs or [ ]); + } // (pkgs.lib.removeAttrs args [ "nativeBuildInputs" ])); in { - inherit crates protos; + inherit crates protos mkCargoBuild; # Provide the snix logo in both .webp and .png format. logo = pkgs.runCommand "logo" @@ -63,19 +76,8 @@ in shell-integration = (import ./shell.nix { inherit pkgs; withIntegration = true; }); # Build the Rust documentation for publishing on snix.dev/rustdoc. - rust-docs = pkgs.stdenv.mkDerivation { - inherit cargoDeps src; + rust-docs = mkCargoBuild { name = "snix-rust-docs"; - PROTO_ROOT = protos; - SNIX_BUILD_SANDBOX_SHELL = "/homeless-shelter"; - - nativeBuildInputs = with pkgs; [ - cargo - pkg-config - protobuf - rustc - rustPlatform.cargoSetupHook - ]; buildInputs = [ pkgs.fuse @@ -89,22 +91,15 @@ in # Run cargo clippy. We run it with -Dwarnings, so warnings cause a nonzero # exit code. - clippy = pkgs.stdenv.mkDerivation { - inherit cargoDeps src; + clippy = mkCargoBuild { name = "snix-clippy"; - PROTO_ROOT = protos; - SNIX_BUILD_SANDBOX_SHELL = "/homeless-shelter"; buildInputs = [ pkgs.fuse ]; + nativeBuildInputs = with pkgs; [ - cargo clippy - pkg-config - protobuf - rustc - rustPlatform.cargoSetupHook ]; buildPhase = "cargo clippy --tests --all-features --benches --examples -- -Dwarnings | tee $out";