1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-29 14:53:16 +02:00
nix/tests/flakes/tree-operators.sh
Eelco Dolstra b48e64162a 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.
2022-12-21 14:45:48 +01:00

48 lines
1.1 KiB
Bash

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)