invalidateFetcherByDrvHash move docs to manual

Changed files
+35 -30
doc
pkgs
top-level
+1 -1
doc/builders/fetchers.chapter.md
···
Because fixed output derivations are _identified_ by their hash, a common mistake is to update a fetcher's URL or a version parameter, without updating the hash. **This will cause the old contents to be used.** So remember to always invalidate the hash argument.
-
For those who develop and maintain fetcheres, a similar problem arises with changes to the implementation of a fetcher. These may cause a fixed output derivation to fail, but won't normally be caught by tests because the supposed output is already in the store or cache. For the purpose of testing, you can use a trick that is embodied by the `invalidateFetcherByDrvHash` function. It uses the derivation `name` to create a unique output path per fetcher implementation, defeating the caching precisely where it would be harmful.
## `fetchurl` and `fetchzip` {#fetchurl}
···
Because fixed output derivations are _identified_ by their hash, a common mistake is to update a fetcher's URL or a version parameter, without updating the hash. **This will cause the old contents to be used.** So remember to always invalidate the hash argument.
+
For those who develop and maintain fetcheres, a similar problem arises with changes to the implementation of a fetcher. These may cause a fixed output derivation to fail, but won't normally be caught by tests because the supposed output is already in the store or cache. For the purpose of testing, you can use a trick that is embodied by the [`invalidateFetcherByDrvHash`](#sec-pkgs-invalidateFetcherByDrvHash) function. It uses the derivation `name` to create a unique output path per fetcher implementation, defeating the caching precisely where it would be harmful.
## `fetchurl` and `fetchzip` {#fetchurl}
+1
doc/builders/special.xml
···
</para>
<xi:include href="special/fhs-environments.section.xml" />
<xi:include href="special/mkshell.section.xml" />
</chapter>
···
</para>
<xi:include href="special/fhs-environments.section.xml" />
<xi:include href="special/mkshell.section.xml" />
+
<xi:include href="special/invalidateFetcherByDrvHash.section.xml" />
</chapter>
+31
doc/builders/special/invalidateFetcherByDrvHash.section.md
···
···
+
+
## `invalidateFetcherByDrvHash` {#sec-pkgs-invalidateFetcherByDrvHash}
+
+
Use the derivation hash to invalidate the output via name, for testing.
+
+
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.
+
+
You might notice that the "salted" name derives from the normal invocation,
+
not the final derivation. `invalidateFetcherByDrvHash` has to invoke the fetcher
+
function twice: once to get a derivation hash, and again to produce the final
+
fixed output derivation.
+
+
Example:
+
+
tests.fetchgit = invalidateFetcherByDrvHash fetchgit {
+
name = "nix-source";
+
url = "https://github.com/NixOS/nix";
+
rev = "9d9dbe6ed05854e03811c361a3380e09183f4f4a";
+
sha256 = "sha256-7DszvbCNTjpzGRmpIVAWXk20P0/XTrWZ79KSOGLrUWY=";
+
};
+2 -29
pkgs/top-level/all-packages.nix
···
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;
···
installShellFiles = callPackage ../build-support/install-shell-files {};
+
# See doc/builders/special/invalidateFetcherByDrvHash.section.md or
+
# https://nixos.org/manual/nixpkgs/unstable/#sec-pkgs-invalidateFetcherByDrvHash
invalidateFetcherByDrvHash = f: args:
let
drvPath = (f args).drvPath;