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

**URL:** https://discourse.nixos.org/t/nix-flakes-nix-store-source-no-such-file-or-directory/17836
**Category:** Help
**Created:** [February 21, 2022, 11:20pm UTC](https://discourse.nixos.org/t/nix-flakes-nix-store-source-no-such-file-or-directory/17836 "2022-02-21T23:20:25Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![emmanuelrosa](https://discourse.nixos.org/user_avatar/discourse.nixos.org/emmanuelrosa/32/1924_2.png) [@emmanuelrosa](https://discourse.nixos.org/u/emmanuelrosa)
#### Post date: [February 21, 2022, 11:20pm UTC](https://discourse.nixos.org/t/nix-flakes-nix-store-source-no-such-file-or-directory/17836/1 "2022-02-21T23:20:25Z")

</div>

A problem I keep running into with flakes is that by builds fail after running `nix-collected-garbage -d`. Here’s an example:

```auto
nix build .#whatever
warning: Git tree '/home/emmanuel/projects/erosanix' is dirty
error (ignored): error: end of string reached
error: getting status of '/nix/store/cwihclkh4g6wghh67nq9lyswfjh650im-source': No such file or directory
(use '--show-trace' to show detailed location information)

```

The path matches the nixpkgs pinned in my flakes.lock:

```auto
{
  "nodes": {
    "nixpkgs": {
      "locked": {
        "lastModified": 1642770210,
        "narHash": "sha256-2kMgAMy3ThQP5UvHkV/z2zMkoml9bQhatEzCpLq5Iwc=",
        "path": "/nix/store/cwihclkh4g6wghh67nq9lyswfjh650im-source",
        "rev": "0bef0d60524fcdb2b609625e34d5c224e150c17a",
        "type": "path"
      },
      "original": {
        "id": "nixpkgs",
        "type": "indirect"
      }
    },
    "root": {
      "inputs": {
        "nixpkgs": "nixpkgs"
      }
    }
  },
  "root": "root",
  "version": 7
}

```

I suspect this happens because I use “follows” in order to avoid using a bunch of different versions of Nixpkgs:

```auto
inputs.nixpkgs.url = "github:NixOS/nixpkgs/master";
inputs.agenix.url = "github:ryantm/agenix";
inputs.agenix.inputs.nixpkgs.follows = "nixpkgs";
inputs.erosanix.url = "github:emmanuelrosa/erosanix";
inputs.erosanix.inputs.nixpkgs.follows = "nixpkgs";

```

I can’t figure out how to get the Nixpkgs version I need (ex. /nix/store/cwihclkh4g6wghh67nq9lyswfjh650im-source) back in the Nix store. Using `nixos-rebuild built --flake` works only after updating my inputs with `nix flake update`. In other words, it won’t bring back the one that I need.

I don’t want to update Nixpkgs right now because as you can see, I use the master branch which is having issues at the moment.

---

<div class="post-metadata">

### Author: ![NobbZ](https://discourse.nixos.org/user_avatar/discourse.nixos.org/nobbz/32/7022_2.png) [@NobbZ](https://discourse.nixos.org/u/NobbZ)
#### Post date: [February 21, 2022, 11:33pm UTC](https://discourse.nixos.org/t/nix-flakes-nix-store-source-no-such-file-or-directory/17836/2 "2022-02-21T23:33:34Z")

</div>

> [@emmanuelrosa](#):
>
> ` "path": "/nix/store/cwihclkh4g6wghh67nq9lyswfjh650im-source",`

For some reason the flake was locked to a local path. You can not reconstruct it. Though there is a `rev` in the metadata, if you are lucky you can use `nix build github:nixos/nixpkgs/0bef0d60524fcdb2b609625e34d5c224e150c17a#hello` to recosntruct the nixpkgs.

At least I had exactly that path after I ran the command.

I do not think, that this is from follows, usually this happens when manually overriding with commit.

---

<div class="post-metadata">

### Author: ![emmanuelrosa](https://discourse.nixos.org/user_avatar/discourse.nixos.org/emmanuelrosa/32/1924_2.png) [@emmanuelrosa](https://discourse.nixos.org/u/emmanuelrosa)
#### Post date: [February 21, 2022, 11:38pm UTC](https://discourse.nixos.org/t/nix-flakes-nix-store-source-no-such-file-or-directory/17836/3 "2022-02-21T23:38:10Z")

</div>

OK. I’m not sure how I’m doing that, but I found a fix. I got the version of Nixpkgs from `nixos-version` and then ran this:  
`nix build --override-input nixpkgs github:NixOS/nixpkgs/add2ba16087cfb104a2ccfbb60630492627c996a .#whatever`

This will get me by until my next update.

---

<div class="post-metadata">

### Author: ![NobbZ](https://discourse.nixos.org/user_avatar/discourse.nixos.org/nobbz/32/7022_2.png) [@NobbZ](https://discourse.nixos.org/u/NobbZ)
#### Post date: [February 21, 2022, 11:53pm UTC](https://discourse.nixos.org/t/nix-flakes-nix-store-source-no-such-file-or-directory/17836/4 "2022-02-21T23:53:02Z")

</div>

Are you sure that is the correct commit? And not one you got by updating in-between?

In the lock file you pasted there’s clearly a git commit visible, that belongs to master from end of January.

---

<div class="post-metadata">

### Author: ![emmanuelrosa](https://discourse.nixos.org/user_avatar/discourse.nixos.org/emmanuelrosa/32/1924_2.png) [@emmanuelrosa](https://discourse.nixos.org/u/emmanuelrosa)
#### Post date: [February 22, 2022, 1:27am UTC](https://discourse.nixos.org/t/nix-flakes-nix-store-source-no-such-file-or-directory/17836/5 "2022-02-22T01:27:13Z")

</div>

I don’t know. I’m utterly confused. I tried the commit in the lock file, but Nix began to download a ton of files. I bet that was correct, but I really just wanted to use whatever Nixpkgs I already had.

It did allow me to build my flake, which is what I needed.

---

<div class="post-metadata">

### Author: ![B4dM4n](https://discourse.nixos.org/user_avatar/discourse.nixos.org/b4dm4n/32/2042_2.png) [@B4dM4n](https://discourse.nixos.org/u/B4dM4n)
#### Post date: [February 22, 2022, 7:35am UTC](https://discourse.nixos.org/t/nix-flakes-nix-store-source-no-such-file-or-directory/17836/6 "2022-02-22T07:35:38Z")

</div>

The locking to a local path can happen if you use the [nix.registry.\<name\>.flake](https://search.nixos.org/options?channel=21.11&show=nix.registry.%3Cname%3E.flake&from=0&size=50&sort=relevance&type=packages&query=nix.registry+flake) option or otherwise pin `nixpkgs` in the flake registry.

If you then do a `nix flake update` on a flake, wich uses the plain `nixpkgs` input, this input will get locked to the path specified by the pinned registry entry.

So if you use registry pinning, I would suggest to replace the `nixpkgs` input of your flake with `github:NixOS/nixpkgs/nixos-unstable` or similar to avoid the pinned registry entry.

---

<div class="post-metadata">

### Author: ![steve-chavez](https://discourse.nixos.org/user_avatar/discourse.nixos.org/steve-chavez/32/6687_2.png) [@steve-chavez](https://discourse.nixos.org/u/steve-chavez)
#### Post date: [June 15, 2022, 9:39pm UTC](https://discourse.nixos.org/t/nix-flakes-nix-store-source-no-such-file-or-directory/17836/7 "2022-06-15T21:39:38Z")

</div>

Had the same issue after running `nix shell github:name/repo`. Then I got the `no such file or directory` when creating a `flake.nix` and running flakes command on it. A `nix flake init` solved the issue.

---

<div class="post-metadata">

### Author: ![ctrlsquid](https://discourse.nixos.org/user_avatar/discourse.nixos.org/ctrlsquid/32/7068_2.png) [@ctrlsquid](https://discourse.nixos.org/u/ctrlsquid)
#### Post date: [August 11, 2022, 7:38pm UTC](https://discourse.nixos.org/t/nix-flakes-nix-store-source-no-such-file-or-directory/17836/8 "2022-08-11T19:38:05Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![glepage](https://discourse.nixos.org/user_avatar/discourse.nixos.org/glepage/32/35129_2.png) [@glepage](https://discourse.nixos.org/u/glepage)
#### Post date: [December 19, 2022, 10:47am UTC](https://discourse.nixos.org/t/nix-flakes-nix-store-source-no-such-file-or-directory/17836/9 "2022-12-19T10:47:57Z")

</div>

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 !

---

<div class="post-metadata">

### Author: ![matttrach](https://discourse.nixos.org/user_avatar/discourse.nixos.org/matttrach/32/8109_2.png) [@matttrach](https://discourse.nixos.org/u/matttrach)
#### Post date: [December 19, 2022, 8:11pm UTC](https://discourse.nixos.org/t/nix-flakes-nix-store-source-no-such-file-or-directory/17836/10 "2022-12-19T20:11:40Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![MattRixman](https://discourse.nixos.org/user_avatar/discourse.nixos.org/mattrixman/32/11541_2.png) [@MattRixman](https://discourse.nixos.org/u/MattRixman)
#### Post date: [December 28, 2022, 4:05pm UTC](https://discourse.nixos.org/t/nix-flakes-nix-store-source-no-such-file-or-directory/17836/11 "2022-12-28T16:05:11Z")

</div>

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

```auto
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`

---

<div class="post-metadata">

### Author: ![christian](https://discourse.nixos.org/user_avatar/discourse.nixos.org/christian/32/1009_2.png) [@christian](https://discourse.nixos.org/u/christian)
#### Post date: [April 12, 2023, 7:34am UTC](https://discourse.nixos.org/t/nix-flakes-nix-store-source-no-such-file-or-directory/17836/12 "2023-04-12T07:34:50Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![NobbZ](https://discourse.nixos.org/user_avatar/discourse.nixos.org/nobbz/32/7022_2.png) [@NobbZ](https://discourse.nixos.org/u/NobbZ)
#### Post date: [April 12, 2023, 7:58am UTC](https://discourse.nixos.org/t/nix-flakes-nix-store-source-no-such-file-or-directory/17836/13 "2023-04-12T07:58:25Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![christian](https://discourse.nixos.org/user_avatar/discourse.nixos.org/christian/32/1009_2.png) [@christian](https://discourse.nixos.org/u/christian)
#### Post date: [April 13, 2023, 3:58pm UTC](https://discourse.nixos.org/t/nix-flakes-nix-store-source-no-such-file-or-directory/17836/14 "2023-04-13T15:58:37Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![fiq](https://discourse.nixos.org/user_avatar/discourse.nixos.org/fiq/32/10016_2.png) [@fiq](https://discourse.nixos.org/u/fiq)
#### Post date: [July 9, 2023, 1:36am UTC](https://discourse.nixos.org/t/nix-flakes-nix-store-source-no-such-file-or-directory/17836/15 "2023-07-09T01:36:24Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![mcmah309](https://discourse.nixos.org/user_avatar/discourse.nixos.org/mcmah309/32/12233_2.png) [@mcmah309](https://discourse.nixos.org/u/mcmah309)
#### Post date: [August 22, 2023, 5:26am UTC](https://discourse.nixos.org/t/nix-flakes-nix-store-source-no-such-file-or-directory/17836/16 "2023-08-22T05:26:42Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![malteneuss](https://discourse.nixos.org/user_avatar/discourse.nixos.org/malteneuss/32/6874_2.png) [@malteneuss](https://discourse.nixos.org/u/malteneuss)
#### Post date: [October 14, 2023, 10:01am UTC](https://discourse.nixos.org/t/nix-flakes-nix-store-source-no-such-file-or-directory/17836/17 "2023-10-14T10:01:09Z")

</div>

> [@glepage](#):
>
> EDIT: `sudo nix-store --repair --verify --check-contents` solved the issue !

This solved it for me, thanks.

---

<div class="post-metadata">

### Author: ![Sophia](https://discourse.nixos.org/user_avatar/discourse.nixos.org/sophia/32/8792_2.png) [@Sophia](https://discourse.nixos.org/u/Sophia)
#### Post date: [October 21, 2023, 5:43pm UTC](https://discourse.nixos.org/t/nix-flakes-nix-store-source-no-such-file-or-directory/17836/18 "2023-10-21T17:43:30Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![mars0008](https://discourse.nixos.org/user_avatar/discourse.nixos.org/mars0008/32/11649_2.png) [@mars0008](https://discourse.nixos.org/u/mars0008)
#### Post date: [November 8, 2023, 12:33pm UTC](https://discourse.nixos.org/t/nix-flakes-nix-store-source-no-such-file-or-directory/17836/19 "2023-11-08T12:33:27Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![michelrandahl](https://discourse.nixos.org/user_avatar/discourse.nixos.org/michelrandahl/32/4754_2.png) [@michelrandahl](https://discourse.nixos.org/u/michelrandahl)
#### Post date: [February 1, 2024, 10:28pm UTC](https://discourse.nixos.org/t/nix-flakes-nix-store-source-no-such-file-or-directory/17836/20 "2024-02-01T22:28:28Z")

</div>

I had this error when attempting to initialize a flake template

```auto
$ 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`.

[Next page](https://discourse.nixos.org/t/nix-flakes-nix-store-source-no-such-file-or-directory/17836.md?page=2)
