lib.fetchers.normalizeHash: replace "" with lib.fake*

This commit is contained in:
nicoo 2024-09-17 07:18:39 +00:00
parent 4e59b77c70
commit 4c991b74d3

View File

@ -5,6 +5,12 @@ let
hNames = [ "hash" ] ++ hashTypes;
hAttrs = lib.genAttrs hNames (lib.const {});
};
fakeH = {
hash = lib.fakeHash;
sha256 = lib.fakeSha256;
sha512 = lib.fakeSha512;
};
in rec {
proxyImpureEnvVars = [
@ -23,12 +29,15 @@ in rec {
Converts an attrset containing one of `hash`, `sha256` or `sha512`,
into one containing `outputHash{,Algo}` as accepted by `mkDerivation`.
An appropriate fake hash is substituted when the hash value is `""`,
as is the [convention for fetchers](#sec-pkgs-fetchers-updating-source-hashes-fakehash-method).
All other attributes in the set remain as-is.
# Example
```nix
normalizeHash { } { hash = lib.fakeHash; foo = "bar"; }
normalizeHash { } { hash = ""; foo = "bar"; }
=>
{
outputHash = lib.fakeHash;
@ -95,8 +104,12 @@ in rec {
;
in
removeAttrs args hNames // (optionalAttrs (h != null) {
outputHash = h.value;
outputHashAlgo = if h.name == "hash" then null else h.name;
outputHash =
if h.value == "" then
fakeH.${h.name} or (throw "no fake hash defined for ${h.name}")
else
h.value;
})
;