Path is not in the nix store during nixos-rebuild switch

I am trying to update and rebuild after several months (plus a new mobo and CPU), but am getting this error during rebuild: error: path '/nix/store/2cvzq9g5r5clwfzx3jng3kdh02zxqphy-linux-6.14-modules-shrunk/lib' is not in the Nix store. When I look in /nix/store/2cvzq9g5r5clwfzx3jng3kdh02zxqphy-linux-6.14-modules-shrunk/lib/modules the folder is 6.14.0-cachyos.

I was previously using the cachyos kernel from the Chaotic Nyx flake. I swapped to boot.kernelPackages = pkgs.linuxPackages_latest;, but am receiving the same error. Is it safe to just delete this path?

Post the output of nix --version, the exact command you ran, and ideally a link to your config or a minimal reproducible example.

nix --version          
nix (Nix) 2.18.5

Command I ran:

 nixos-rebuild switch --impure --show-trace
warning: Git tree '/etc/nixos' is dirty
building the system configuration...
warning: Git tree '/etc/nixos' is dirty
error: path '/nix/store/2cvzq9g5r5clwfzx3jng3kdh02zxqphy-linux-6.14-modules-shrunk/lib' is not in the Nix store

Here is my repo of /etc/nixos files: GitHub - Jaage/nix-desktop

Thanks for sharing your nix dotfiles. I was not able to reproduce your issue with them. You might have a corrupted nix store. Can you try running the following command with root permissions? nix-store --verify --check-contents --repair
If that won’t work, you might need to reinstall system. Don’t worry, installing NixOS does not wipe any data.

1 Like

That command returned:

reading the Nix store...
checking path existence...
checking link hashes...
checking store hashes...

Building again after that resulted in the same error error: path '/nix/store/2cvzq9g5r5clwfzx3jng3kdh02zxqphy-linux-6.14-modules-shrunk/lib' is not in the Nix store

Is it time to just reinstall? Is there better way to do that from console or just boot from the ISO USB?

Thanks for your help so far.

same issue as this Issue building linux kernel modules after Flake update

tldr there was a regression that broke building with nix 2.18.5, you can use a nix-shell like the following to build the configuration with a newer version of nix then swap to the resulting config:

{ pkgs ? import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/nixos-unstable.tar.gz") { } }:
pkgs.mkShell {
  packages = with pkgs; [
    nixVersions.latest
  ];
}
2 Likes

Thanks, I made a shell.nix with your snippet and ran nix-shell which had Nix 2.28.3. Unfortunately, I get a similar error when running sudo nixos-rebuild build --impure in that shell:

error: path '/nix/store/4kmcb587yz035l7wsrqnnjiiyb5hmc77-linux-6.14.5-modules-shrunk/lib' is not in the Nix store

Did I miss a step in building my configuration from that shell?

After changing my pinned nixpkgs to 24.11 and swapping from the latest linux kernel to cachyos latest I was able to build and switch to my new config.

What worked for me:

I think you would have needed to put nixos-rebuild itself into the mkShell, as your present nixos-rebuild doesn’t use an updated nix from $PATH but its own hard-coded one. I had to do a stunt like this to use the new self.submodules thing.

This worked for me, was on a really old version of nix

For those who come after:

# shell.nix
# nix-shell shell.nix

{ pkgs ? import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/nixos-unstable.tar.gz") { } }:
pkgs.mkShell {
  packages = with pkgs; [
    nixVersions.latest
    nixos-rebuild
  ];
}
3 Likes

Even more additional information for those who come after

I was unable to get this to work with just the shell above because my nix-daemon was still out of date.

I stopped my nix daemon (systemctl stop nix-daemon, systemctl stop nix-daemon-socket), sudo rmed the socket /nix/var/nix/daemon-socket/socket

I then started a nix daemon inside the shell from above (nix-daemon --daemon)
I then ran the rebuild in another shell, which then used that daemon and succeeded.

I hope this helps somebody in the future and saves them some time.

2 Likes

I just ran into this. In my case, it seems I had nix installed in root’s env. Took me a while to figure out why it wouldn’t update.

# nix --version
nix (Nix) 2.15.0
# nix-env -q
nix-2.15.0
# nix-env -e nix
uninstalling 'nix-2.15.0'
building '/nix/store/xsk9wjy0dpp7w7d3r3bkzxzaklqdzq6q-user-environment.drv'...
# nix --version
nix (Nix) 2.28.2

After fixing that, the update went through…

I’m also getting error: path '/nix/store/5ki9j1nrvdjw9fqvn7d6a2n8dgmv05al-linux-6.12.55-modules-shrunk/lib' is not in the Nix store just now, with nix (Nix) 2.18.2 and daemon of the same version.

But that dir is in my nix store (exists /nix/store), and contains things.

# nix-store --delete /nix/store/5ki9j1nrvdjw9fqvn7d6a2n8dgmv05al-linux-6.12.55-modules-shrunk/lib
finding garbage collector roots...
0 store paths deleted, 0.00 MiB freed
error: Cannot delete path '/nix/store/5ki9j1nrvdjw9fqvn7d6a2n8dgmv05al-linux-6.12.55-modules-shrunk' since it is still alive. To find out why, use: nix-store --query --roots

# nix-store -r /nix/store/5ki9j1nrvdjw9fqvn7d6a2n8dgmv05al-linux-6.12.55-modules-shrunk/lib
warning: you did not specify '--add-root'; the result might be removed by the garbage collector
/nix/store/5ki9j1nrvdjw9fqvn7d6a2n8dgmv05al-linux-6.12.55-modules-shrunk

How can it claim these things, and simultaneously claim it’s not in there?

Deleting and re-fetching:

#  nix-store --delete $(nix-store -q --referrers-closure /nix/store/5ki9j1nrvdjw9fqvn7d6a2n8dgmv05al-linux-6.12.55-modules-shrunk/lib)
finding garbage collector roots...
deleting '/nix/store/lbrfvb2fnzcgfqql83qj08mn2lgs0bpp-boot.json'
deleting '/nix/store/dazb8wxyhl0gm6v7ni6zf1c1qza3csrk-initrd-linux-6.12.55'
deleting '/nix/store/a5m21c9l2gpz2v7jsxniqkz5xc99m8c2-boot.json'
deleting '/nix/store/cnlzkpm4n3ydvsjmwh74n9g1zi4zqhhh-initrd-linux-6.12.55'
deleting '/nix/store/5ki9j1nrvdjw9fqvn7d6a2n8dgmv05al-linux-6.12.55-modules-shrunk'
deleting unused links...
note: currently hard linking saves -0.00 MiB
5 store paths deleted, 26.47 MiB freed

# nix-store -r /nix/store/5ki9j1nrvdjw9fqvn7d6a2n8dgmv05al-linux-6.12.55-modules-shrunk/lib
this path will be fetched (2.35 MiB download, 2.53 MiB unpacked):
  /nix/store/5ki9j1nrvdjw9fqvn7d6a2n8dgmv05al-linux-6.12.55-modules-shrunk
copying path '/nix/store/5ki9j1nrvdjw9fqvn7d6a2n8dgmv05al-linux-6.12.55-modules-shrunk'

Then when trying to build, same error again.

My bisection claims

a041086e600fe605f1098061f4ac8893f804ce94 is the first bad commit
commit a041086e600fe605f1098061f4ac8893f804ce94
Author: zowoq <59103226+zowoq@users.noreply.github.com>
Date:   Thu Oct 23 22:10:40 2025 +0000

    linux_6_12: 6.12.54 -> 6.12.55

 pkgs/os-specific/linux/kernel/kernels-org.json | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
bisect found first bad commit

but I doubt that can really be the issue. However, reverting that allows me to at least build my NixOS VM tests to review PRs again…

This issue was a bug in Nix 2.18 that was fixed, at least by 2.18.9. See: Issue building linux kernel modules after Flake update - #8 by ElvishJerricco

1 Like