-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IFD is crazy slow due to copying the entire tree #347
Comments
After some testing, since src = lib.fileset.toSource {
root = src;
fileset = lib.fileset.fromSource (lib.cleanSourceWith {
inherit src;
filter = path: type: (
let baseName = baseNameOf (toString path);
in
(
(type == "directory" && baseName != "target" && baseName != "node_modules")
|| (baseName == "Cargo.toml" || baseName == "Cargo.lock" || baseName == "lib.rs" || baseName == "main.rs")
) && (lib.cleanSourceFilter path type) # + other basic filters
);
});
}; It's still not completely ideal because we actually don't care about the contents of the |
Potential solution: two additional parameters, |
This looks like it would work, but it doesn't seem trivial as it also requires traversing the entire file tree with the same kind of filtering to generate the list of such files to make the derivation generate: it should also work on workspaces, which may have multiple sub- |
The
src
directory for IFD is not filtered:crate2nix/tools.nix
Line 50 in cf03486
This asks to copy the entire workspace tree to the nix store, performing no filtering.
On large repositories containing build artifacts, this is impractical: it may sometimes represent hundreds of gigabytes, and causes the build to freeze forever while it's trying to copy those hundreds of gigabytes to the store, when all one really needs is all the
Cargo.toml
s andCargo.lock
.Fixing
EDIT: see updated solution below instead
It looks like this may be fixed by using
cleanSourceWith
:Although this still has the annoying property that the derivation hash will depend on a bunch of unnecessary empty directories (the hash shouldn't depend on any empty directory either), it makes it run reasonably, so it would still be a clear improvement.
Alternatively
lib.fileset
may be an option.Also cleaning up empty directories
This post seems to suggest that
lib.fileset
may by default already be filtering empty directories.Alternatively
According to this post, adding another layer to further recursively clean unnecessary empty directories:
may allow preserving the source hash regardless of whether new empty directories are created, but I'm not sure what prevents this from being source addressed so maybe I misunderstand something.
Maybe that + another layer of IFD re-copying the cleaned source would fix it but that seems incredibly dirty.
The post also presents another option that does not have this issue, but which is obviously bad "because nested directories at depth N are redundantly processed N - 1 times.".
It looks like doing the regular directory traversal that filterSource does, but only creating a directory once we're about to put an actual file inside, is something that should already exist in Nix though... I can't be the first looking for this, so it must be in
lib.fileset
...The text was updated successfully, but these errors were encountered: