Issue on page /tutorials/file-sets.html
ocharles opened this issue · comments
This page says
When using the flakes and nix-command experimental features, a local directory within a Flake is always copied into the Nix store completely unless it is a Git repository!
But I don't really understand the implications of this warning. Does it mean that filesets are useless when using Nix flakes/nix develop
? Does it mean the examples on this page don't really work?
This note says that if the directory your flake.nix
is in is not a Git repository, evaluating ${./.}
will copy all the files under ./.
into the store. If you have a large directory, this is quite wasteful. This means that fileset
is particularly useful in that case. NixOS/nix#6530 is supposed to alleviate that limitation when enforcing pure evaluation, but we don't know when it will be completed.
The other note on flakes and gitTracked
is where fileset
indeed does not add much benefit: only files tracked by Git are copied to the store when the flakes
experimental feature is enabled, so there is no point filtering for them with fileset
.
Ok, but I'm still curious about how useful filesets are with Flakes, because it sounds like I will still end up copying the entire Git repository into the store before anything happens. Would #6530 help here too?
I will still end up copying the entire Git repository into the store before anything happens
With flakes indeed you'll copy the repo into the store, but then filesets will let you extract small store objects for compilation. Which means that if those don't change, you don't have to copy around large chunks during builds.
This note says that if the directory your
flake.nix
is in is not a Git repository, evaluating${./.}
will copy all the files under./.
into the store. If you have a large directory, this is quite wasteful. This means thatfileset
is particularly useful in that case
Just to clarify, this isn't right. Filesets (or any other way to filter sources) can't prevent files from being added to the store if you use Flakes. So they won't help with that. That's a Nix problem to fix, and I'm not sure even NixOS/nix#6530 helps with that.
But indeed as already mentioned by Valentin, file sets are still useful to make derivations depend on only the files they actually need, so that you don't need to build them again when e.g. the README.md
or default.nix
changes.
Got it, thanks!