about summary refs log tree commit diff
path: root/nixpkgs/lib/sources.nix
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2019-09-11 15:24:55 +0000
committerAlyssa Ross <hi@alyssa.is>2019-09-16 22:14:45 +0000
commit89c4dccbd5f33f71808d4b1baafe619696af1162 (patch)
treefb1b8d3a2f171164a05d404ab2340cfb1a9d3e21 /nixpkgs/lib/sources.nix
parent8920a0e4d962a919238bab69ddc607d7f3396f70 (diff)
parente19054ab3cd5b7cc9a01d0efc71c8fe310541065 (diff)
downloadnixlib-89c4dccbd5f33f71808d4b1baafe619696af1162.tar
nixlib-89c4dccbd5f33f71808d4b1baafe619696af1162.tar.gz
nixlib-89c4dccbd5f33f71808d4b1baafe619696af1162.tar.bz2
nixlib-89c4dccbd5f33f71808d4b1baafe619696af1162.tar.lz
nixlib-89c4dccbd5f33f71808d4b1baafe619696af1162.tar.xz
nixlib-89c4dccbd5f33f71808d4b1baafe619696af1162.tar.zst
nixlib-89c4dccbd5f33f71808d4b1baafe619696af1162.zip
Merge commit 'e19054ab3cd5b7cc9a01d0efc71c8fe310541065'
Diffstat (limited to 'nixpkgs/lib/sources.nix')
-rw-r--r--nixpkgs/lib/sources.nix37
1 files changed, 33 insertions, 4 deletions
diff --git a/nixpkgs/lib/sources.nix b/nixpkgs/lib/sources.nix
index c4680087b245..51bcf5559e32 100644
--- a/nixpkgs/lib/sources.nix
+++ b/nixpkgs/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.