nixfiles/switch
teidesu 5ba68e987d
chore: better unsafe secret handling
turned out my previous scheme didn't work properly under linux xd
2024-05-12 12:43:51 +03:00

52 lines
No EOL
1 KiB
Bash
Executable file

#!/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
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
if [ "$(uname)" == "Darwin" ]; then
if [ $(hostname) == "teidesu-osx" ]; then
git add -f hosts/teidesu-osx/arc-setup.nix
fi
if command -v darwin-rebuild &> /dev/null; then
darwin-rebuild switch --flake $flake $args $@
else
nix --extra-experimental-features nix-command --extra-experimental-features flakes run nix-darwin -- switch --flake $flake $args $@
fi
else
sudo nixos-rebuild $cmd --flake $flake $args $@
fi