From 7c19bb37a30e1601543b104f78ef6079a465e2c3 Mon Sep 17 00:00:00 2001 From: nicoo Date: Mon, 16 Sep 2024 18:13:39 +0000 Subject: [PATCH] fetchipfs: simplify, error-out when given multiple hashes Also dropped the `md5` attribute, as `stdenv.mkDerivation` rejects MD5 since last year (87c22100a6892b864ff94476f2965a793d8e4282) --- pkgs/build-support/fetchipfs/default.nix | 76 ++++++++++-------------- pkgs/top-level/all-packages.nix | 4 +- 2 files changed, 32 insertions(+), 48 deletions(-) diff --git a/pkgs/build-support/fetchipfs/default.nix b/pkgs/build-support/fetchipfs/default.nix index 0cbb094d6003..da94200206ba 100644 --- a/pkgs/build-support/fetchipfs/default.nix +++ b/pkgs/build-support/fetchipfs/default.nix @@ -1,50 +1,36 @@ -{ stdenv +{ lib +, stdenv , curl }: +lib.fetchers.withNormalizedHash { hashTypes = [ "sha1" "sha256" "sha512" ]; } ( + { ipfs + , url ? "" + , curlOpts ? "" + , outputHash + , outputHashAlgo + , meta ? {} + , port ? "8080" + , postFetch ? "" + , preferLocalBuild ? true + }: + stdenv.mkDerivation { + name = ipfs; + builder = ./builder.sh; + nativeBuildInputs = [ curl ]; -{ ipfs -, url ? "" -, curlOpts ? "" -, outputHash ? "" -, outputHashAlgo ? "" -, md5 ? "" -, sha1 ? "" -, sha256 ? "" -, sha512 ? "" -, meta ? {} -, port ? "8080" -, postFetch ? "" -, preferLocalBuild ? true -}: + # New-style output content requirements. + inherit outputHash outputHashAlgo; + outputHashMode = "recursive"; -let + inherit curlOpts + postFetch + ipfs + url + port + meta; - hasHash = (outputHash != "" && outputHashAlgo != "") - || md5 != "" || sha1 != "" || sha256 != "" || sha512 != ""; - -in - -if (!hasHash) then throw "Specify sha for fetchipfs fixed-output derivation" else stdenv.mkDerivation { - name = ipfs; - builder = ./builder.sh; - nativeBuildInputs = [ curl ]; - - # New-style output content requirements. - outputHashAlgo = if outputHashAlgo != "" then outputHashAlgo else - 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"; - - inherit curlOpts - postFetch - ipfs - url - port - meta; - - # Doing the download on a remote machine just duplicates network - # traffic, so don't do that. - inherit preferLocalBuild; -} + # Doing the download on a remote machine just duplicates network + # traffic, so don't do that. + inherit preferLocalBuild; + } +) diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 9f5a5ece5be8..8c78ce887896 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -1141,9 +1141,7 @@ with pkgs; fetchRepoProject = callPackage ../build-support/fetchrepoproject { }; - fetchipfs = import ../build-support/fetchipfs { - inherit curl stdenv; - }; + fetchipfs = callPackage ../build-support/fetchipfs { }; fetchit = callPackage ../applications/networking/cluster/fetchit { };