smooooth/smooooth.sh
2025-05-21 17:14:26 +10:00

40 lines
990 B
Bash
Executable File

SACRED_SPACE="$1"
BLOCKERS="$2"
PERIOD="$3"
scrapePids() {
for pid in $(ls /proc); do
if [[ "$pid" =~ ^[0-9]*$ ]]; then
if egrep -q $BLOCKERS /proc/$pid/comm; then
cat /proc/$pid/comm
readlink /proc/$pid/cwd
if [[ "$(readlink /proc/$pid/cwd)" == "$SACRED_SPACE"* ]]; then
return 0
fi
fi
fi
done
return 1
}
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