refactor(tvix): assemble cragoDeps outputHashes from Cargo.nix

We already have these hashes accessible in the Cargo.nix file created
by cargo2nix, so there's no need to also manually maintain them here.

It removes one potential footgun I ran into while updating wu-manber to
a different rev, without updating it here.

Change-Id: I93932ac8ba55f83746ee38571b7740af2d49bbdf
Reviewed-on: https://cl.tvl.fyi/c/depot/+/9090
Autosubmit: flokli <flokli@flokli.de>
Tested-by: BuildkiteCI
Reviewed-by: raitobezarius <tvl@lahfa.xyz>
This commit is contained in:
Florian Klink 2023-08-19 16:46:36 +02:00 committed by flokli
parent bba7bbf820
commit 778bd6894b

View file

@ -1,21 +1,10 @@
# Nix helpers for projects under //tvix # Nix helpers for projects under //tvix
{ pkgs, depot, ... }: { pkgs, lib, depot, ... }:
let let
# crate override for crates that need protobuf # crate override for crates that need protobuf
protobufDep = prev: (prev.nativeBuildInputs or [ ]) ++ [ pkgs.protobuf ]; protobufDep = prev: (prev.nativeBuildInputs or [ ]) ++ [ pkgs.protobuf ];
# Cargo dependencies to be used with nixpkgs rustPlatform functions.
cargoDeps = pkgs.rustPlatform.importCargoLock {
lockFile = ./Cargo.lock;
outputHashes = {
"test-generator-0.3.0" = "08brp3qqa55hijc7xby3lam2cc84hvx1zzfqv6lj7smlczh8k32y";
"tonic-mock-0.1.0" = "0lwa03hpp0mxa6aa1zv5w68k61y4hccfm0q2ykyq392fwal8vb50";
"wu-manber-0.1.0" = "1zhk83lbq99xzyjwphv2qrb8f8qgfqwa5bbbvyzm0z0bljsjv0pd";
};
};
in
{
# Load the crate2nix crate tree. # Load the crate2nix crate tree.
crates = import ./Cargo.nix { crates = import ./Cargo.nix {
inherit pkgs; inherit pkgs;
@ -42,6 +31,26 @@ in
}; };
}; };
# Cargo dependencies to be used with nixpkgs rustPlatform functions.
cargoDeps = pkgs.rustPlatform.importCargoLock {
lockFile = ./Cargo.lock;
# Extract the hashes from `crates` / Cargo.nix, we already get them from cargo2nix.
# This returns an attribute set containing "${crateName}-${version}" as key,
# and the outputHash as value.
outputHashes = builtins.listToAttrs
(map
(crateName:
(lib.nameValuePair "${crateName}-${crates.internal.crates.${crateName}.version}" crates.internal.crates.${crateName}.src.outputHash)
) [
"test-generator"
"tonic-mock"
"wu-manber"
]);
};
in
{
inherit crates;
# Run crate2nix generate in the current working directory, then # Run crate2nix generate in the current working directory, then
# format the generated file with depotfmt. # format the generated file with depotfmt.
crate2nixGenerate = pkgs.writeShellScriptBin "crate2nix-generate" '' crate2nixGenerate = pkgs.writeShellScriptBin "crate2nix-generate" ''