From 893351cc6b753290ca6d95ca32d7de77332108b4 Mon Sep 17 00:00:00 2001 From: Dmitry Ivankov Date: Sat, 7 Dec 2024 00:01:08 +0100 Subject: [PATCH] lib: add randomHash helper Similar to `lib.fakeHash` but value is different each time. This is useful to avoid locking when rebuilding multiple packages and/or for multiple architectures. With `lib.fakeHash` multiple `FOD` builds on same machine would assume that output with `fakeHash` can be produced so only one `FOD` build at a time would be allowed to save efforts `_if_` all those builds would produce same output with `fakeHash`. But actual reason to use `fakeHash` is letting the build fail and produce hash mismatch error with real hash value, so it makes more sense to let all fake hash FODs be different Randomness code is partially borrowed from https://github.com/figsoda/rand-nix/blob/main/default.nix Admittedly this is a little ugly, but if only used during local rebuilds might be good enough. --- lib/default.nix | 2 +- lib/deprecated/misc.nix | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/default.nix b/lib/default.nix index 5b742b195d340..22906e53d55cc 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -169,7 +169,7 @@ let mergeAttrsWithFunc mergeAttrsConcatenateValues mergeAttrsNoOverride mergeAttrByFunc mergeAttrsByFuncDefaults mergeAttrsByFuncDefaultsClean mergeAttrBy - fakeHash fakeSha256 fakeSha512 + fakeHash fakeSha256 fakeSha512 randomHash nixType imap; inherit (self.versions) splitVersion; diff --git a/lib/deprecated/misc.nix b/lib/deprecated/misc.nix index 34d1c01ce811a..a4c5b9d4bfb84 100644 --- a/lib/deprecated/misc.nix +++ b/lib/deprecated/misc.nix @@ -329,6 +329,7 @@ let fakeHash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="; fakeSha256 = "0000000000000000000000000000000000000000000000000000000000000000"; fakeSha512 = "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"; + randomHash = builtins.hashString "sha256" (builtins.readFile /proc/sys/kernel/random/uuid); in @@ -346,6 +347,7 @@ in fakeHash fakeSha256 fakeSha512 + randomHash foldArgs getValue ifEnable