nixfiles/switch

52 lines
1 KiB
Text
Raw Normal View History

2024-01-08 07:49:51 +03:00
#!/usr/bin/env bash
args=""
cmd="switch"
if [ "$1" == "debug" ]; then
args="--show-trace -v -L"
shift
fi
if [ "$1" == "build" ]; then
cmd="build"
shift
fi
if [ "$1" == "dry-activate" ]; then
cmd="dry-activate"
shift
fi
if [ "$1" == "boot" ]; then
cmd="boot"
shift
fi
2024-05-01 04:53:38 +03:00
flake="."
if [ ! -z ${NIX_HOSTNAME+x} ]; then
flake=".#$NIX_HOSTNAME"
fi
function on_exit {
git restore --staged secrets/unsafe.key
if [ $(hostname) == "teidesu-osx" ]; then
git restore --staged hosts/teidesu-osx/arc-setup.nix
fi
}
trap on_exit EXIT
git add -f secrets/unsafe.key
2024-03-03 06:32:03 +03:00
if [ "$(uname)" == "Darwin" ]; then
2024-05-01 04:53:38 +03:00
if [ $(hostname) == "teidesu-osx" ]; then
git add -f hosts/teidesu-osx/arc-setup.nix
fi
2024-03-03 06:32:03 +03:00
if command -v darwin-rebuild &> /dev/null; then
2024-05-01 04:53:38 +03:00
darwin-rebuild switch --flake $flake $args $@
2024-03-03 06:32:03 +03:00
else
2024-05-01 04:53:38 +03:00
nix --extra-experimental-features nix-command --extra-experimental-features flakes run nix-darwin -- switch --flake $flake $args $@
2024-03-03 06:32:03 +03:00
fi
else
2024-05-01 04:53:38 +03:00
sudo nixos-rebuild $cmd --flake $flake $args $@
2024-03-03 06:32:03 +03:00
fi