Commit 7c19bb37 authored by nicoo's avatar nicoo
Browse files

fetchipfs: simplify, error-out when given multiple hashes

Also dropped the `md5` attribute, as `stdenv.mkDerivation` rejects
MD5 since last year (87c22100)
parent 30361c57
Loading
Loading
Loading
Loading
+34 −48
Original line number Diff line number Diff line
{ stdenv
{ lib
, stdenv
, curl
}:

lib.fetchers.withNormalizedHash { hashTypes = [ "sha1" "sha256" "sha512" ]; } (
  { ipfs
  , url            ? ""
  , curlOpts       ? ""
, outputHash     ? ""
, outputHashAlgo ? ""
, md5            ? ""
, sha1           ? ""
, sha256         ? ""
, sha512         ? ""
  , outputHash
  , outputHashAlgo
  , meta           ? {}
  , port           ? "8080"
  , postFetch      ? ""
  , preferLocalBuild ? true
  }:

let

  hasHash = (outputHash != "" && outputHashAlgo != "")
    || md5 != "" || sha1 != "" || sha256 != "" || sha512 != "";

in

if (!hasHash) then throw "Specify sha for fetchipfs fixed-output derivation" else stdenv.mkDerivation {
  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;

    inherit outputHash outputHashAlgo;
    outputHashMode = "recursive";

    inherit curlOpts
@@ -48,3 +33,4 @@ if (!hasHash) then throw "Specify sha for fetchipfs fixed-output derivation" els
    # traffic, so don't do that.
    inherit preferLocalBuild;
  }
)
+1 −3
Original line number Diff line number Diff line
@@ -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 { };