fetchipfs: simplify, error-out when given multiple hashes

Also dropped the `md5` attribute, as `stdenv.mkDerivation` rejects
MD5 since last year (87c22100a6)
This commit is contained in:
nicoo 2024-09-16 18:13:39 +00:00
parent 30361c578f
commit 7c19bb37a3
2 changed files with 32 additions and 48 deletions

View File

@ -1,40 +1,25 @@
{ stdenv { lib
, stdenv
, curl , curl
}: }:
lib.fetchers.withNormalizedHash { hashTypes = [ "sha1" "sha256" "sha512" ]; } (
{ ipfs { ipfs
, url ? "" , url ? ""
, curlOpts ? "" , curlOpts ? ""
, outputHash ? "" , outputHash
, outputHashAlgo ? "" , outputHashAlgo
, md5 ? ""
, sha1 ? ""
, sha256 ? ""
, sha512 ? ""
, meta ? {} , meta ? {}
, port ? "8080" , port ? "8080"
, postFetch ? "" , postFetch ? ""
, preferLocalBuild ? true , preferLocalBuild ? true
}: }:
stdenv.mkDerivation {
let
hasHash = (outputHash != "" && outputHashAlgo != "")
|| md5 != "" || sha1 != "" || sha256 != "" || sha512 != "";
in
if (!hasHash) then throw "Specify sha for fetchipfs fixed-output derivation" else stdenv.mkDerivation {
name = ipfs; name = ipfs;
builder = ./builder.sh; builder = ./builder.sh;
nativeBuildInputs = [ curl ]; nativeBuildInputs = [ curl ];
# New-style output content requirements. # New-style output content requirements.
outputHashAlgo = if outputHashAlgo != "" then outputHashAlgo else inherit outputHash outputHashAlgo;
if sha512 != "" then "sha512" else if sha256 != "" then "sha256" else if sha1 != "" then "sha1" else "md5";
outputHash = if outputHash != "" then outputHash else
if sha512 != "" then sha512 else if sha256 != "" then sha256 else if sha1 != "" then sha1 else md5;
outputHashMode = "recursive"; outputHashMode = "recursive";
inherit curlOpts inherit curlOpts
@ -48,3 +33,4 @@ if (!hasHash) then throw "Specify sha for fetchipfs fixed-output derivation" els
# traffic, so don't do that. # traffic, so don't do that.
inherit preferLocalBuild; inherit preferLocalBuild;
} }
)

View File

@ -1141,9 +1141,7 @@ with pkgs;
fetchRepoProject = callPackage ../build-support/fetchrepoproject { }; fetchRepoProject = callPackage ../build-support/fetchrepoproject { };
fetchipfs = import ../build-support/fetchipfs { fetchipfs = callPackage ../build-support/fetchipfs { };
inherit curl stdenv;
};
fetchit = callPackage ../applications/networking/cluster/fetchit { }; fetchit = callPackage ../applications/networking/cluster/fetchit { };