mirror of
https://github.com/NixOS/nix
synced 2025-07-07 18:31:49 +02:00
Add builtins.filterPath
This is like builtins.{filterSource,path}, but returns a virtual path that applies the filter lazily, rather than copying the result to the Nix store. Thus filterPath can be composed.
This commit is contained in:
parent
15d2e0e63b
commit
b48e64162a
6 changed files with 263 additions and 21 deletions
48
tests/flakes/tree-operators.sh
Normal file
48
tests/flakes/tree-operators.sh
Normal file
|
@ -0,0 +1,48 @@
|
|||
source ./common.sh
|
||||
|
||||
flake1Dir=$TEST_ROOT/flake1
|
||||
|
||||
mkdir -p $flake1Dir
|
||||
|
||||
pwd=$(pwd)
|
||||
|
||||
cat > $flake1Dir/flake.nix <<EOF
|
||||
{
|
||||
inputs.docs = {
|
||||
url = "path://$pwd/../../doc";
|
||||
flake = false;
|
||||
};
|
||||
|
||||
outputs = { self, docs }: with import ./lib.nix; {
|
||||
|
||||
mdOnly = builtins.filterPath {
|
||||
path = docs;
|
||||
filter =
|
||||
path: type:
|
||||
(type != "regular" || hasSuffix ".md" path);
|
||||
};
|
||||
|
||||
noReleaseNotes = builtins.filterPath {
|
||||
path = self.mdOnly + "/manual";
|
||||
filter =
|
||||
path: type:
|
||||
assert !hasPrefix "/manual" path;
|
||||
(builtins.baseNameOf path != "release-notes");
|
||||
};
|
||||
|
||||
};
|
||||
}
|
||||
EOF
|
||||
|
||||
cp ../lang/lib.nix $flake1Dir/
|
||||
|
||||
nix build --out-link $TEST_ROOT/result $flake1Dir#mdOnly
|
||||
[[ -e $TEST_ROOT/result/manual/src/quick-start.md ]]
|
||||
[[ -e $TEST_ROOT/result/manual/src/release-notes ]]
|
||||
(! find $TEST_ROOT/result/ -type f | grep -v '.md$')
|
||||
find $TEST_ROOT/result/ -type f | grep release-notes
|
||||
|
||||
nix build --out-link $TEST_ROOT/result $flake1Dir#noReleaseNotes
|
||||
[[ -e $TEST_ROOT/result/src/quick-start.md ]]
|
||||
(! [[ -e $TEST_ROOT/result/src/release-notes ]])
|
||||
(! find $TEST_ROOT/result/ -type f | grep release-notes)
|
|
@ -19,6 +19,8 @@ rec {
|
|||
|
||||
sum = foldl' (x: y: add x y) 0;
|
||||
|
||||
hasPrefix = pref: str: substring 0 (stringLength pref) str == pref;
|
||||
|
||||
hasSuffix = ext: fileName:
|
||||
let lenFileName = stringLength fileName;
|
||||
lenExt = stringLength ext;
|
||||
|
|
|
@ -10,6 +10,7 @@ nix_tests = \
|
|||
flakes/unlocked-override.sh \
|
||||
flakes/absolute-paths.sh \
|
||||
flakes/build-paths.sh \
|
||||
flakes/tree-operators.sh \
|
||||
ca/gc.sh \
|
||||
gc.sh \
|
||||
remote-store.sh \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue