about summary refs log tree commit diff
path: root/tvix/default.nix
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2023-08-19T14·46+0200
committerflokli <flokli@flokli.de>2023-08-20T22·42+0000
commit778bd6894ba555d04a29ac01486d571a1299d0e3 (patch)
treeac9637eb911e2834a4463b1d75054aae726f6af7 /tvix/default.nix
parentbba7bbf820d64d4d46e75dd590d0cf04e648ac41 (diff)
refactor(tvix): assemble cragoDeps outputHashes from Cargo.nix r/6514
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>
Diffstat (limited to 'tvix/default.nix')
-rw-r--r--tvix/default.nix33
1 files changed, 21 insertions, 12 deletions
diff --git a/tvix/default.nix b/tvix/default.nix
index 12aabc9ded57..66d4a79d993a 100644
--- a/tvix/default.nix
+++ b/tvix/default.nix
@@ -1,21 +1,10 @@
 # Nix helpers for projects under //tvix
-{ pkgs, depot, ... }:
+{ pkgs, lib, depot, ... }:
 
 let
   # crate override for crates that need 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.
   crates = import ./Cargo.nix {
     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
   # format the generated file with depotfmt.
   crate2nixGenerate = pkgs.writeShellScriptBin "crate2nix-generate" ''