#!/bin/sh CONFIG_PATH=$HOME/global/system/config/ NID=$RANDOM cmd=$(printf "Test\nSwitch\nCommit\nUpdate" | wofi -d -p 'Select') kind=test desc=Temporarily case "$cmd" in Update) nix flake update --flake "$CONFIG_PATH" dunstify " NixOS - Config" "Updated Flake" ;;& Switch | Commit | Update) git -C "$CONFIG_PATH" add . git -C "$CONFIG_PATH" commit -m "$(date '+%Y-%m-%d updates by auto-switch')" dunstify " NixOS - Config" "Created New Commit" case "$cmd" in Commit | Update) exit; esac kind=switch desc=Permanently ;;& Test | Switch) dunstify -r "$NID" " NixOS - Config" "Switching Config $desc." --hints=int:value:0 -t 0 declare -i i=0 sudo nixos-rebuild "$kind" --flake "$CONFIG_PATH" 2>&1 | while IFS="" read -r line || [ -n "$line" ]; do case "$line" in these*)n=$(echo "$line" | grep -Eo '[0-9]*');; "building '"*) i+=1 progress=$(($i * 100 / $n)) dunstify -r "$NID" " NixOS - Config" "Switching Config $desc." --hints=int:value:"$progress" -t 0 ;; *error*) dunstify -r "$NID" -u 2 " NixOS - Config" "Error Loading Config" ;; *Done.*) dunstify -r "$NID" " NixOS - Config" "Switching Config $desc.\nDone." ;; esac done ;; esac