Files
nixos-config/os.sh
Morten Olsen a4432938df update
2023-09-21 22:49:34 +02:00

39 lines
609 B
Bash
Executable File

ACTION=$1; shift
LOCATION=$PWD
function apply() {
name=$1
if [ -z "$name" ]; then
sudo nixos-rebuild switch --flake $LOCATION
else
sudo nixos-rebuild switch --flake "$LOCATION#$name"
fi
}
function upgrade() {
if git -C "$LOCATION" diff-index --quiet HEAD --; then
nix flake update --commit-lock-file "$LOCATION"
else
echo "Error: git working tree is dirty"
exit 1
fi
}
function cleanup() {
nix-collect-garbage -d
nixos-store --optimise
}
case $ACTION in
apply)
apply $1
;;
upgrade)
upgrade $1
;;
*)
echo "Usage: $0 {apply}"
exit 1
esac