From c3691d772d954f14e8a93256faaaff0d3348af8f Mon Sep 17 00:00:00 2001 From: nicoo Date: Sun, 15 Sep 2024 22:32:42 +0000 Subject: [PATCH] fetchfossil: simplify and check that multiple hashes were not passed in --- pkgs/build-support/fetchfossil/default.nix | 47 +++++++++------------- 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/pkgs/build-support/fetchfossil/default.nix b/pkgs/build-support/fetchfossil/default.nix index 3f3bf69db047..d0fc4cdea703 100644 --- a/pkgs/build-support/fetchfossil/default.nix +++ b/pkgs/build-support/fetchfossil/default.nix @@ -1,33 +1,26 @@ {stdenv, lib, fossil, cacert}: -{ name ? null -, url -, rev -, sha256 ? "" -, hash ? "" -}: +lib.fetchers.withNormalizedHash { } ( + { name ? null + , url + , rev + , outputHash ? lib.fakeHash + , outputHashAlgo ? null + }: -if hash != "" && sha256 != "" then - throw "Only one of sha256 or hash can be set" -else -stdenv.mkDerivation { - name = "fossil-archive" + (lib.optionalString (name != null) "-${name}"); - builder = ./builder.sh; - nativeBuildInputs = [fossil cacert]; + stdenv.mkDerivation { + name = "fossil-archive" + (lib.optionalString (name != null) "-${name}"); + builder = ./builder.sh; + nativeBuildInputs = [fossil cacert]; - # Envvar docs are hard to find. A link for the future: - # https://www.fossil-scm.org/index.html/doc/trunk/www/env-opts.md - impureEnvVars = [ "http_proxy" ]; + # Envvar docs are hard to find. A link for the future: + # https://www.fossil-scm.org/index.html/doc/trunk/www/env-opts.md + impureEnvVars = [ "http_proxy" ]; - outputHashAlgo = if hash != "" then null else "sha256"; - outputHashMode = "recursive"; - outputHash = if hash != "" then - hash - else if sha256 != "" then - sha256 - else - lib.fakeSha256; + inherit outputHash outputHashAlgo; + outputHashMode = "recursive"; - inherit url rev; - preferLocalBuild = true; -} + inherit url rev; + preferLocalBuild = true; + } +)