Skip to content

Commit

Permalink
nix: Improve flexibility of Cargo lockfile vendoring
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Spinale <nick@nickspinale.com>
  • Loading branch information
nspin committed Jun 5, 2024
1 parent 3d75402 commit 04da55d
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions hacking/nix/rust-utils/vendor-lockfile.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,21 @@
, buildPackages
, fetchurl
, jq
, toTOMLFile
, defaultRustToolchain
}:

{ rustToolchain ? defaultRustToolchain
, lockfileContents ? null
, lockfileValue ? if lockfileContents == null then null else builtins.fromTOML lockfileContents
, lockfileContents ? if lockfile == null then null else builtins.readFile lockfile
, lockfile ? null
, fetchGitSubmodules ? false
, extraMkCrateTarballURLFns ? {}
} @ args:

assert lockfileContents != null || lockfile != null;
assert lockfileValue != null;

let
lockfileContents =
if lockfile != null
then builtins.readFile lockfile
else args.lockfileContents;

lockfileValue = builtins.fromTOML lockfileContents;

packages =
# TODO enforce?
# assert lockfileValue.version == 3;
Expand Down Expand Up @@ -213,8 +208,18 @@ let
printf '{"files": {}, "package": null}' > "$out/.cargo-checksum.json"
'';

in {
lockfile = if lockfile != null then lockfile else builtins.toFile "Cargo.lock" lockfileContents;
inherit lockfileValue;
in lib.fix (self: {
configFragment = vendoredSources;
}
inherit lockfileValue;
lockfile =
let
fname = "Cargo.lock";
in
if lockfile != null
then lockfile
else (
if lockfileContents != null
then builtins.toFile fname lockfileContents
else toTOMLFile fname lockfileValue
);
})

0 comments on commit 04da55d

Please sign in to comment.