Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
buildRustPackage: add cargoCopyLockfile option
When enabled, it allows to check whenever the cargoSha256 needs updating
or not. This technique depends on IFS and is not allowed inside of
nixpkgs but it's handy to have available. Eg:

    let
      pkg = buildRustPackage { ... };
      srcContent = builtins.readFile "${pkg.src}/Cargo.lock";
      depsContent = builtins.readFile "${pkgs.cargoDeps}/Cargo.lock";
    in
      # this will fail when the cargoSha256 gets out of sync
      assert (srcContent == depsContent);
      pkg
  • Loading branch information
zimbatm committed Aug 24, 2019
1 parent b240871 commit 0a51b5b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions pkgs/build-support/rust/default.nix
Expand Up @@ -11,6 +11,7 @@
, buildInputs ? []
, nativeBuildInputs ? []
, cargoUpdateHook ? ""
, cargoCopyLockfile ? false
, cargoDepsHook ? ""
, cargoBuildFlags ? []
, buildType ? "release"
Expand All @@ -26,6 +27,7 @@ let
cargoDeps = if cargoVendorDir == null
then fetchcargo {
inherit name src srcs sourceRoot cargoUpdateHook;
copyLockfile = cargoCopyLockfile;
patches = cargoPatches;
sha256 = cargoSha256;
}
Expand Down
15 changes: 14 additions & 1 deletion pkgs/build-support/rust/fetchcargo.nix
Expand Up @@ -17,7 +17,16 @@ let cargo-vendor-normalise = stdenv.mkDerivation {
preferLocalBuild = true;
};
in
{ name ? "cargo-deps", src, srcs, patches, sourceRoot, sha256, cargoUpdateHook ? "" }:
{ name ? "cargo-deps"
, src
, srcs
, patches
, sourceRoot
, sha256
, cargoUpdateHook ? ""
, # whenever to also include the Cargo.lock in the output
copyLockfile ? false
}:
stdenv.mkDerivation {
name = "${name}-vendor";
nativeBuildInputs = [ cacert cargo-vendor git cargo-vendor-normalise cargo ];
Expand Down Expand Up @@ -52,6 +61,10 @@ stdenv.mkDerivation {
if ! cmp $CARGO_CONFIG ${./fetchcargo-default-config.toml} > /dev/null; then
install -D $CARGO_CONFIG $out/.cargo/config;
fi;
'' + lib.optionalString copyLockfile ''
# add the Cargo.lock to allow hash invalidation
cp Cargo.lock $out/Cargo.lock
'';

outputHashAlgo = "sha256";
Expand Down

0 comments on commit 0a51b5b

Please sign in to comment.