# Flakes for development in large repos

**URL:** https://discourse.nixos.org/t/flakes-for-development-in-large-repos/59180
**Category:** Development
**Created:** [January 21, 2025, 7:46pm UTC](https://discourse.nixos.org/t/flakes-for-development-in-large-repos/59180 "2025-01-21T19:46:03Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![jle](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/j/278dde/32.png) [@jle](https://discourse.nixos.org/u/jle)
#### Post date: [January 21, 2025, 7:46pm UTC](https://discourse.nixos.org/t/flakes-for-development-in-large-repos/59180/1 "2025-01-21T19:46:03Z")

</div>

Hello,

I’d really like to use flakes for setting up consistent development environments/shells for my projects. I’ve run into the problem that if the flake.nix is part of a git repo, nix always copies the whole repo to the nix store first, despite the fact that except for the flake.nix, all of it is completely unrelated source code. For my larger repo this is very slow (~10s even if there is nothing to rebuild), also I would prefer not to have all my source code in the public nix store. What is the preferred way to avoid this?

---

<div class="post-metadata">

### Author: ![waffle8946](https://discourse.nixos.org/user_avatar/discourse.nixos.org/waffle8946/32/27221_2.png) [@waffle8946](https://discourse.nixos.org/u/waffle8946)
#### Post date: [January 21, 2025, 8:02pm UTC](https://discourse.nixos.org/t/flakes-for-development-in-large-repos/59180/2 "2025-01-21T20:02:42Z")

</div>

> [@jle](#):
>
> if the flake.nix is part of a git repo, nix always copies the whole repo to the nix store first,

No, flakes are always copied to the store, git repo or not.

You could create a flake located away from your code.

---

<div class="post-metadata">

### Author: ![rnhmjoj](https://discourse.nixos.org/user_avatar/discourse.nixos.org/rnhmjoj/32/1792_2.png) [@rnhmjoj](https://discourse.nixos.org/u/rnhmjoj)
#### Post date: [January 22, 2025, 7:40am UTC](https://discourse.nixos.org/t/flakes-for-development-in-large-repos/59180/3 "2025-01-22T07:40:31Z")

</div>

It’s not possible yet, but at least a solution is planned, see [Copy local flakes to the store lazily · Issue #3121 · NixOS/nix · GitHub](https://github.com/NixOS/nix/issues/3121).

---

<div class="post-metadata">

### Author: ![phanirithvij](https://discourse.nixos.org/user_avatar/discourse.nixos.org/phanirithvij/32/28729_2.png) [@phanirithvij](https://discourse.nixos.org/u/phanirithvij)
#### Post date: [January 22, 2025, 9:22am UTC](https://discourse.nixos.org/t/flakes-for-development-in-large-repos/59180/4 "2025-01-22T09:22:19Z")

</div>

> [@waffle8946](#):
>
> You could create a flake located away from your code.

do you mean only for dev shells?

something like `nix shell github:your/dev-flake#rust-tools` ?

How could it be possible for building the tools in a monorepo with a flake located away from your code?

---

<div class="post-metadata">

### Author: ![waffle8946](https://discourse.nixos.org/user_avatar/discourse.nixos.org/waffle8946/32/27221_2.png) [@waffle8946](https://discourse.nixos.org/u/waffle8946)
#### Post date: [January 22, 2025, 12:44pm UTC](https://discourse.nixos.org/t/flakes-for-development-in-large-repos/59180/5 "2025-01-22T12:44:56Z")

</div>

> [@phanirithvij](#):
>
> do you mean only for dev shells?
> 
> something like `nix shell`

`nix develop` is for dev shells, not `nix shell`.  
Also, no, I mean in general.

> [@phanirithvij](#):
>
> How could it be possible for building the tools in a monorepo with a flake located away from your code?

Use a fetcher for the code.  
But OP doesn’t want to fetch the code, evidently?

---

<div class="post-metadata">

### Author: ![jle](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/j/278dde/32.png) [@jle](https://discourse.nixos.org/u/jle)
#### Post date: [January 22, 2025, 12:50pm UTC](https://discourse.nixos.org/t/flakes-for-development-in-large-repos/59180/6 "2025-01-22T12:50:38Z")

</div>

It would be possible to use a separate repo for the flake, but that (kind of) defeats the most awesome feature, which is having a description of you dev environment directly tied to the source code, so once you have the source code, you have the dev environment as well.

I see a few good ways how this could be implemented:

1. Add a rule (possibly optional) that only paths _below_ the flake.nix gets copied to the store, not parent directories. Then we could just create a `nix-stuff` directory and put everything there, without all of the source code unrelated to nix being copied.
2. Add an optional `filters` parameter to each item in `inputs`, which allows to specify which files should be copied and which shouldn’t (e.g., `filters = [“+./nix-stuff/\*\*” “-\*.c”]).
3. Have a `.nixignore` which works like `.gitignore` but is only parsed by nix.

---

<div class="post-metadata">

### Author: ![andrewhamon](https://discourse.nixos.org/user_avatar/discourse.nixos.org/andrewhamon/32/8387_2.png) [@andrewhamon](https://discourse.nixos.org/u/andrewhamon)
#### Post date: [February 1, 2025, 8:17am UTC](https://discourse.nixos.org/t/flakes-for-development-in-large-repos/59180/7 "2025-02-01T08:17:41Z")

</div>

The unfortunate truth is that flakes in their current state are a bad fit for large, frequently changing repos. Efforts to fix that are underway, but they have been underway several years now.

The good news is that pretty much anything you can achieve with flakes, you can achieve without flakes. It just might take more work and you’ll be a little off the beaten path.

(Note that when I say “without flakes” I just mean no flake.nix, but not necessarily restricting yourself only to the stable command line).
