Nix flakes /nix/store/***-source no such file or directory

I was experiencing the same issue. A nix flake init did not work for me. But making arbitrary changes and committing them in git seemed to allow me to run it again it worked.

4 Likes

Hello,

I face the same bug…
I manage to rebuild my system when pinning NixOS to a specific commit but not when using nixos-unstable.
And I cannot get home-manager to work at all.
I wonder if this is fixable without reinstalling.

I do not use nix.registry.<name>.flake

EDIT: sudo nix-store --repair --verify --check-contents solved the issue !

5 Likes

Hey,
I was having the same issue, I moved my flake.nix, ran flake init (it generated a simple flake.nix, which I deleted), then moved my flake.nix back and everything worked.

6 Likes

I wound up here while looking for help with this error:

error: getting status of '/nix/store/d59fka53ir1das1085ly6hngj6ba1xm3-source/flake.nix': No such file or directory

Which I experienced after adding a flake.nix to a repo. Direnv was trying to build the environment, but then nix refused to see the file because it wasn’t added yet. I just had to git add flake.nix

15 Likes

I just ran into this issue on a newly initialized git repo where I had not yet committed anything. nix develop worked before I ran git init (one of the last things I did a while back). I came back a few days later and it was suddenly broken. Turns out merely running git add flake.nix fixed the problem.

I must say, this is an absolutely terrible error that provides absolutely no useful feedback. If a flake.nix file exists and is being ignored because it isn’t tracked by git, then the error should say so.

6 Likes

There is active work on a feature that would enable us such a report, though currently it is technically not possiboe to do such an error reporting.

I understand. I’m currently working with a company that is rolling out Nix flakes-based builds and development environment management across all their teams. There’s only a relative handful of Nix experts, while there are hundreds of developers that have never used Nix at all.

My concern is that people who know how to use Nix and see the benefit of flakes want to use it in production despite its “experimental” status (clearly it isn’t experimental anymore). Yet these rough-around-the-edges experiences might turn away the aforementioned newbie Nix users.

5 Likes

Thanks. That saved me some pain. I hear you. I’m that nix newbie and new to flakes. Loving nix, but have had to remain headstrong in not going back to typical linux work arounds I’m used to. Although, I’m sure this would have been the case pre-flakes. Getting into the habit of ensuring the current state I’m working with has been at least git add’ed. Turns out I didn’t have to commit the flake.nix so much just add it. A better error in such situations such as ‘have you checked that you’ve added a flake.nix’ would have been appreciated.

Much pain was caused because a file was not added to git. Please fix the error message or add a helpful hint if it is not possible to know for sure.

4 Likes

This solved it for me, thanks.

1 Like

Just ran into this error. Nothing fixed it, only to realize I had previously changed the folder name where I keep my nixos configs and not changed it in the flake that imports it.
So heads up for anyone, this can be a cause too.

i got this error when i moved hardware-configuration.nix into a sub folder system/. In turns out i had hardware-configuration.nix in my .gitgnore file which seemed to be blocking the nix build from seeing it. i fixed with git add -f system/hardware-configuration.nix and then rebuilding.

1 Like

I had this error when attempting to initialize a flake template

$ nix flake init -t github:purs-nix/purs-nix
error: opening directory '/nix/store/2hbz2waa9pscqv8yrm6f581b5vlzh52z-default': No such file or directory

Tried many things unsuccessfully including what other people reported as success in here.
In the end I solved the problem by deleting ~/.cache/nix.

just adding flake.nix file to git , i.e. git add flake.nix solved this for me.

Thank you all this thread was a great resource.

I had no idea about this. I ran into this issue in two separate projects, where I could build a source file with Cabal just fine outside of nix develop or nix build, I’d get an error like:

> Error: Setup: can't find source for SomeSourceFile in src, dist/build/autogen,
> dist/build/global-autogen

Doing a git add on the file allowed me to build just fine after.

1 Like

Also make sure that the flake is already in the repo. If not use
git add flake.nix
In my case it was as simple as that as the repo contained a shell.nix file previously and I just forgot to add the flake.nix

1 Like

For me, adding it to git was the way to go. The error message was not very explanatory this time :slight_smile:

I realise this is an old topic but this error is incredibly confusing.

Why does nixos-rebuild care about whether the contents are version controlled.

This sequence of commands makes no sense:

nixos-rebuild ... [works perfectly]
git init
nixos-rebuild ... [broken with unobvious error message]

Without changing a thing in the configuration nixos-rebuild works or not based on whether another unrelated command has been run.

Worse, you can’t load files which aren’t tracked by git. I had a private directory full of nix files that created things like .ssh and my sublime text licence key.

Plan was to push my config to github with those ignored via .gitignore but the coupling of nixos-rebuild and git breaks that approach

Answered here - Why can't nixos-rebuild see files that aren't in the git repository? - #2 by waffle8946

Just came across this today. I built a project and then when I was ready to initialize my git repo it started acting up. Everything worked fine (building a python env with a requirements.txt) after committing the flake to the newly created repo.