From 2a9ab9c1e08178c70178e25b8cc8315a8f36a683 Mon Sep 17 00:00:00 2001 From: adisbladis Date: Mon, 12 Aug 2024 17:02:16 +1200 Subject: [PATCH 1/2] fetchPypiLegacy: Reformat with nixfmt --- .../build-support/fetchpypilegacy/default.nix | 41 ++++++++++--------- pkgs/build-support/fetchpypilegacy/tests.nix | 3 +- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/pkgs/build-support/fetchpypilegacy/default.nix b/pkgs/build-support/fetchpypilegacy/default.nix index bcd560449916..7c28c60185b2 100644 --- a/pkgs/build-support/fetchpypilegacy/default.nix +++ b/pkgs/build-support/fetchpypilegacy/default.nix @@ -1,7 +1,8 @@ # Fetch from PyPi legacy API as documented in https://warehouse.pypa.io/api-reference/legacy.html -{ runCommand -, lib -, python3 +{ + runCommand, + lib, + python3, }: { # package name @@ -21,25 +22,27 @@ let urls' = urls ++ lib.optional (url != null) url; pathParts = lib.filter ({ prefix, path }: "NETRC" == prefix) builtins.nixPath; - netrc_file = - if (pathParts != [ ]) - then (lib.head pathParts).path - else ""; + netrc_file = if (pathParts != [ ]) then (lib.head pathParts).path else ""; in # Assert that we have at least one URL -assert urls' != [ ]; runCommand file - ({ - nativeBuildInputs = [ python3 ]; - impureEnvVars = lib.fetchers.proxyImpureEnvVars; - outputHashMode = "flat"; - # if hash is empty select a default algo to let nix propose the actual hash. - outputHashAlgo = if hash == "" then "sha256" else null; - outputHash = hash; - NETRC = netrc_file; - } - // (lib.optionalAttrs (name != null) {inherit name;})) +assert urls' != [ ]; +runCommand file + ( + { + nativeBuildInputs = [ python3 ]; + impureEnvVars = lib.fetchers.proxyImpureEnvVars; + outputHashMode = "flat"; + # if hash is empty select a default algo to let nix propose the actual hash. + outputHashAlgo = if hash == "" then "sha256" else null; + outputHash = hash; + NETRC = netrc_file; + } + // (lib.optionalAttrs (name != null) { inherit name; }) + ) '' - python ${./fetch-legacy.py} ${lib.concatStringsSep " " (map (url: "--url ${lib.escapeShellArg url}") urls')} --pname ${pname} --filename ${file} + python ${./fetch-legacy.py} ${ + lib.concatStringsSep " " (map (url: "--url ${lib.escapeShellArg url}") urls') + } --pname ${pname} --filename ${file} mv ${file} $out '' diff --git a/pkgs/build-support/fetchpypilegacy/tests.nix b/pkgs/build-support/fetchpypilegacy/tests.nix index b16325b96b7e..3edfd646e942 100644 --- a/pkgs/build-support/fetchpypilegacy/tests.nix +++ b/pkgs/build-support/fetchpypilegacy/tests.nix @@ -1,4 +1,5 @@ -{ testers, fetchPypiLegacy, ... }: { +{ testers, fetchPypiLegacy, ... }: +{ # Tests that we can send custom headers with spaces in them fetchSimple = testers.invalidateFetcherByDrvHash fetchPypiLegacy { pname = "requests"; From 482a26382fc8ad6392ad406ebb7a916aa2d1ebd6 Mon Sep 17 00:00:00 2001 From: adisbladis Date: Mon, 12 Aug 2024 17:03:41 +1200 Subject: [PATCH 2/2] fetchPypiLegacy: pass NETRC via impureEnvVars if inPureEval Co-authored-by: Matthew Croughan --- .../build-support/fetchpypilegacy/default.nix | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/pkgs/build-support/fetchpypilegacy/default.nix b/pkgs/build-support/fetchpypilegacy/default.nix index 7c28c60185b2..b2715f85dd86 100644 --- a/pkgs/build-support/fetchpypilegacy/default.nix +++ b/pkgs/build-support/fetchpypilegacy/default.nix @@ -4,6 +4,20 @@ lib, python3, }: +let + inherit (lib) + optionalAttrs + fetchers + optional + inPureEvalMode + filter + head + concatStringsSep + escapeShellArg + ; + + impureEnvVars = fetchers.proxyImpureEnvVars ++ optional inPureEvalMode "NETRC"; +in { # package name pname, @@ -19,10 +33,10 @@ name ? null, }: let - urls' = urls ++ lib.optional (url != null) url; + urls' = urls ++ optional (url != null) url; - pathParts = lib.filter ({ prefix, path }: "NETRC" == prefix) builtins.nixPath; - netrc_file = if (pathParts != [ ]) then (lib.head pathParts).path else ""; + pathParts = filter ({ prefix, path }: "NETRC" == prefix) builtins.nixPath; + netrc_file = if (pathParts != [ ]) then (head pathParts).path else ""; in # Assert that we have at least one URL @@ -31,18 +45,18 @@ runCommand file ( { nativeBuildInputs = [ python3 ]; - impureEnvVars = lib.fetchers.proxyImpureEnvVars; + inherit impureEnvVars; outputHashMode = "flat"; # if hash is empty select a default algo to let nix propose the actual hash. outputHashAlgo = if hash == "" then "sha256" else null; outputHash = hash; - NETRC = netrc_file; } - // (lib.optionalAttrs (name != null) { inherit name; }) + // optionalAttrs (name != null) { inherit name; } + // optionalAttrs (!inPureEvalMode) { env.NETRC = netrc_file; } ) '' python ${./fetch-legacy.py} ${ - lib.concatStringsSep " " (map (url: "--url ${lib.escapeShellArg url}") urls') + concatStringsSep " " (map (url: "--url ${escapeShellArg url}") urls') } --pname ${pname} --filename ${file} mv ${file} $out ''