Loading lib/fetchers.nix +30 −23 Original line number Diff line number Diff line Loading @@ -66,14 +66,20 @@ rec { normalizeHash = { hashTypes ? [ "sha256" ], required ? true, }: args: with builtins; with lib; }: let hNames = [ "hash" ] ++ hashTypes; hAttrs = genAttrs hNames (const {}); in with builtins; with lib; args: if args ? "outputHash" then args else let # The argument hash, as a {name, value} pair h = let _h = attrsToList (intersectAttrs (genAttrs hNames (const {})) args); in let _h = attrsToList (intersectAttrs hAttrs args); in if _h == [] then throwIf required "fetcher called without `hash`" null else if tail _h != [] then Loading @@ -82,9 +88,6 @@ rec { head _h ; in if args ? "outputHash" then args else removeAttrs args hNames // (optionalAttrs (h != null) { outputHash = h.value; outputHashAlgo = if h.name == "hash" then null else h.name; Loading Loading @@ -148,13 +151,17 @@ rec { let hAttrs = genAttrs ([ "hash" ] ++ hashTypes) (const {}); fArgs = functionArgs fetcher; normalize = normalizeHash { inherit hashTypes; required = !fArgs.outputHash; }; in # The o.g. fetcher must *only* accept outputHash and outputHashAlgo assert fArgs ? outputHash && fArgs ? outputHashAlgo; assert intersectAttrs fArgs hAttrs == {}; setFunctionArgs (args: fetcher (normalizeHash { inherit hashTypes required; } args)) (removeAttrs fArgs [ "outputHash" "outputHashAlgo" ] // { hash = !required; }); (args: fetcher (normalize args)) (removeAttrs fArgs [ "outputHash" "outputHashAlgo" ] // { hash = fArgs.outputHash; }); } Loading
lib/fetchers.nix +30 −23 Original line number Diff line number Diff line Loading @@ -66,14 +66,20 @@ rec { normalizeHash = { hashTypes ? [ "sha256" ], required ? true, }: args: with builtins; with lib; }: let hNames = [ "hash" ] ++ hashTypes; hAttrs = genAttrs hNames (const {}); in with builtins; with lib; args: if args ? "outputHash" then args else let # The argument hash, as a {name, value} pair h = let _h = attrsToList (intersectAttrs (genAttrs hNames (const {})) args); in let _h = attrsToList (intersectAttrs hAttrs args); in if _h == [] then throwIf required "fetcher called without `hash`" null else if tail _h != [] then Loading @@ -82,9 +88,6 @@ rec { head _h ; in if args ? "outputHash" then args else removeAttrs args hNames // (optionalAttrs (h != null) { outputHash = h.value; outputHashAlgo = if h.name == "hash" then null else h.name; Loading Loading @@ -148,13 +151,17 @@ rec { let hAttrs = genAttrs ([ "hash" ] ++ hashTypes) (const {}); fArgs = functionArgs fetcher; normalize = normalizeHash { inherit hashTypes; required = !fArgs.outputHash; }; in # The o.g. fetcher must *only* accept outputHash and outputHashAlgo assert fArgs ? outputHash && fArgs ? outputHashAlgo; assert intersectAttrs fArgs hAttrs == {}; setFunctionArgs (args: fetcher (normalizeHash { inherit hashTypes required; } args)) (removeAttrs fArgs [ "outputHash" "outputHashAlgo" ] // { hash = !required; }); (args: fetcher (normalize args)) (removeAttrs fArgs [ "outputHash" "outputHashAlgo" ] // { hash = fArgs.outputHash; }); }