Is it possible to make a flake that has no source tree?

I want to use a flake.nix with nix develop to set up a build environment, but the build environment has no need of a source tree as I’ve already got the local tree. Is there any way to make it stop treating the current folder as a source tree and copying it into the store? My folder has tons of build artifacts in it!

I’m about to try moving the flake into an empty subdirectory and then just remembering to reference that subdirectory with nix develop instead, but that’s awkward.

5 Likes

I’m fairly sure the answer is no, but edolstra has some thoughts about how this might work in the future here: Copy local flakes to the store lazily · Issue #3121 · NixOS/nix · GitHub

2 Likes

@lilyball — I also use the flake-in-empty -subdirectory workaround, having accidentally exhausted disk space on /nix by unintentionally repeatedly copying 10G of unchanged source + artifacts whenever a few text files were modified.

Also, in addition to the lazy initialization issue linked above, I also think that the “settings on inputs.self” idea from Support self-fetching parameters in flake.nix · Issue #5312 · NixOS/nix · GitHub would solve this nicely, along with flake-author-controlled submodules processing among other kinds of source processing and filtering.

1 Like

My first thought was “what if I remove the self arg from outputs?” which honestly, it seems like it should work because without the self arg there’s nothing to do. But trying this made it copy to the story first, and then throw an error about how self was passed but didn’t match any argument :persevere:

(for context, I was using this for nix-direnv, nothing in the current directory beyond the flake itself and optionally any nix files it might import, though even that would be acceptable to turn into a flake input itself).

It seems to me this is a significant limitation of flakes. There is a variety of files you may not want to copy to the store:

  • large build artifacts
  • special unsupported files (like sockets)
  • plaintext secrets (git-crypt, transcrypt, etc.)
  • the whole tree (build environments, this case)

There’s some discussion about excluding files (.flakeignore) here:
https://github.com/NixOS/nix/issues/4097

3 Likes