Last active
November 14, 2018 10:25
-
-
Save LisannaAtHome/b06f767f9aa30f5d68861799fa169ce9 to your computer and use it in GitHub Desktop.
nix-surgeon: tool for repairing corrupted nix store paths
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env bash | |
NIX_STORE=${NIX_STORE:-"/nix/store"}; | |
store_path=$1; | |
# check if path is actually broken | |
if nix-store --verify-path $store_path; then exit 0; fi; | |
# abuse --check flag to get a fresh, non-substituted rebuild of the path | |
# TODO: GC? | |
echo "building a new copy of $store_path"; | |
nix-store --realise --check -K $(nix-store -q --deriver $store_path); | |
echo "repairing $store_path"; | |
unshare -m sh -c " \ | |
mount -o remount,rw $NIX_STORE; \ | |
rm -rf $store_path; \ | |
nix-store --dump $store_path.check | nix-store --restore $store_path; \ | |
" | |
nix-store --verify-path $store_path; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment