Update: After talking with @roberth , he agreed for me to just go ahead and start incrementally merging PR’s implementing this. The first one is merged now, though it’s a very limited interface:
NixOS:master ← tweag:fileset.toSource
opened 11:40PM - 26 Jul 23 UTC
###### Description of changes
This is the first PR split off from the more co… mplete [file set combinators PR](https://github.com/NixOS/nixpkgs/pull/222981), in order to make it easier to incrementally review and merge it. This PR implements a severely limited interface, only containing a single new function:
```nix
# Imports ./. into the store, only including files under ./some/path
lib.fileset.toSource {
root = ./.;
fileset = ./some/path;
}
```
Despite that, it's kind of neat how even this simple filtering was previously rather tricky to implement using `lib.sources` filters, and simple mistakes can break it:
<details>
<summary>How to do it without this function</summary>
Edit: Actually it occurred to me that this might have a mistake, iirc something relating to the filesystem root.
```nix
{
functionBased =
let
# The toString and extra "/" is necessary!
subpath = toString ./some/path + "/";
in
lib.cleanSourceWith {
src = ./.;
filter = path: type:
lib.strings.hasPrefix path subpath || lib.strings.hasPrefix subpath path;
};
regexBased = lib.sourceByRegex ./. [
"some"
"some/path"
"some/path/.*"
];
}
```
</details>
This work is sponsored by [Antithesis](https://antithesis.com/) :sparkles:
###### Things done
- [x] Implementation
- [x] Tested
- [x] Commented
- [x] Benchmarked
- [x] Contributor documentation
- [x] Design document
- [x] User documentation
- [x] Function reference
- [x] General library documentation
The second one is much more interesting, but I just opened it, reviews appreciated!
NixOS:master ← tweag:fileset.union
opened 09:42PM - 13 Sep 23 UTC
## Description of changes
This is another split off from the [file set combin… ators PR](https://github.com/NixOS/nixpkgs/pull/222981), based on top of the already-merged [`lib.fileset.toSource`](https://github.com/NixOS/nixpkgs/pull/245623) and fileset infrastructure.
This adds two new functions, allowing the creation of [unions](https://en.wikipedia.org/wiki/Union_(set_theory)) of file sets:
```nix
lib.fileset.toSource {
root = ./.;
# Includes ./Makefile and recursively all files in ./src
fileset = lib.fileset.union
./Makefile
./src;
}
lib.fileset.toSource {
# Needed to be able to include a file from the parent directory
root = ./..;
# unions takes a list instead, only the given paths are included, nothing else
fileset = lib.fileset.unions [
./Makefile
./src
# Also include a file from the parent directory
../LICENSE
];
}
```
Comparatively, doing this correctly using the existing `lib.sources` functions is notoriously difficult.
This work is sponsored by [Antithesis](https://antithesis.com/) :sparkles:
## Things done
- [x] Implementation
- [x] Tested
- [x] Commented
- [x] Benchmarked
- [x] Added user documentation
- [x] Updated other relevant documentation
6 Likes