about summary refs log tree commit diff
path: root/pkgs/build-support/fetchpypilegacy
diff options
context:
space:
mode:
authorDavHau <hsngrmpf+github@gmail.com>2023-11-12 23:40:41 +0700
committeradisbladis <adisbladis@gmail.com>2024-02-17 17:11:59 +1300
commit81d43b9b83b4443d9c4d90f601e6fe356eb89a9e (patch)
treebad041fae011ca393e2cfc48867b18bf39858265 /pkgs/build-support/fetchpypilegacy
parentd52b3a7cc02221f1f3447690b1f76206d76a7542 (diff)
fetchPypiLegacy: add test
Diffstat (limited to 'pkgs/build-support/fetchpypilegacy')
-rw-r--r--pkgs/build-support/fetchpypilegacy/default.nix11
-rw-r--r--pkgs/build-support/fetchpypilegacy/tests.nix9
2 files changed, 15 insertions, 5 deletions
diff --git a/pkgs/build-support/fetchpypilegacy/default.nix b/pkgs/build-support/fetchpypilegacy/default.nix
index 1a308ffc323eb..bcd560449916b 100644
--- a/pkgs/build-support/fetchpypilegacy/default.nix
+++ b/pkgs/build-support/fetchpypilegacy/default.nix
@@ -14,6 +14,8 @@
   file,
   # SRI hash
   hash,
+  # allow overriding the derivation name
+  name ? null,
 }:
 let
   urls' = urls ++ lib.optional (url != null) url;
@@ -27,17 +29,16 @@ let
 in
 # Assert that we have at least one URL
 assert urls' != [ ]; runCommand file
-  {
+  ({
     nativeBuildInputs = [ python3 ];
     impureEnvVars = lib.fetchers.proxyImpureEnvVars;
     outputHashMode = "flat";
-    outputHashAlgo = null;
+    # 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;
-    passthru = {
-      urls = urls';
-    };
   }
+  // (lib.optionalAttrs (name != null) {inherit name;}))
   ''
     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
new file mode 100644
index 0000000000000..b16325b96b7ec
--- /dev/null
+++ b/pkgs/build-support/fetchpypilegacy/tests.nix
@@ -0,0 +1,9 @@
+{ testers, fetchPypiLegacy, ... }: {
+  # Tests that we can send custom headers with spaces in them
+  fetchSimple = testers.invalidateFetcherByDrvHash fetchPypiLegacy {
+    pname = "requests";
+    file = "requests-2.31.0.tar.gz";
+    url = "https://pypi.org/simple";
+    hash = "sha256-lCxadY+Y15Dq7Ropy27vx/+w0c968Fw9J5Flbb1q0eE=";
+  };
+}