| 1 | #!/bin/sh |
| 2 | set -e |
| 3 | cd "$(dirname "$0")" |
| 4 | nh_subcommand="os" |
| 5 | fallback_command="nixos-rebuild" |
| 6 | if [ -n "$1" ]; then |
| 7 | hostname="$1" |
| 8 | elif [ -f ".hostname" ]; then |
| 9 | hostname=$(cat .hostname) |
| 10 | fi |
| 11 | if [ -z "$hostname" ]; then |
| 12 | hostname="$(hostname)" |
| 13 | fi |
| 14 | printf "%s" "$hostname" >.hostname |
| 15 | if [ "$(uname -s)" = "Darwin" ]; then |
| 16 | nh_subcommand="darwin" |
| 17 | fallback_command="nix run .#darwin-rebuild" |
| 18 | fi |
| 19 | if command -v nh >/dev/null; then |
| 20 | if [ "$nh_subcommand" = "darwin" ]; then |
| 21 | nh darwin switch . --hostname "$hostname" |
| 22 | else |
| 23 | nh os switch '.#'"$hostname" |
| 24 | fi |
| 25 | else |
| 26 | $fallback_command -- switch --flake '.#'"$hostname" |
| 27 | fi |