From 778bd6894ba555d04a29ac01486d571a1299d0e3 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Sat, 19 Aug 2023 16:46:36 +0200 Subject: 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 Tested-by: BuildkiteCI Reviewed-by: raitobezarius --- tvix/default.nix | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) (limited to 'tvix/default.nix') diff --git a/tvix/default.nix b/tvix/default.nix index 12aabc9ded..66d4a79d99 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" '' -- cgit 1.4.1