45 lines
1.1 KiB
Bash
Executable File
45 lines
1.1 KiB
Bash
Executable File
SACRED_SPACE="$1"
|
|
BLOCKERS="$2"
|
|
PERIOD="$3"
|
|
|
|
scrapePids() {
|
|
for pid in /proc/*; do
|
|
if [[ "$pid" =~ ^[0-9]*$ ]]; then
|
|
if grep -E "$BLOCKERS" -q /proc/"$pid"/comm; then
|
|
if [[ "$(readlink /proc/"$pid"/cwd)" == "$SACRED_SPACE"* ]]; then
|
|
echo "$pid with name $(cat /proc/"$pid"/comm) is blocking"
|
|
return 0
|
|
fi
|
|
fi
|
|
fi
|
|
done
|
|
return 1
|
|
}
|
|
|
|
while true; do
|
|
|
|
inotifywait -r "$SACRED_SPACE"
|
|
|
|
|
|
notify-send "smooooth" "config change detected. waiting for blockers to resolve.."
|
|
while scrapePids; do
|
|
echo "found blocker in $SACRED_SPACE, waiting.."
|
|
sleep "$PERIOD"
|
|
done
|
|
|
|
echo "building system"
|
|
notify-send "smooooth" "rebuilding your nixos config - please stand by"
|
|
temp="$(mktemp -d)"
|
|
build="$temp/system"
|
|
nix build --out-link "$build" "$SACRED_SPACE"#nixosConfigurations."$HOSTNAME".config.system.build.toplevel
|
|
|
|
echo "built - attempting to activate system"
|
|
notify-send "smooooth" "activating your new config"
|
|
switch="$(readlink "$build")/bin/switch-to-configuration"
|
|
pkexec "$switch" switch
|
|
|
|
echo "cleaning up"
|
|
rm -r "$temp"
|
|
|
|
done
|