Skip to content

Flakes: Not including untracked files is confusing for unaware users. #7107

Open

Description

@ElvishJerricco

As flakes become more and more common, so too is the issue that untracked files aren't included when your flake is copied to the nix store. Personally, I consider this behavior a good thing, as it prevents me from accidentally copying result symlinks or nixos.qcow2 images into the store unnecessarily. But in my experience assisting users on Matrix and Discourse, it's a common error to not track a necessary file with git. This manifests with users being very confused why their shiny new code seems to not exist at all.

I'm not sure what the answer is here. Again, I personally prefer the current behavior, but clearly it's a problem for people who are unaware of the cause. I figured there should be an open issue to at least discuss the matter.

Activity

  1. silky commented on Sep 27, 2022

    @silky
    Member

    Thanks for making this issue :)

    I'd honestly be happy/expect to see this pop up when running adding some verbosity to the commands; it's what I tried to do to debug the issue, and was left confused when additional v's didn't yield me any particularly relevant hints ....

  2. Kha commented on Sep 28, 2022

    @Kha
    Contributor

    Relevant: #6858 (comment) and following comments

  3. squalus commented on Dec 27, 2022

    @squalus
    Contributor

    For anyone else running into this, here's how to include untracked files:
    nix build path:///path/to/myflake#mypackage.

    The entire flake directory gets copied to the Nix store in this case.

  4. Atemu commented on Jan 1, 2023

    @Atemu
    Member

    With #6530, the problem of accidentally copying large untracked files should no longer exist.

    I think it'd make sense to disable the unintuitive git integration then.

    I'm all for integrating different tools with another but that should always be an optional feature. A build tool should not care about which VCS I'm using or what its state is; especially not by default. (Being able to fetch a build expression via git is a great feature though.)

  5. andrewhamon commented on Jan 6, 2023

    @andrewhamon
    Contributor

    I too was pretty surprised at the tight git integration, and it makes certain things impossible, like conditionally importing an untracked file that may or may not exists (i.e. poor mans secret management, or a way to let folks customize a nix shell in a large shared repo).

  6. silky commented on Jan 6, 2023

    @silky
    Member

    Depending on your setup @andrewhamon you might be interested in something like this - https://github.com/hasura/graphql-engine/blob/master/.envrc#L59 - to source a local .envrc file.

  7. bergkvist commented on Jan 11, 2023

    @bergkvist
    Member

    Even being familiar with this behavior, I find it cumbersome/unintuitive, and it is one of my biggest barriers to moving from traditional nix over to flakes.

    What if instead of using the git staging area, there was a .flakeignore, similar to .dockerignore/.gitignore? I think this would be a lot more intuitive to new users, and could provide similar benefits in a more flexible way.

    It might also be a step towards decoupling nix flakes and git - such that companies that use alternatives to git for version control would actually be able to adopt flakes as well.

  8. outfoxxed commented on Jan 21, 2023

    @outfoxxed
    Member

    It is also extremely frustrating on nixos with direnv for development environments, where the project does not need or want the flake in version control. I have to remove the nix files from git, commit, and re-add them. The only reason for these flakes to exist is to set up my local dev env.

  9. tejing1 commented on Jan 25, 2023

    @tejing1

    Could nix by default use path:. instead of git+file:. when flake.nix is untracked and/or gitignored? It would at least streamline the local-only flake.nix usecase.

  10. ryanalta commented on Feb 1, 2023

    @ryanalta

    Being newish to nix and flakes I'm definitely in the user group of of 'unaware users'. One problem I run into is that I might want a .env in the development shell, but definitely don't want to track in git (it's in my .gitignore so I don't accidentally add, commit and push it).

    I'm not sure what the best practice is for this with flakes, but my first guess of having an .env file in the directory with flake.nix appears to be wrong.

  11. mwotton commented on Apr 28, 2023

    @mwotton

    I think the behaviour is right, but some breadcrumbs in the error message about it being potentially related to source control would be very much appreciated.

  12. 1oglop1 commented on Sep 10, 2023

    @1oglop1

    It would be great to have a warning or hint if the local file is untracked.
    It is my second day of learning nix and this behaviour is quite confusing.
    Because the problem with untracked files appears only inside the git repo which I have not initialized for small learning projects, then after progressing towards a more real project I kept getting the error No such file or directory and it took me some time to realize that it may be an untracked file.

  13. agraven commented on Nov 29, 2023

    @agraven

    Another factor that exacerbated the confusion for me is that this behavior also aplloes wheb you are in an ignored subfolder of a repo with a root higher up the tree. I sync my dotfiles by making my $HOME a git repo, so when i went into my projects directory and attempted to create a flake with nix flake init, it failed to build with an extremely unhelpful "No such file or directory" error that provided zero indication what the actual problem was.

  14. nixos-discourse commented on Jan 7, 2024

    @nixos-discourse
  15. 9 remaining items

  16. nixos-discourse commented on Nov 3, 2024

    @nixos-discourse

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

    https://discourse.nixos.org/t/path-nix-store-does-not-exist/55413/4

  17. jwdevantier commented on Jan 14, 2025

    @jwdevantier

    Just to point out. it is path:<flake-ref> not :path<flake-ref>, aside from that, it does fix the issue.

    I just want to point out also that this STILL happens even if operating in a sub-directory which is explicitly ignored by .gitignore.
    I think this is deeply unintuitive, and does more harm than good.

    Why would you have files in an ignored directory, you ask ? For example, you may be generating these configuration files - and there might be good reasons for that.

  18. Ev357 commented on Feb 8, 2025

    @Ev357

    I'm sure that there is a good reason for this behaviour, but maybe an option to disable this for quick testing?

  19. eclairevoyant commented on Feb 8, 2025

    @eclairevoyant
    Contributor

    A dozen workarounds have been mentioned upthread e.g. #7107 (comment) and #7107 (comment), can this not become a support thread asking the same questions repeatedly?

  20. brbsleepy commented on May 30, 2025

    @brbsleepy

    hello, i just stepped on this rake.

    redirected from the helpful people here:
    https://discourse.nixos.org/t/path-nix-store-does-not-exist/55413/2

    i'd love to see some mention of git tracking in the error message

  21. sleroq commented on Jun 4, 2025

    @sleroq
    Member

    Having to commit files

    Reminder that you do not need to commit anything. git add -N is sufficient if you don't want to stage the changes yet.

    edit: thumbs down notwithstanding, my statement is still correct.

    Thank you for the git add -N tip.

    To add to that, for not committing files by accident, I use git update-index --skip-worktree <your-file>. So, it won't even show up as modified when you go to commit.

    And you can add it to your Nix dev shell if you want to make it automatic for all contributors.

    Hope this helps someone to not commit private info to GitHub.

  22. non-bin commented on Jul 7, 2025

    @non-bin

    Just spent half an hour debugging because of this, I'm a seasoned nix user and I just forgot. I don't think it would be hard to add a check like this:

    if (!exists('git+file:'+filePath) && exists('file:'+filePath)) {
      print('Did you forget to stage '+filePath+'?');
    }

    It might involve making a list of untracked files during pre-build and keeping it around in case of an error. Maybe I'll take a look sometime

  23. gauravjuvekar commented on Jul 7, 2025

    @gauravjuvekar

    It seems like there is a related recent regression, though I haven't been able to bisect it to an exact nix commit yet.

    Observed:
    If your .git points to a different directory gitdir: /some/other/path, then nix behaves as if the repo was not updated even if changes are staged / committed. Adding --refresh to the nix command line fixes that.

  24. non-bin commented on Jul 7, 2025

    @non-bin

    What was the behaviour before the regression?

  25. gauravjuvekar commented on Jul 10, 2025

    @gauravjuvekar

    Before the regression, it will correctly pick up all staged / committed changes even if the .git directory lives outside directory containing the flake.nix.

  26. non-bin commented on Jul 11, 2025

    @non-bin

    oh, that's not my issue :P
    I just forget to stage new files

  27. nixos-discourse commented on Jul 28, 2025

    @nixos-discourse
  28. nixos-discourse commented on Sep 17, 2025

    @nixos-discourse
  29. nixos-discourse commented on Nov 1, 2025

    @nixos-discourse
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions