invalidateFetcherByDrvHash: init
This commit is contained in:
@@ -594,6 +594,42 @@ with pkgs;
|
||||
|
||||
installShellFiles = callPackage ../build-support/install-shell-files {};
|
||||
|
||||
/*
|
||||
Use the derivation hash to invalidate the output via name, for testing
|
||||
purposes.
|
||||
|
||||
Type: (a@{ name, ... } -> Derivation) -> a -> Derivation
|
||||
|
||||
Normally, fixed output derivations can and should be cached by their output
|
||||
hash only, but for testing we want to re-fetch everytime the fetcher changes.
|
||||
|
||||
Changes to the fetcher become apparent in the drvPath, which is a hash of
|
||||
how to fetch, rather than a fixed store path.
|
||||
By inserting this hash into the name, we can make sure to re-run the fetcher
|
||||
every time the fetcher changes.
|
||||
|
||||
This relies on the assumption that Nix isn't clever enough to reuse its
|
||||
database of local store contents to optimize fetching.
|
||||
|
||||
Note that the "salt" derives from a different drv than the final fetcher
|
||||
drv. This is necessary, because it can not be defined recursively.
|
||||
|
||||
Example:
|
||||
|
||||
tests.fetchgit = invalidateFetcherByDrvHash fetchgit {
|
||||
name = "nix-source";
|
||||
url = "https://github.com/NixOS/nix";
|
||||
rev = "9d9dbe6ed05854e03811c361a3380e09183f4f4a";
|
||||
sha256 = "sha256-7DszvbCNTjpzGRmpIVAWXk20P0/XTrWZ79KSOGLrUWY=";
|
||||
};
|
||||
*/
|
||||
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));
|
||||
in f (args // { name = "${args.name or "source"}-salted-${salt}"; });
|
||||
|
||||
lazydocker = callPackage ../tools/misc/lazydocker { };
|
||||
|
||||
ld-is-cc-hook = makeSetupHook { name = "ld-is-cc-hook"; }
|
||||
|
||||
Reference in New Issue
Block a user