Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion tools.nix
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ rec {
cp ${vendor.cargoConfig} $out/cargo/config

crate_hashes="$out/crate-hashes.json"
echo -n '${builtins.toJSON vendor.extendedHashes}' | jq > "$crate_hashes"
echo -n '${builtins.toJSON vendor.extendedHashes'}' | jq > "$crate_hashes"
# Remove last trailing newline, which crate2nix doesn't (yet) include
truncate -s -1 "$crate_hashes"

Expand Down Expand Up @@ -244,6 +244,14 @@ rec {
, hashes ? { }
}:
rec {
packageIdsFile = pkgs.runCommand "package-ids" { nativeBuildInputs = with pkgs; [ cargo jq ]; } ''
mkdir -p "$out/cargo"
export CARGO_HOME=$out/cargo
cp ${cargoConfig} $out/cargo/config
cargo metadata --manifest-path ${crateDir}/Cargo.toml --locked --offline --format-version 1 | jq -r > $out/cargo-metadata.json
'';
packageIds = builtins.listToAttrs (builtins.map ({ name, version, source, id, ... }@package: { name = toPackageId package; value = id; }) (builtins.filter (p: p.source != null) (builtins.fromJSON (builtins.unsafeDiscardStringContext (builtins.readFile "${packageIdsFile}/cargo-metadata.json"))).packages));

toPackageId = { name, version, source, ... }:
"${name} ${version} (${source})";

Expand Down Expand Up @@ -289,6 +297,11 @@ rec {
extendedHashes = hashes
// builtins.listToAttrs (map mkGitHash (packagesByType.git or [ ]));

extendedHashes' = builtins.listToAttrs (builtins.map
(nixId: { name = builtins.getAttr nixId packageIds; value = builtins.getAttr nixId extendedHashes; })
(builtins.attrNames extendedHashes)
);

packages =
let
packagesWithDuplicates = assert builtins.isList locked.package; locked.package;
Expand Down