File in nix store empty, unable to be repaired

I’ve been trying out nixos for a few days, and I recently ran into trouble. Whenever I run any sort of nix-env command, I get an error like this: error: syntax error, unexpected end of file, at /nix/store/9xdi4s14daz4s89i2zx10g26ij3hkdr6-env-manifest.nix:1:1

I ran nix-store --verify-path /nix/store/9xdi4s14daz4s89i2zx10g26ij3hkdr6-env-manifest.nix and it indicates that the file was modified. However, nix-store --repair-path ... is unable to repair it.

I queried the store, and found that whatever package it is, it’s depended on by gtk3. If it was a different package, I might be able to get rid of it temporarily, run the garbage collector, and then re-install it. However, since gtk3 is a pretty important piece of software, I can’t exactly easily remove it.

How would I go about repairing this?

1 Like

nix-store --verify --check-contents --repair can take a long time, but generally solves most nix store woes

2 Likes

I ran the command, and it found two modified files, but it was unable to repair either of them:

reading the Nix store...
checking path existence...
checking hashes...
path '/nix/store/9xdi4s14daz4s89i2zx10g26ij3hkdr6-env-manifest.nix' was modified! expected hash 'sha256:09c3brbj3s1s7balh9n4jbm689ly9mshb5rr9lq69gdvpliqjcf9', got 'sha256:0ip26j2h11n1kgkz36rl4akv694yz65hr72q4kv4b3lxcbi65b3p'
error: cannot repair path '/nix/store/9xdi4s14daz4s89i2zx10g26ij3hkdr6-env-manifest.nix'
path '/nix/store/j6smxadd5fphms8hix1fvvxw2mbc6wzb-user-environment.drv' was modified! expected hash 'sha256:0p2hr55g7zjdr5w2s0gi07jrxjhjcvmcmzfhcp1hazd16jvcfxkd', got 'sha256:0ip26j2h11n1kgkz36rl4akv694yz65hr72q4kv4b3lxcbi65b3p'
error: cannot repair path '/nix/store/j6smxadd5fphms8hix1fvvxw2mbc6wzb-user-environment.drv'
warning: not all errors were fixed

If the files cannot be automatically repaired, what are my options to fix them?

well, the question is ‘why’ is that happening?

do you have bad hardware? memory errors, hard disk failure?

or is something modifying your filesystem without your knowledge.

you don’t give us much info on what your running…

be interested to start on a fresh system, and try and reproduce the steps to this failure? what did you do?

1 Like

Are the problematic store paths alive, or can you delete them with nix-store --delete and then recreate them and see if they’re still broken? (In theory you can delete live paths using the --ignore-liveness option. However, depending which paths you delete, that could have consequences)

Try setting nix.autoOptimiseStore = false;

So I reinstalled NixOS, hoping that a clean install would fix it, but it didn’t, not too sure as to why though. I find it hard to believe that a completely new install would carry the same issues (but I guess Nix is reproducible, even the problems).

At first I reinstalled, using my normal config, which didn’t work. Then, I reinstalled with a semi-minimal config (just KDE and some basic packages) and had the same problems.

I literally have no idea what would be causing this, it feels like I’ve tried most simple solutions, and haven’t found one that works.

Normally I wouldn’t mind this too much, I can still build my config, but home manager can’t run so I can’t config user-level applications. Does anyone know what’s going on here?

this looks like it might be related to ca-derivations. It’s still an experimental feature, and you may have it an edge case

The exact same thing happened to me a week ago. I did have ca-derivations and keep-derivations enabled in nix.conf, and auto-optimise-store = false by the way.

Unfortunately, nix-store --repair did not work!!

Log of what happened to me

Here’s a more complete log of what happened. I can’t remember the nixpkgs rev off the top of my head though.

root@tethys:~ # nixos-rebuild switch                                                                                                                   
this derivation will be built:
  /nix/store/78mw9fbgdmn7jbpqkam53smy3jxhkpzz-nixos-rebuild.drv
building '/nix/store/78mw9fbgdmn7jbpqkam53smy3jxhkpzz-nixos-rebuild.drv'...
/nix/store/a9skvgykplgx882i0wgf3k4gqj7nm9i2-stdenv-linux/setup: line 754: /nix/store/wj4z7145vcph0mp3h78afvi7h6v0k0kj-nixos-rebuild/bin/nixos-rebuild: No such file or directory
error: builder for '/nix/store/78mw9fbgdmn7jbpqkam53smy3jxhkpzz-nixos-rebuild.drv' failed with exit code 1
building Nix...
nix-instantiate: error while loading shared libraries: /nix/store/79lh7p2jjwqimzwksnpaclc3zj42zqda-openssl-1.1.1k/lib/libcrypto.so.1.1: file too short
building the system configuration...
nix-build: error while loading shared libraries: /nix/store/79lh7p2jjwqimzwksnpaclc3zj42zqda-openssl-1.1.1k/lib/libcrypto.so.1.1: file too short
root@tethys:~ # nix-store --repair-path /nix/store/79lh7p2jjwqimzwksnpaclc3zj42zqda-openssl-1.1.1k                                                       
copying path '/nix/store/79lh7p2jjwqimzwksnpaclc3zj42zqda-openssl-1.1.1k' from 'https://cache.nixos.org'...

root@tethys:~ # nixos-rebuild switch                                                                                                                     
this derivation will be built:
  /nix/store/78mw9fbgdmn7jbpqkam53smy3jxhkpzz-nixos-rebuild.drv
building '/nix/store/78mw9fbgdmn7jbpqkam53smy3jxhkpzz-nixos-rebuild.drv'...
/nix/store/a9skvgykplgx882i0wgf3k4gqj7nm9i2-stdenv-linux/setup: line 754: /nix/store/wj4z7145vcph0mp3h78afvi7h6v0k0kj-nixos-rebuild/bin/nixos-rebuild: No such file or directory
error: builder for '/nix/store/78mw9fbgdmn7jbpqkam53smy3jxhkpzz-nixos-rebuild.drv' failed with exit code 1
building Nix...
nix-instantiate: error while loading shared libraries: /nix/store/0mb2vd16sclqn9h6gsm64il4hfiwgwn3-bzip2-1.0.6.0.2/lib/libbz2.so.1: file too short
building the system configuration...
nix-build: error while loading shared libraries: /nix/store/0mb2vd16sclqn9h6gsm64il4hfiwgwn3-bzip2-1.0.6.0.2/lib/libbz2.so.1: file too short

root@tethys:~ # nix-store --repair-path /nix/store/0mb2vd16sclqn9h6gsm64il4hfiwgwn3-bzip2-1.0.6.0.2/lib/libbz2.so.1                                                    
copying path '/nix/store/0mb2vd16sclqn9h6gsm64il4hfiwgwn3-bzip2-1.0.6.0.2' from 'https://cache.nixos.org'...

root@tethys:~ # nixos-rebuild switch                                                                                                                                   
this derivation will be built:
  /nix/store/78mw9fbgdmn7jbpqkam53smy3jxhkpzz-nixos-rebuild.drv
building '/nix/store/78mw9fbgdmn7jbpqkam53smy3jxhkpzz-nixos-rebuild.drv'...
/nix/store/a9skvgykplgx882i0wgf3k4gqj7nm9i2-stdenv-linux/setup: line 754: /nix/store/wj4z7145vcph0mp3h78afvi7h6v0k0kj-nixos-rebuild/bin/nixos-rebuild: No such file or directory
error: builder for '/nix/store/78mw9fbgdmn7jbpqkam53smy3jxhkpzz-nixos-rebuild.drv' failed with exit code 1
building Nix...
nix-instantiate: error while loading shared libraries: /nix/store/9xnwvyzm8x3d7kk3lsvy9wyjdf684x5w-zlib-1.2.11/lib/libz.so.1: file too short
building the system configuration...
nix-build: error while loading shared libraries: /nix/store/9xnwvyzm8x3d7kk3lsvy9wyjdf684x5w-zlib-1.2.11/lib/libz.so.1: file too short

root@tethys:~ # nix-store --repair-path /nix/store/9xnwvyzm8x3d7kk3lsvy9wyjdf684x5w-zlib-1.2.11/lib/libz.so.1                                                          
copying path '/nix/store/9xnwvyzm8x3d7kk3lsvy9wyjdf684x5w-zlib-1.2.11' from 'https://cache.nixos.org'...

root@tethys:~ # nixos-rebuild switch                                                                                                                                
this derivation will be built:
  /nix/store/78mw9fbgdmn7jbpqkam53smy3jxhkpzz-nixos-rebuild.drv
building '/nix/store/78mw9fbgdmn7jbpqkam53smy3jxhkpzz-nixos-rebuild.drv'...
/nix/store/a9skvgykplgx882i0wgf3k4gqj7nm9i2-stdenv-linux/setup: line 754: /nix/store/wj4z7145vcph0mp3h78afvi7h6v0k0kj-nixos-rebuild/bin/nixos-rebuild: No such file or directory
error: builder for '/nix/store/78mw9fbgdmn7jbpqkam53smy3jxhkpzz-nixos-rebuild.drv' failed with exit code 1
building Nix...
nix-instantiate: error while loading shared libraries: /nix/store/g53fspaj03xks0zrknm4vbng04rcl5b1-acl-2.3.1/lib/libacl.so.1: file too short
building the system configuration...
nix-build: error while loading shared libraries: /nix/store/g53fspaj03xks0zrknm4vbng04rcl5b1-acl-2.3.1/lib/libacl.so.1: file too short
root@tethys:~ # 

My current nixos system generation was working perfectly, but many - if not all - of the store dependencies of the new system derivation that I was trying to build were all messed up as described by @ajkachnic.

Basic dependencies like /nix/store/79lh7p2jjwqimzwksnpaclc3zj42zqda-openssl-1.1.1k/lib/libcrypto.so.1.1 were truncated to zero length. There were many .drv files in /nix/store which were empty. These prevented nix-store --verify --repair from working because Nix couldn’t parse an empty derivation.

I needed to do this to fix it:

nix-store --query --referrers-closure $(find /nix/store -maxdepth 1 -type f -name '*.drv' -size 0)  | xargs nix-store --delete --ignore-liveness
nix-store --gc
nix-store --verify --check-contents --repair
10 Likes

Unfortunately this hasn’t helped me. Do you have any other suggestions?

found this reddit post that helped me, don’t know about it’s safety:

Comment
byu/adivinity from discussion
inNixOS

I then rebuilt the system, checked the store, repaired it, garbage collected and optimised no problems, then rebooted, no problems still