diff options
author | Alyssa Ross <hi@alyssa.is> | 2023-11-05 09:32:31 +0100 |
---|---|---|
committer | Alyssa Ross <hi@alyssa.is> | 2023-11-05 09:32:31 +0100 |
commit | 480416cc0d7e508b652c516af8d7342e3b1e59e3 (patch) | |
tree | d64d990b0d7cc1f80dca687b48563bc71628b55e /nixpkgs/lib/fileset/default.nix | |
parent | 05f40ff2bfe9c68198664c38d65816f677ac7ed4 (diff) | |
parent | fa804edfb7869c9fb230e174182a8a1a7e512c40 (diff) | |
download | nixlib-480416cc0d7e508b652c516af8d7342e3b1e59e3.tar nixlib-480416cc0d7e508b652c516af8d7342e3b1e59e3.tar.gz nixlib-480416cc0d7e508b652c516af8d7342e3b1e59e3.tar.bz2 nixlib-480416cc0d7e508b652c516af8d7342e3b1e59e3.tar.lz nixlib-480416cc0d7e508b652c516af8d7342e3b1e59e3.tar.xz nixlib-480416cc0d7e508b652c516af8d7342e3b1e59e3.tar.zst nixlib-480416cc0d7e508b652c516af8d7342e3b1e59e3.zip |
Merge branch 'nixos-unstable' of https://github.com/NixOS/nixpkgs into HEAD
Conflicts: nixpkgs/pkgs/servers/pr-tracker/default.nix
Diffstat (limited to 'nixpkgs/lib/fileset/default.nix')
-rw-r--r-- | nixpkgs/lib/fileset/default.nix | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/nixpkgs/lib/fileset/default.nix b/nixpkgs/lib/fileset/default.nix index 0342be3e0371..4a97633b4a89 100644 --- a/nixpkgs/lib/fileset/default.nix +++ b/nixpkgs/lib/fileset/default.nix @@ -9,6 +9,7 @@ let _fileFilter _printFileset _intersection + _difference ; inherit (builtins) @@ -369,6 +370,58 @@ If a directory does not recursively contain any file, it is omitted from the sto (elemAt filesets 1); /* + The file set containing all files from the first file set that are not in the second file set. + See also [Difference (set theory)](https://en.wikipedia.org/wiki/Complement_(set_theory)#Relative_complement). + + The given file sets are evaluated as lazily as possible, + with the first argument being evaluated first if needed. + + Type: + union :: FileSet -> FileSet -> FileSet + + Example: + # Create a file set containing all files from the current directory, + # except ones under ./tests + difference ./. ./tests + + let + # A set of Nix-related files + nixFiles = unions [ ./default.nix ./nix ./tests/default.nix ]; + in + # Create a file set containing all files under ./tests, except ones in `nixFiles`, + # meaning only without ./tests/default.nix + difference ./tests nixFiles + */ + difference = + # The positive file set. + # The result can only contain files that are also in this file set. + # + # This argument can also be a path, + # which gets [implicitly coerced to a file set](#sec-fileset-path-coercion). + positive: + # The negative file set. + # The result will never contain files that are also in this file set. + # + # This argument can also be a path, + # which gets [implicitly coerced to a file set](#sec-fileset-path-coercion). + negative: + let + filesets = _coerceMany "lib.fileset.difference" [ + { + context = "first argument (positive set)"; + value = positive; + } + { + context = "second argument (negative set)"; + value = negative; + } + ]; + in + _difference + (elemAt filesets 0) + (elemAt filesets 1); + + /* Incrementally evaluate and trace a file set in a pretty way. This function is only intended for debugging purposes. The exact tracing format is unspecified and may change. |