Skip to content

Copy local flakes to the store lazily #3121

Closed

Description

@edolstra

Currently flakes are evaluated from the Nix store, so when using a local flake, it's first copied to the store. This means that

$ cd /path/to/nixpkgs
$ nix build .#hello

is a lot slower than the non-flake alternative

$ nix build -f . hello

Ideally, we would copy the flake to the store only when its outPath attribute is evaluated. However, we also need to ensure that it's not possible to access untracked files (i.e. we need to check every file against git ls-files).

Activity

  1. self-assigned this
    on Oct 7, 2019
  2. added this to the flakes-v3 milestone on Oct 7, 2019
  3. nixos-discourse commented on Dec 30, 2020

    @nixos-discourse

    This issue has been mentioned on NixOS Discourse. There might be relevant details there:

    https://discourse.nixos.org/t/flakes-without-git-copies-entire-tree-to-nix-store/10743/2

  4. hmenke commented on Jun 28, 2021

    @hmenke
    Member

    Still important.

  5. nixos-discourse commented on Jul 26, 2021

    @nixos-discourse

    This issue has been mentioned on NixOS Discourse. There might be relevant details there:

    https://discourse.nixos.org/t/my-painpoints-with-flakes/9750/20

  6. modified the milestones: flakes-v3, nix-3.0 on Aug 30, 2021
  7. L-as commented on Sep 3, 2021

    @L-as
    Member

    It would be nice if Nix could take advantage of the filesystem's native CoW functionality (if present) in order to speed up copying.
    We discussed this briefly in #offtopic:nixos.org.

  8. nixos-discourse commented on Nov 13, 2021

    @nixos-discourse

    This issue has been mentioned on NixOS Discourse. There might be relevant details there:

    https://discourse.nixos.org/t/is-it-possible-to-make-a-flake-that-has-no-source-tree/16037/2

  9. lilyball commented on Nov 13, 2021

    @lilyball
  10. lilyball commented on Nov 13, 2021

    @lilyball
    Member

    Also for context, in my case the flake was not in a git repo, it was just in a folder. Copying to the nix store is unacceptable because the folder contains multiple git repos along with all their build artifacts. Copying a git repo to the Nix store at least would avoid copying untracked files, but in my case it had hundreds of thousands of files and multiple gigabytes of data to look at and copy.

  11. 132 remaining items

  12. fgaz commented on Sep 22, 2024

    @fgaz
    Member

    @tmillr you can set auto-optimise-store = true in nix.conf.

  13. Atemu commented on Sep 22, 2024

    @Atemu
    Member

    While that reduces the space usage needed asynchronously, it still does a copy which wastes IO time and write endurance.

  14. tmillr commented on Sep 23, 2024

    @tmillr

    @tmillr you can set auto-optimise-store = true in nix.conf.

    Thank you. I guess I forgot that that mechanism works based off of file content and not nix store hash (or something else).

    I am using that currently, but I have to run a custom nix store optimise daemon/service on a schedule instead of using the option (as the option causes random build issues/failures on darwin last I checked).

    It sounds like even using that option causes extra fs writes to occur however (but will work for saving space alone).

  15. nixos-discourse commented on Oct 1, 2024

    @nixos-discourse

    This issue has been mentioned on NixOS Discourse. There might be relevant details there:

    https://discourse.nixos.org/t/confused-about-nix-copying-nixpkgs/53737/2

  16. anka-213 commented on Oct 3, 2024

    @anka-213

    note that reflinking is something an application must choose to do; it is not the default.

    I don't think it's worth spending time on this at this point though as it's much more important to push #6530 forward. After that's done, reflinking would be an extremely minor optimisation; probably not signficant enough to be worth considering.

    @Atemu Reflinking wouldn’t be significant for reducing the copies incurred by the eval, but it could still be significant in reducing the otherwise still necessary copies of inputs for the build itself, right?

  17. Atemu commented on Oct 3, 2024

    @Atemu
    Member

    I'm not sure what you mean by that. Reflink copies speed up copying any path to the Nix store aswell as reducing storage cost (though in an unpredictable manner) but the best thing to do on any case is to copy as few things to the Nix store as possible.

    For reducing copies between existing build inputs in the Nix store, the right tool is Nix store optimisation as @fgaz mentioned and it's filesystem-agnostic.

  18. nixos-discourse commented on Oct 27, 2024

    @nixos-discourse
  19. nixos-discourse commented on Nov 9, 2024

    @nixos-discourse

    This issue has been mentioned on NixOS Discourse. There might be relevant details there:

    https://discourse.nixos.org/t/how-can-i-delete-sensitive-information-copied-into-nix-store-by-flake/55782/1

  20. nixos-discourse commented on Jan 22, 2025

    @nixos-discourse

    This issue has been mentioned on NixOS Discourse. There might be relevant details there:

    https://discourse.nixos.org/t/flakes-for-development-in-large-repos/59180/3

  21. added a commit that references this issue on Mar 20, 2026
  22. xokdvium commented on Apr 19, 2026

    @xokdvium
    Contributor

    My attempt at doing this in #15711, @edolstra has done a lot of good work to make that PR possible, I'm just putting the pieces together. Feedback welcome of course.

  23. lisanna-dettwyler commented on Jun 9, 2026

    @lisanna-dettwyler
    Contributor

    Completed in #15711

  24. moved this from In Progress to Done in Nix UXon Jun 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    fetchingflakessignificant

    Projects

    • Status
      Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions