Merge pull request #334059 from adisbladis/fetchpypilegacy-netrc-pureeval

fetchPypiLegacy: pass NETRC via impureEnvVars if inPureEval
This commit is contained in:
adisbladis 2024-08-14 13:16:46 +12:00 committed by GitHub
commit e5d7d560f8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 40 additions and 22 deletions

View File

@ -1,8 +1,23 @@
# Fetch from PyPi legacy API as documented in https://warehouse.pypa.io/api-reference/legacy.html
{ runCommand
, lib
, python3
{
runCommand,
lib,
python3,
}:
let
inherit (lib)
optionalAttrs
fetchers
optional
inPureEvalMode
filter
head
concatStringsSep
escapeShellArg
;
impureEnvVars = fetchers.proxyImpureEnvVars ++ optional inPureEvalMode "NETRC";
in
{
# package name
pname,
@ -18,28 +33,30 @@
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
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 ];
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;
}
// optionalAttrs (name != null) { inherit name; }
// optionalAttrs (!inPureEvalMode) { env.NETRC = netrc_file; }
)
''
python ${./fetch-legacy.py} ${lib.concatStringsSep " " (map (url: "--url ${lib.escapeShellArg url}") urls')} --pname ${pname} --filename ${file}
python ${./fetch-legacy.py} ${
concatStringsSep " " (map (url: "--url ${escapeShellArg url}") urls')
} --pname ${pname} --filename ${file}
mv ${file} $out
''

View File

@ -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";