From 5a6a31e54ddaf59aa8e1c5e7e9b02623d4881c34 Mon Sep 17 00:00:00 2001 From: Artturin Date: Tue, 17 May 2022 21:49:33 +0300 Subject: [PATCH] fetchzip: extraPostFetch -> postFetch && tests --- pkgs/build-support/fetchzip/default.nix | 8 +++++++- pkgs/build-support/fetchzip/tests.nix | 25 +++++++++++++++++++++++++ pkgs/test/default.nix | 1 + pkgs/top-level/all-packages.nix | 5 ++++- 4 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 pkgs/build-support/fetchzip/tests.nix diff --git a/pkgs/build-support/fetchzip/default.nix b/pkgs/build-support/fetchzip/default.nix index a3f22de58c7..98c41037074 100644 --- a/pkgs/build-support/fetchzip/default.nix +++ b/pkgs/build-support/fetchzip/default.nix @@ -12,6 +12,7 @@ , url ? "" , urls ? [] , extraPostFetch ? "" +, postFetch ? "" , name ? "source" , nativeBuildInputs ? [ ] , # Allows to set the extension for the intermediate downloaded @@ -20,6 +21,8 @@ extension ? null , ... } @ args: + +lib.warnIf (extraPostFetch != "") "use 'postFetch' instead of 'extraPostFetch' with 'fetchzip' and 'fetchFromGitHub'." (fetchurl (let tmpFilename = if extension != null @@ -60,11 +63,14 @@ in { mv "$unpackDir" "$out" '') + '' + ${postFetch} + '' + '' ${extraPostFetch} '' + # Remove non-owner write permissions # Fixes https://github.com/NixOS/nixpkgs/issues/38649 + '' chmod 755 "$out" ''; -} // removeAttrs args [ "stripRoot" "extraPostFetch" "extension" "nativeBuildInputs" ])) +} // removeAttrs args [ "stripRoot" "extraPostFetch" "postFetch" "extension" "nativeBuildInputs" ])) diff --git a/pkgs/build-support/fetchzip/tests.nix b/pkgs/build-support/fetchzip/tests.nix new file mode 100644 index 00000000000..1ee2d0e7a49 --- /dev/null +++ b/pkgs/build-support/fetchzip/tests.nix @@ -0,0 +1,25 @@ +{ testers, fetchzip, ... }: + +let + zipUrl = "https://gist.github.com/glandium/01d54cefdb70561b5f6675e08f2990f2/archive/2f430f0c136a69b0886281d0c76708997d8878af.zip"; +in +{ + simple = testers.invalidateFetcherByDrvHash fetchzip { + inherit zipUrl; + sha256 = "sha256-0ecwgL8qUavSj1+WkaxpmRBmu7cvj53V5eXQV71fddU="; + }; + + postFetch = testers.invalidateFetcherByDrvHash fetchzip { + inherit zipUrl; + sha256 = "sha256-7sAOzKa+9vYx5XyndHxeY2ffWAjOsgCkXC9anK6cuV0="; + postFetch = ''touch $out/filee''; + }; + + #extraPostFetch = testers.invalidateFetcherByDrvHash fetchzip { + # inherit url; + # sha256 = "sha256-UC8oJqojqpjqa72UpT0QTME+UwQhVVk5/d9mgRPDR20="; + # extraPostFetch = '' + # touch $out/afile + # ''; + #}; +} diff --git a/pkgs/test/default.nix b/pkgs/test/default.nix index 2ab03bda8b7..d6e4c545a08 100644 --- a/pkgs/test/default.nix +++ b/pkgs/test/default.nix @@ -28,6 +28,7 @@ with pkgs; cc-multilib-clang = callPackage ./cc-wrapper/multilib.nix { stdenv = clangMultiStdenv; }; fetchpatch = callPackages ../build-support/fetchpatch/tests.nix { }; + fetchzip = callPackages ../build-support/fetchzip/tests.nix { }; fetchgit = callPackages ../build-support/fetchgit/tests.nix { }; fetchFirefoxAddon = callPackages ../build-support/fetchfirefoxaddon/tests.nix { }; diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 6707508cc04..a5347b836b9 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -723,7 +723,10 @@ with pkgs; inherit curl stdenv; }; - fetchzip = callPackage ../build-support/fetchzip { }; + fetchzip = callPackage ../build-support/fetchzip { } + // { + tests = pkgs.tests.fetchzip; + }; fetchCrate = callPackage ../build-support/rust/fetchcrate.nix { };