nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at python-updates 70 lines 1.8 kB view raw
1# Fetch from PyPi legacy API as documented in https://warehouse.pypa.io/api-reference/legacy.html 2{ 3 runCommand, 4 lib, 5 python3, 6 cacert, 7}@pkgs: 8let 9 inherit (lib) 10 optionalAttrs 11 fetchers 12 optional 13 inPureEvalMode 14 filter 15 head 16 concatStringsSep 17 escapeShellArg 18 ; 19 20 impureEnvVars = fetchers.proxyImpureEnvVars ++ optional inPureEvalMode "NETRC"; 21in 22lib.makeOverridable ( 23 { 24 # package name 25 pname, 26 # Package index 27 url ? null, 28 # Multiple package indices to consider 29 urls ? [ ], 30 # filename including extension 31 file, 32 # SRI hash 33 hash, 34 # allow overriding the derivation name 35 name ? null, 36 # allow overriding cacert using src.override { cacert = cacert.override { extraCertificateFiles = [ ./path/to/cert.pem ]; }; } 37 cacert ? pkgs.cacert, 38 }: 39 let 40 urls' = urls ++ optional (url != null) url; 41 42 pathParts = filter ({ prefix, path }: "NETRC" == prefix) builtins.nixPath; 43 netrc_file = if (pathParts != [ ]) then (head pathParts).path else ""; 44 45 in 46 # Assert that we have at least one URL 47 assert urls' != [ ]; 48 runCommand file 49 ( 50 { 51 nativeBuildInputs = [ 52 python3 53 cacert 54 ]; 55 inherit impureEnvVars; 56 outputHashMode = "flat"; 57 # if hash is empty select a default algo to let nix propose the actual hash. 58 outputHashAlgo = if hash == "" then "sha256" else null; 59 outputHash = hash; 60 } 61 // optionalAttrs (name != null) { inherit name; } 62 // optionalAttrs (!inPureEvalMode) { env.NETRC = netrc_file; } 63 ) 64 '' 65 python ${./fetch-legacy.py} ${ 66 concatStringsSep " " (map (url: "--url ${escapeShellArg url}") urls') 67 } --pname ${pname} --filename ${file} 68 mv ${file} $out 69 '' 70)