From c071530ca51013059cb8181d6a34e65fef9702a1 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Thu, 5 May 2022 12:08:50 +0200 Subject: [PATCH] testers.invalidateFetcherByDrvHash: Move from top-level --- pkgs/build-support/docker/examples.nix | 2 +- pkgs/build-support/fetchfirefoxaddon/tests.nix | 6 +++--- pkgs/build-support/fetchgit/tests.nix | 6 +++--- pkgs/build-support/fetchpatch/tests.nix | 8 ++++---- .../node/fetch-yarn-deps/tests/default.nix | 8 ++++---- pkgs/build-support/testers/default.nix | 18 ++++++++++++++++++ pkgs/top-level/aliases.nix | 1 + pkgs/top-level/all-packages.nix | 17 ----------------- 8 files changed, 34 insertions(+), 32 deletions(-) diff --git a/pkgs/build-support/docker/examples.nix b/pkgs/build-support/docker/examples.nix index 169edb171db..9b9a21a1469 100644 --- a/pkgs/build-support/docker/examples.nix +++ b/pkgs/build-support/docker/examples.nix @@ -97,7 +97,7 @@ rec { }; # Same example, but re-fetches every time the fetcher implementation changes. # NOTE: Only use this for testing, or you'd be wasting a lot of time, network and space. - testNixFromDockerHub = pkgs.invalidateFetcherByDrvHash pullImage { + testNixFromDockerHub = pkgs.testers.invalidateFetcherByDrvHash pullImage { imageName = "nixos/nix"; imageDigest = "sha256:85299d86263a3059cf19f419f9d286cc9f06d3c13146a8ebbb21b3437f598357"; sha256 = "19fw0n3wmddahzr20mhdqv6jkjn1kanh6n2mrr08ai53dr8ph5n7"; diff --git a/pkgs/build-support/fetchfirefoxaddon/tests.nix b/pkgs/build-support/fetchfirefoxaddon/tests.nix index c407d0e74b8..fd70d0f82ac 100644 --- a/pkgs/build-support/fetchfirefoxaddon/tests.nix +++ b/pkgs/build-support/fetchfirefoxaddon/tests.nix @@ -1,7 +1,7 @@ -{ invalidateFetcherByDrvHash, fetchFirefoxAddon, fetchurl, ... }: +{ testers, fetchFirefoxAddon, fetchurl, ... }: { - simple = invalidateFetcherByDrvHash fetchFirefoxAddon { + simple = testers.invalidateFetcherByDrvHash fetchFirefoxAddon { name = "image-search-options"; # Chosen because its only 147KB url = "https://addons.mozilla.org/firefox/downloads/file/3059971/image_search_options-3.0.12-fx.xpi"; @@ -14,7 +14,7 @@ sha256 = "sha256-H73YWX/DKxvhEwKpWOo7orAQ7c/rQywpljeyxYxv0Gg="; }; in - invalidateFetcherByDrvHash fetchFirefoxAddon { + testers.invalidateFetcherByDrvHash fetchFirefoxAddon { name = "image-search-options"; src = image-search-options; }; diff --git a/pkgs/build-support/fetchgit/tests.nix b/pkgs/build-support/fetchgit/tests.nix index c558fb6efa4..b9ab66d9353 100644 --- a/pkgs/build-support/fetchgit/tests.nix +++ b/pkgs/build-support/fetchgit/tests.nix @@ -1,14 +1,14 @@ -{ invalidateFetcherByDrvHash, fetchgit, ... }: +{ testers, fetchgit, ... }: { - simple = invalidateFetcherByDrvHash fetchgit { + simple = testers.invalidateFetcherByDrvHash fetchgit { name = "nix-source"; url = "https://github.com/NixOS/nix"; rev = "9d9dbe6ed05854e03811c361a3380e09183f4f4a"; sha256 = "sha256-7DszvbCNTjpzGRmpIVAWXk20P0/XTrWZ79KSOGLrUWY="; }; - sparseCheckout = invalidateFetcherByDrvHash fetchgit { + sparseCheckout = testers.invalidateFetcherByDrvHash fetchgit { name = "nix-source"; url = "https://github.com/NixOS/nix"; rev = "9d9dbe6ed05854e03811c361a3380e09183f4f4a"; diff --git a/pkgs/build-support/fetchpatch/tests.nix b/pkgs/build-support/fetchpatch/tests.nix index ff2b81bf3a1..a42b7cd7d14 100644 --- a/pkgs/build-support/fetchpatch/tests.nix +++ b/pkgs/build-support/fetchpatch/tests.nix @@ -1,18 +1,18 @@ -{ invalidateFetcherByDrvHash, fetchpatch, ... }: +{ testers, fetchpatch, ... }: { - simple = invalidateFetcherByDrvHash fetchpatch { + simple = testers.invalidateFetcherByDrvHash fetchpatch { url = "https://github.com/facebook/zstd/pull/2724/commits/e1f85dbca3a0ed5ef06c8396912a0914db8dea6a.patch"; sha256 = "sha256-PuYAqnJWAE+L9bsroOnnBGJhERW8LHrGSLtIEkKU9vg="; }; - relative = invalidateFetcherByDrvHash fetchpatch { + relative = testers.invalidateFetcherByDrvHash fetchpatch { url = "https://github.com/boostorg/math/commit/7d482f6ebc356e6ec455ccb5f51a23971bf6ce5b.patch"; relative = "include"; sha256 = "sha256-KlmIbixcds6GyKYt1fx5BxDIrU7msrgDdYo9Va/KJR4="; }; - full = invalidateFetcherByDrvHash fetchpatch { + full = testers.invalidateFetcherByDrvHash fetchpatch { url = "https://github.com/boostorg/math/commit/7d482f6ebc356e6ec455ccb5f51a23971bf6ce5b.patch"; relative = "test"; stripLen = 1; diff --git a/pkgs/build-support/node/fetch-yarn-deps/tests/default.nix b/pkgs/build-support/node/fetch-yarn-deps/tests/default.nix index a781dad8307..19451466f24 100644 --- a/pkgs/build-support/node/fetch-yarn-deps/tests/default.nix +++ b/pkgs/build-support/node/fetch-yarn-deps/tests/default.nix @@ -1,15 +1,15 @@ -{ invalidateFetcherByDrvHash, fetchYarnDeps, ... }: +{ testers, fetchYarnDeps, ... }: { - simple = invalidateFetcherByDrvHash fetchYarnDeps { + simple = testers.invalidateFetcherByDrvHash fetchYarnDeps { yarnLock = ./simple.lock; sha256 = "sha256-Erdkw2E8wWT09jFNLXGkrdwKl0HuSZWnUDJUrV95vSE="; }; - gitDep = invalidateFetcherByDrvHash fetchYarnDeps { + gitDep = testers.invalidateFetcherByDrvHash fetchYarnDeps { yarnLock = ./git.lock; sha256 = "sha256-lAqN4LpoE+jgsQO1nDtuORwcVEO7ogEV53jCu2jFJUI="; }; - githubDep = invalidateFetcherByDrvHash fetchYarnDeps { + githubDep = testers.invalidateFetcherByDrvHash fetchYarnDeps { yarnLock = ./github.lock; sha256 = "sha256-Tsfgyjxz8x6gNmfN0xR7G/NQNoEs4svxRN/N+26vfJU="; }; diff --git a/pkgs/build-support/testers/default.nix b/pkgs/build-support/testers/default.nix index 8b79843b833..d983e43c0bf 100644 --- a/pkgs/build-support/testers/default.nix +++ b/pkgs/build-support/testers/default.nix @@ -15,4 +15,22 @@ echo "$output" >&2 && exit 1 fi ''; + + # See doc/builders/testers.chapter.md or + # https://nixos.org/manual/nixpkgs/unstable/#tester-invalidateFetcherByDrvHash + invalidateFetcherByDrvHash = f: args: + let + drvPath = (f args).drvPath; + # It's safe to discard the context, because we don't access the path. + salt = builtins.unsafeDiscardStringContext (lib.substring 0 12 (baseNameOf drvPath)); + # New derivation incorporating the original drv hash in the name + salted = f (args // { name = "${args.name or "source"}-salted-${salt}"; }); + # Make sure we did change the derivation. If the fetcher ignores `name`, + # `invalidateFetcherByDrvHash` doesn't work. + checked = + if salted.drvPath == drvPath + then throw "invalidateFetcherByDrvHash: Adding the derivation hash to the fixed-output derivation name had no effect. Make sure the fetcher's name argument ends up in the derivation name. Otherwise, the fetcher will not be re-run when its implementation changes. This is important for testing." + else salted; + in checked; + } diff --git a/pkgs/top-level/aliases.nix b/pkgs/top-level/aliases.nix index d0c8cee8e24..4c3c44ddc3f 100644 --- a/pkgs/top-level/aliases.nix +++ b/pkgs/top-level/aliases.nix @@ -1278,6 +1278,7 @@ mapAliases ({ terraform_1_0_0 = throw "terraform_1_0_0 has been renamed to terraform_1"; # Added 2021-06-15 tesseract_4 = throw "'tesseract_4' has been renamed to/replaced by 'tesseract4'"; # Converted to throw 2022-02-22 testVersion = testers.testVersion; # Added 2022-04-20 + invalidateFetcherByDrvHash = testers.invalidateFetcherByDrvHash; # Added 2022-05-05 tex-gyre-bonum-math = throw "'tex-gyre-bonum-math' has been renamed to/replaced by 'tex-gyre-math.bonum'"; # Converted to throw 2022-02-22 tex-gyre-pagella-math = throw "'tex-gyre-pagella-math' has been renamed to/replaced by 'tex-gyre-math.pagella'"; # Converted to throw 2022-02-22 tex-gyre-schola-math = throw "'tex-gyre-schola-math' has been renamed to/replaced by 'tex-gyre-math.schola'"; # Converted to throw 2022-02-22 diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 9b4b5760373..45bf4c6bf0b 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -744,23 +744,6 @@ with pkgs; installShellFiles = callPackage ../build-support/install-shell-files {}; - # See doc/builders/testers.chapter.md or - # https://nixos.org/manual/nixpkgs/unstable/#tester-invalidateFetcherByDrvHash - invalidateFetcherByDrvHash = f: args: - let - drvPath = (f args).drvPath; - # It's safe to discard the context, because we don't access the path. - salt = builtins.unsafeDiscardStringContext (lib.substring 0 12 (baseNameOf drvPath)); - # New derivation incorporating the original drv hash in the name - salted = f (args // { name = "${args.name or "source"}-salted-${salt}"; }); - # Make sure we did change the derivation. If the fetcher ignores `name`, - # `invalidateFetcherByDrvHash` doesn't work. - checked = - if salted.drvPath == drvPath - then throw "invalidateFetcherByDrvHash: Adding the derivation hash to the fixed-output derivation name had no effect. Make sure the fetcher's name argument ends up in the derivation name. Otherwise, the fetcher will not be re-run when its implementation changes. This is important for testing." - else salted; - in checked; - lazydocker = callPackage ../tools/misc/lazydocker { }; ld-is-cc-hook = makeSetupHook { name = "ld-is-cc-hook"; }