summary refs log tree commit diff
path: root/lib/sources.nix
diff options
context:
space:
mode:
authorMichael Peyton Jones <me@michaelpj.com>2020-03-23 09:26:12 +0000
committerMichael Peyton Jones <me@michaelpj.com>2020-03-23 09:53:07 +0000
commit07f363fae3b106412746e75c631d35da3e5119d8 (patch)
tree5e60bc2e6ea18cb4b1949b517534dc6bb27ba101 /lib/sources.nix
parent8130f3c1c2bb0e533b5e150c39911d6e61dcecc2 (diff)
downloadnixpkgs-07f363fae3b106412746e75c631d35da3e5119d8.tar
nixpkgs-07f363fae3b106412746e75c631d35da3e5119d8.tar.gz
nixpkgs-07f363fae3b106412746e75c631d35da3e5119d8.tar.bz2
nixpkgs-07f363fae3b106412746e75c631d35da3e5119d8.tar.lz
nixpkgs-07f363fae3b106412746e75c631d35da3e5119d8.tar.xz
nixpkgs-07f363fae3b106412746e75c631d35da3e5119d8.tar.zst
nixpkgs-07f363fae3b106412746e75c631d35da3e5119d8.zip
cleanSourceWith: don't use baseNameOf
Currently, not providing `name` to `cleanSourceWith` will use the name
of the imported directory. However, a common case is for this to be the
top level of some repository. In that case, the name will be the name of
the checkout on the current machine, which is not necessarily
reproducible across different settings, and can lead to e.g. cache
misses in CI.

This is documented in the comment on `cleanSourceWith`, but this does
not stop it being a subtle trap for users.

There are different tradeoffs in each case:

1. If `cleanSourceWith` defaults to `"source"`, then we may end up with a
user not knowing what directory a source store path corresponds to.
However, it being called "unnamed" may give them a clue that there is a
way for them to name it, and lead them to the definition of the
function, which has a clear `name` parameter.

2. If `cleanSoureWith` defaults to the directory name, then a user may face
occasional loss of caching, which is hard to notice, and hard to track
down. Tracking it down likely requires use of more advanced tools like
`nix-diff`, and reading the source of a lot of nix code.

I think the downside of the status quo is worse.

This is really another iteration of
https://github.com/NixOS/nix/issues/1305: that led to adding the `name`
argument in the first place, this just makes us use a better default
`name`.
Diffstat (limited to 'lib/sources.nix')
-rw-r--r--lib/sources.nix7
1 files changed, 2 insertions, 5 deletions
diff --git a/lib/sources.nix b/lib/sources.nix
index 05519c3e392..ed9bce48530 100644
--- a/lib/sources.nix
+++ b/lib/sources.nix
@@ -63,17 +63,14 @@ rec {
   #             https://nixos.org/nix/manual/#builtin-filterSource
   #
   #   name:     Optional name to use as part of the store path.
-  #             This defaults `src.name` or otherwise `baseNameOf src`.
-  #             We recommend setting `name` whenever `src` is syntactically `./.`.
-  #             Otherwise, you depend on `./.`'s name in the parent directory,
-  #             which can cause inconsistent names, defeating caching.
+  #             This defaults to `src.name` or otherwise `"source"`.
   #
   cleanSourceWith = { filter ? _path: _type: true, src, name ? null }:
     let
       isFiltered = src ? _isLibCleanSourceWith;
       origSrc = if isFiltered then src.origSrc else src;
       filter' = if isFiltered then name: type: filter name type && src.filter name type else filter;
-      name' = if name != null then name else if isFiltered then src.name else baseNameOf src;
+      name' = if name != null then name else if isFiltered then src.name else "source";
     in {
       inherit origSrc;
       filter = filter';