SACRED_SPACE="$1" BLOCKERS="$2" PERIOD="$3" scrapePids() { for pid in /proc/*; do if [[ "$pid" =~ .*[0-9]*$ ]]; then if grep -E "$BLOCKERS" -q "$pid"/comm; then if [[ "$(readlink "$pid"/cwd)" == "$SACRED_SPACE"* ]]; then echo "$pid with name $(cat "$pid"/comm) is blocking" return 0 fi fi fi done return 1 } echo "Starting up for $SACRED_SPACE with blockers $BLOCKERS and polling of $PERIOD" while true; do inotifywait -r -e modify -e move -e create -e delete "$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 and linked at $build - attempting to activate system" notify-send "smooooth" "activating your new config" switch="$build/bin/switch-to-configuration" /run/wrappers/bin/pkexec "$switch" switch echo "cleaning up" rm -r "$temp" done