Skip to content

Instantly share code, notes, and snippets.

@danieldk
Last active October 1, 2021 20:02
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danieldk/d8c7791d0074ce2227420e3754bf4a05 to your computer and use it in GitHub Desktop.
Save danieldk/d8c7791d0074ce2227420e3754bf4a05 to your computer and use it in GitHub Desktop.
Rough procedure for updating all cargoSha256/cargoHash
Rough procedure for updating cargo hashes. Warning: this still requires a lot
of manual work to cover all bases. Based on:
https://github.com/NixOS/nixpkgs/pull/112764/commits/2650d5d2b8c19844224f8b368887153e2f18fdae
# Invalidate all hashes
rg -l "cargoHash" | grep "\.nix" | xargs -n1 sed -i -re 's/cargoHash = "..../cargoHash = "sha256-1234/g'
rg -l "cargoSha256" | grep "\.nix" | xargs -n1 sed -i -re 's/cargoSha256 = "[^s].../cargoSha256 = "1234/g'
rg -l "cargoSha256" | grep "\.nix" | xargs -n1 sed -i -re 's/cargoSha256 = "sha256-..../cargoSha256 = "sha256-1234/g'
# Rebuild, logging hash mismatches
nix-build -k -E '
let pkgs = import ./. {};
in with builtins; with pkgs.lib;
mapAttrs (n: v: v.cargoDeps) (filterAttrs (n: v:
(tryEval v).success && isDerivation v &&
hasAttr "cargoDeps" v.drvAttrs && v.drvAttrs.cargoDeps != null
) pkgs)' |& tee /tmp/build-cargoDepsAttrs
# Update hashes
awk '
BEGIN {print "rg -l \"(cargoSha256|cargoHash)\" pkgs | grep \"\\.nix\" | xargs sed -i \\"}
/specified: sha256-/ {wanted=$2}
/got: sha256-/ {
wantedNoPrefix=wanted
sub(/sha256-/, "", wantedNoPrefix)
#printf("-e \"s|%s|%s|\"",wantedNoPrefix,$2);
printf(" -e \"s|%s|%s|\"",wanted,$2);
system("wanted=`nix hash to-base32 --type sha256 " wanted "`; \
got=`nix hash to-base32 --type sha256 " $2 "`; \
echo \" -e \\\"s|$wanted|$got|\\\" \\\\\"");
}' /tmp/build-cargoDepsAttrs > /tmp/updateCargoDeps
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment