Skip to content

Commit

Permalink
lib: add randomHash helper
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
boltzmannrain committed Dec 6, 2024
1 parent 9bb136e commit 893351c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions lib/deprecated/misc.nix
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ let
fakeHash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
fakeSha256 = "0000000000000000000000000000000000000000000000000000000000000000";
fakeSha512 = "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
randomHash = builtins.hashString "sha256" (builtins.readFile /proc/sys/kernel/random/uuid);

in

Expand All @@ -346,6 +347,7 @@ in
fakeHash
fakeSha256
fakeSha512
randomHash
foldArgs
getValue
ifEnable
Expand Down

0 comments on commit 893351c

Please sign in to comment.