summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorFrederik Rietdijk <fridh@fridh.nl>2019-09-06 22:46:05 +0200
committerFrederik Rietdijk <fridh@fridh.nl>2019-09-06 22:46:05 +0200
commit66bc7fc1b3e7a85a2cfde9bb121498a181d411a4 (patch)
treefa53c32dfef1265496170172a28a3c71bb32a655 /lib
parentf9237f315264a0ccb8b50ff4fa6ff456239e4dc1 (diff)
parentcfe51be04f8b7c36fe9f71ca5835bd683ede087f (diff)
downloadnixpkgs-66bc7fc1b3e7a85a2cfde9bb121498a181d411a4.tar
nixpkgs-66bc7fc1b3e7a85a2cfde9bb121498a181d411a4.tar.gz
nixpkgs-66bc7fc1b3e7a85a2cfde9bb121498a181d411a4.tar.bz2
nixpkgs-66bc7fc1b3e7a85a2cfde9bb121498a181d411a4.tar.lz
nixpkgs-66bc7fc1b3e7a85a2cfde9bb121498a181d411a4.tar.xz
nixpkgs-66bc7fc1b3e7a85a2cfde9bb121498a181d411a4.tar.zst
nixpkgs-66bc7fc1b3e7a85a2cfde9bb121498a181d411a4.zip
Merge master into staging-next
Diffstat (limited to 'lib')
-rw-r--r--lib/lists.nix2
-rw-r--r--lib/sources.nix37
2 files changed, 34 insertions, 5 deletions
diff --git a/lib/lists.nix b/lib/lists.nix
index d075a02d475..f9f30412770 100644
--- a/lib/lists.nix
+++ b/lib/lists.nix
@@ -88,7 +88,7 @@ rec {
   /* Strict version of `foldl`.
 
      The difference is that evaluation is forced upon access. Usually used
-     with small whole results (in contract with lazily-generated list or large
+     with small whole results (in contrast with lazily-generated list or large
      lists where only a part is consumed.)
 
      Type: foldl' :: (b -> a -> b) -> b -> [a] -> b
diff --git a/lib/sources.nix b/lib/sources.nix
index c4680087b24..51bcf5559e3 100644
--- a/lib/sources.nix
+++ b/lib/sources.nix
@@ -36,18 +36,47 @@ rec {
   # allowing you to chain multiple calls together without any
   # intermediate copies being put in the nix store.
   #
-  #     lib.cleanSourceWith f (lib.cleanSourceWith g ./.)     # Succeeds!
-  #     builtins.filterSource f (builtins.filterSource g ./.) # Fails!
-  cleanSourceWith = { filter, src }:
+  #     lib.cleanSourceWith {
+  #       filter = f;
+  #       src = lib.cleanSourceWith {
+  #         filter = g;
+  #         src = ./.;
+  #       };
+  #     }
+  #     # Succeeds!
+  #
+  #     builtins.filterSource f (builtins.filterSource g ./.)
+  #     # Fails!
+  #
+  # Parameters:
+  #
+  #   src:      A path or cleanSourceWith result to filter and/or rename.
+  #
+  #   filter:   A function (path -> type -> bool)
+  #             Optional with default value: constant true (include everything)
+  #             The function will be combined with the && operator such
+  #             that src.filter is called lazily.
+  #             For implementing a filter, see
+  #             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.
+  #
+  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;
     in {
       inherit origSrc;
       filter = filter';
-      outPath = builtins.filterSource filter' origSrc;
+      outPath = builtins.path { filter = filter'; path = origSrc; name = name'; };
       _isLibCleanSourceWith = true;
+      name = name';
     };
 
   # Filter sources by a list of regular expressions.