I garbage collected a bit too eagerly now system flake won't build

I did a garbage collection run. And since then things are a bit weird.

I have my nix conf here for reference nix-conf/nix at main · tbaumann/nix-conf · GitHub

When ? run nixos-rebuild it comlains that it can’t see the content of the repo in the nix store.

[snip]
┃        error: getting status of '/nix/store/9rfm0lnhf6hhpdqmpxnvbcnmm2l9znfr-source/flake.nix': No such file or directory
┣

I can remove inputs from the flake and it just complains about the next…

Why does it complain about the nix store instead of just building it where it is? I tried nix flake update, doesn’t change anything.

I’m a bit lost. Either put it in the store if it’s needed or just use the file locally. I never hat this before. I was using this config for months.

Something else is a bit weird. I have a huge amount of nixos generations. If I try to clear them nothing happens. Is that perhaps another sign that there is something fucked about my store?

~ 
› nixos-rebuild list-generations|wc -l
139

~ took 8s 
› nix-env --delete-generations +5

~ 
› nixos-rebuild list-generations|wc -l
139

Try adding ?dir=nix to your flake reference i.e. run nixos-rebuild --flake github:tbaumann/nix-conf?dir=nix (you might need to escape the question mark or put the flake reference in quotes). This is because a flake reference by default reefers to the root of a git repository.

nix-env --delete-generations by default, only deletes generations within /nix/var/nix/profiles/per-user/$USER, try running either sudo nix-env --delete-generations -p /nix/var/nix/profiles/system or sudo nix-collect-garbage -d

Thanks @MaxHearnden for the sudo trick. I assumed because I’m trusted user I would be allowed to do system level cleanup without sudo :smiley:

I will play around with the dir thing. I usually don’t build from the repo. I just use

nixos-rebuild switch --flake '.#zuse' --impure 

But somehow the fact that it’s a git repo matters even though this is just a local file.

Even if I move the .git directory away it won’t do it. For all it should be concerned it’s at that point just a local directory.

Somehow a bunch of source trees are broken.

› nix store verify --all
error: getting status of '/nix/store/0fjj5kb8b89c788lnc48rp3g1kgwm1dq-modules': No such file or directory
error: getting status of '/nix/store/174623zcndh9idvg3qg3am0g920phrc5-source': No such file or directory
error: getting status of '/nix/store/279gp24afj44wq1vxgg8yh8vh3mllpkk-source': No such file or directory
error: getting status of '/nix/store/2qy7pg663y2b3xl90p4z0jhjf79in6af-source': No such file or directory
error: getting status of '/nix/store/3wlmjgxmand5n1cxszbsy7khngdvkz3z-source': No such file or directory
error: getting status of '/nix/store/5009b7fvgw6n97m47qys03nagkyc18ah-source': No such file or directory
error: getting status of '/nix/store/56zz655bnnaz8ybs6w8xycyz16wvllj3-source': No such file or directory
error: getting status of '/nix/store/5cfskd0gnkhg0sxg5d89bwa67sbjpwls-source': No such file or directory
error: getting status of '/nix/store/6n86v7gp9na15rfj5b6s7zv51qcjl58y-source': No such file or directory
error: getting status of '/nix/store/72fkns61g8f7423m1hnfl80fyb2mk9j5-source': No such file or directory
error: getting status of '/nix/store/8rh5xrysjwcjkj4i1pz9sgxc2fn5jr2b-source': No such file or directory
error: getting status of '/nix/store/8rz17fv8rxpzzb7qglhvsk3p034g5hmf-source': No such file or directory
error: getting status of '/nix/store/9j8zwkw13lxw53g0v5029360l0v18gv7-source': No such file or directory
error: getting status of '/nix/store/9rfm0lnhf6hhpdqmpxnvbcnmm2l9znfr-source': No such file or directory
error: getting status of '/nix/store/ac2qiscsqkps9vj2ycr6d5nnr1nvvd0g-source': No such file or directory
error: getting status of '/nix/store/ands56q7g2ryqa05s6c7z6ryxzs18d00-source': No such file or directory
error: getting status of '/nix/store/bs6vn26dcbf17508lyv4n0gizviks0xv-source': No such file or directory
error: getting status of '/nix/store/ccr35si6hrhlzpqr34dd04jvnywhc9vd-source': No such file or directory
error: getting status of '/nix/store/gyp09r440zcz6xsj27w24ampi3274vcl-source': No such file or directory
error: getting status of '/nix/store/gyrh7gs09zms1z1a83ldwghk5cd09vwd-source': No such file or directory
error: getting status of '/nix/store/i7lwa0s4f302r4i6j2r59pa84q7rl2m8-source': No such file or directory
error: getting status of '/nix/store/k18wsx52wvx3pqvzbdhjvlbrk2lx0aac-source': No such file or directory
error: getting status of '/nix/store/l255rlb1i158kmzw7mmrzvybqbpxfynz-source': No such file or directory
error: getting status of '/nix/store/mg787snn75cy2692v2k1yf4ml8qa2bnj-source': No such file or directory
error: getting status of '/nix/store/n65y6h4kkqgiqss3bhqf34vb181js1ib-source': No such file or directory
error: getting status of '/nix/store/n9czz5ak3nnkgjvlywhaccjisjyaxhjy-source': No such file or directory
error: getting status of '/nix/store/nzzc3ws42li3l45kwfg5lzklqklfkfwb-source': No such file or directory
error: getting status of '/nix/store/pgid9c9xfcrbqx2giry0an0bi0df7s5c-source': No such file or directory
error: getting status of '/nix/store/qgmgl27cn60sja2w5a8w7r84yyyi71j2-source': No such file or directory
error: getting status of '/nix/store/qkig73szmrhgp0qhncxy5vb36lw2g3jj-source': No such file or directory
error: getting status of '/nix/store/qxh2chm0qkq9j4mf8bb5an5ff7md42hm-source': No such file or directory
error: getting status of '/nix/store/s5m76d20b0qfazxcr4cl4r330zybxvlf-source': No such file or directory
error: getting status of '/nix/store/sj42qwava614xrmp2wah2j1y4i9pfz4n-source': No such file or directory
error: getting status of '/nix/store/vj5a3pw51nk83v7jfv18qhlq910pvmbx-source': No such file or directory
error: getting status of '/nix/store/vy24l9y3jziwnzcqgrdm6g75hwg0grsw-source': No such file or directory
error: getting status of '/nix/store/xl3gk5nny8kixl0ycc6yhmhby7flj5dv-source': No such file or directory
error: getting status of '/nix/store/xpnpp1sq0gmzf72r0iy2ky6r4h4i6vvb-source': No such file or directory
error: getting status of '/nix/store/yg7sklj8a9lj3gzjygcdigvqvxnasrmw-source': No such file or directory
error: getting status of '/nix/store/yj1wxm9hh8610iyzqnz75kvs6xl8j3my-source': No such file or directory
error: getting status of '/nix/store/zl5lb4v9rh8bcc4mvg2dkbcxl95m2rxh-source': No such file or directory
path '/nix/store/5kdjpww8lhdnzwsphqcnm6x66w126pww-nixos-23.11pre536306.12bdeb01ff9e' is untrusted

Needless to say, one of those is the one that the build is trying to access.

I deleted all those b0rked source paths from nix store and now it works again.

nix store delete /nix/store/174623zcndh9idvg3qg3am0g920phrc5-source

Somehow those paths were in the store but empty.