Explicitly declare runtime dependencies in Nix package

pull/187/head
Joseph LaFreniere 9 months ago
parent 90c304238a
commit 2798b84408
No known key found for this signature in database
GPG Key ID: EE236AA0141EFCA3

@ -49,27 +49,46 @@
filter = pkgs.lib.cleanSourceFilter; filter = pkgs.lib.cleanSourceFilter;
}; };
buildInputs = with pkgs; nativeBuildInputs = pkgs.lib.optionals pkgs.stdenv.isDarwin [
[ ffmpeg imagemagick pandoc poppler_utils ripgrep tesseract ] # Additional darwin specific inputs can be set here
++ pkgs.lib.optionals pkgs.stdenv.isDarwin [ pkgs.libiconv
# Additional darwin specific inputs can be set here ];
pkgs.libiconv
]; runtimeInputs = with pkgs; [
ffmpeg
imagemagick
pandoc
poppler_utils
ripgrep
tesseract
zip
];
# Build *just* the cargo dependencies, so we can reuse # Build *just* the cargo dependencies, so we can reuse
# all of that work (e.g. via cachix) when running in CI # all of that work (e.g. via cachix) when running in CI
cargoArtifacts = craneLib.buildDepsOnly { inherit src buildInputs; }; cargoArtifacts =
craneLib.buildDepsOnly { inherit src nativeBuildInputs; };
# Build the actual crate itself, reusing the dependency # Build the actual crate itself, reusing the dependency
# artifacts from above. # artifacts from above.
rga = craneLib.buildPackage { inherit cargoArtifacts src buildInputs; }; rgaBinary = craneLib.buildPackage {
inherit cargoArtifacts src nativeBuildInputs;
buildInputs = runtimeInputs; # needed for tests
};
# Provide a shell script of the Rust binary plus runtime dependencies.
rga = pkgs.pkgs.writeShellApplication {
name = "rga";
text = ''rga "$@"'';
runtimeInputs = runtimeInputs ++ [ rgaBinary ];
};
pre-commit = pre-commit-hooks.lib."${system}".run; pre-commit = pre-commit-hooks.lib."${system}".run;
in { in {
# `nix flake check` # `nix flake check`
checks = { checks = {
# Build the crate as part of `nix flake check` for convenience # Build the crate as part of `nix flake check` for convenience
inherit rga; inherit rgaBinary;
# Run clippy (and deny all warnings) on the crate source, # Run clippy (and deny all warnings) on the crate source,
# again, resuing the dependency artifacts from above. # again, resuing the dependency artifacts from above.
@ -78,7 +97,7 @@
# we can block the CI if there are issues here, but not # we can block the CI if there are issues here, but not
# prevent downstream consumers from building our crate by itself. # prevent downstream consumers from building our crate by itself.
rga-clippy = craneLib.cargoClippy { rga-clippy = craneLib.cargoClippy {
inherit cargoArtifacts src buildInputs; inherit cargoArtifacts src;
cargoClippyExtraArgs = "--all-targets -- --deny warnings"; cargoClippyExtraArgs = "--all-targets -- --deny warnings";
}; };
@ -92,7 +111,8 @@
# Run tests with cargo-nextest. # Run tests with cargo-nextest.
rga-nextest = craneLib.cargoNextest { rga-nextest = craneLib.cargoNextest {
inherit cargoArtifacts src buildInputs; inherit cargoArtifacts src nativeBuildInputs;
buildInputs = runtimeInputs; # needed for tests
partitions = 1; partitions = 1;
partitionType = "count"; partitionType = "count";
}; };
@ -113,7 +133,7 @@
# `nix build` # `nix build`
packages = { packages = {
inherit rga; # `nix build .#rga` inherit rgaBinary rga;
default = rga; # `nix build` default = rga; # `nix build`
}; };
@ -124,7 +144,7 @@
devShells.default = craneLib.devShell { devShells.default = craneLib.devShell {
inherit (self.checks.${system}.pre-commit) shellHook; inherit (self.checks.${system}.pre-commit) shellHook;
inputsFrom = builtins.attrValues self.checks; inputsFrom = builtins.attrValues self.checks;
packages = buildInputs; packages = runtimeInputs ++ nativeBuildInputs;
}; };
}); });
} }

Loading…
Cancel
Save