Si vous tombez dans une situation délicate où un fichier du Nix store est corrompu, vous pouvez le récupérer en utilisant la commande nix-store
. La commande nix-store
a une option --repair
qui peut être utilisée pour récupérer les fichiers corrompus, et une option --check-contents
pour vérifier l’intégrité du Nix store.
Vous pouvez tomber dans une telle situation si vous modifiez manuellement un fichier du nix store (à éviter !), ou si vous avez une défaillance matérielle qui corrompt le fichier.
[root@nixos:~]# nix-store --verify --repair --check-contents
reading the Nix store...
checking path existence...
checking link hashes...
checking store hashes...
path '/nix/store/0db33kxbw5k0lbwrkc037dbqyz3rgzw8-libnftnl-1.2.6' was modified! expected hash 'sha256:0nhmj43w3i1qkq4p87s0w03fl16f0gwq7yi6k22hb3ljdf2r8wcz', got 'sha256:0sjjj9z1dhilhpc8pq4154czrb79z9cm044jvn75kxcjv6v5l2m5'
copying path '/nix/store/0db33kxbw5k0lbwrkc037dbqyz3rgzw8-libnftnl-1.2.6' from 'https://cache.nixos.org'...
path '/nix/store/0iixl4gy02ci4n9d9f7cs6abb1y6nffp-nixos-24.05pre598085.c75037bbf909' was modified! expected hash 'sha256:0c7x36xjl96l0rvqja2rp5v7nfmwm0fcbzgc035443aai4ssbzaj', got 'sha256:07v4kynvhsyi8imahiwf1w4vkpis3sw8zffly5jmn4674f36nizw'
copying path '/nix/store/0iixl4gy02ci4n9d9f7cs6abb1y6nffp-nixos-24.05pre598085.c75037bbf909' from 'https://cache.nixos.org'...
path '/nix/store/46dac1q1v9yp7dfanyyginpk8z7zvnf5-etc-fstab' was modified! expected hash 'sha256:1y4qhsizjlllgzjsnd8sfnj55akp8lq8zbsy2d8vq8z4r54irsm7', got 'sha256:14pw1n0yyzf6jqdql1lcn222g9gv8g0f91gmissb651vblgwdcjc'
checking path '/nix/store/46dac1q1v9yp7dfanyyginpk8z7zvnf5-etc-fstab'...
path '/nix/store/46dac1q1v9yp7dfanyyginpk8z7zvnf5-etc-fstab' is corrupted or missing!
checking path '/nix/store/xz6h70zgmd6wf2931rdg5v4khnsxfg40-bash-5.2p26'...
checking path '/nix/store/z0yj0l3k9bdvvnp5iabmri4cbpkrwdpq-stdenv-linux'...
copying path '/nix/store/xz6h70zgmd6wf2931rdg5v4khnsxfg40-bash-5.2p26' from 'https://cache.nixos.org'...
checking path '/nix/store/5sdcqrw3rjzc8ddndsnbbla0mfp2wygr-libidn2-2.3.7'...
...
checking path '/nix/store/sdrzrynbirmgk47byj2k9280zhh268v6-xgcc-13.2.0-libgcc'...
copying path '/nix/store/z0yj0l3k9bdvvnp5iabmri4cbpkrwdpq-stdenv-linux' from 'https://cache.nixos.org'...
checking path '/nix/store/1639yfqw64vivi4163ljawq8w8raypvj-file-5.45'...
checking path '/nix/store/18qib5wgasqrrp49lyjj0majydlnmpzh-gnu-config-2023-09-19'...
checking path '/nix/store/2shf6zxxx9a5mjskhhc2g55adxrxblhr-ed-1.20.1'...
...
checking path '/nix/store/y650rhxwi5ry2v33ns8wcc1c722v1h0w-gmp-with-cxx-6.3.0'...
checking path '/nix/store/z7abiwmqsg4m7d877sq1dinbxxsgg5jr-patchelf-0.15.0'...
repairing outputs of '/nix/store/x4hbrz2649pi0bj8vy5ym13fyg84n7m1-etc-fstab.drv'...
path '/nix/store/m2ffzbr042hj16fbbb2ngbgzw06bkgx4-libnetfilter_conntrack-1.0.9' was modified! expected hash 'sha256:1qrcrjdd7qzdv8bwcig38bg4nzsbnw61ns0gy7azrkighiydxax0', got 'sha256:0vaig2vwqgl9mx9kkv6awbzcmi46gcbxid7pgz31bjqckm1i3553'
copying path '/nix/store/m2ffzbr042hj16fbbb2ngbgzw06bkgx4-libnetfilter_conntrack-1.0.9' from 'https://cache.nixos.org'...
path '/nix/store/wiyax30lh6wj0n04i2agpk1k8hmjg3zw-libnl-3.8.0' was modified! expected hash 'sha256:0chmfxb3rx5nmrskiwmp839hfq9g1qpy9jhhnnpv42l60bx9dkwz', got 'sha256:0sjjj9z1dhilhpc8pq4154czrb79z9cm044jvn75kxcjv6v5l2m5'
copying path '/nix/store/wiyax30lh6wj0n04i2agpk1k8hmjg3zw-libnl-3.8.0' from 'https://cache.nixos.org'...
Si la commande s’est exécutée correctement, vous avez récupéré les fichiers corrompus.