chore: rewrite manage in bash

This commit is contained in:
Primrose 2026-02-01 23:05:34 +01:00
parent e701910524
commit f90dd5bde6
Signed by: primrose
GPG key ID: 4E887A4CA9714ADA

71
manage.sh Executable file
View file

@ -0,0 +1,71 @@
#!/usr/bin/env bash
set -euo pipefail
function mk-nixos-cmd-args() {
hostname="$1"
pkgs=$(nix-instantiate --eval -E "let sources = import ./npins; in sources.nixpkgs.outPath" | tr -d '"')
args=(
"-I" "nixpkgs=$pkgs"
"-I" "nixos-config=./nix/configurations/$hostname.nix"
"--file" "./default.nix"
"--attr" "nixosConfigurations.$hostname"
)
echo "${args[@]}"
}
function wrapped-nixos-rebuild() {
hostname="$1"
action="$2"
# shellcheck disable=SC2046
nixos-rebuild "$action" $(mk-nixos-cmd-args "$hostname") --no-reexec
}
function wrapped-nixos-install() {
hostname="$1"
# shellcheck disable=SC2046
nixos-install $(mk-nixos-cmd-args "$hostname")
}
function help() {
cat <<EOF
manage.sh
manage.sh is a thin wrapper to make nixos-{install,rebuild} easier to use.
Black lives matter. Trans rights are human rights. No nazi bullsh*t.
Available commands:
os <hostname> <action>: run perhost action with nixos-rebuild
install <hostname>: run perhost action with nixos-install
--help: show this help menu
EOF
}
if [ $# -lt 1 ]; then
help
exit 1
fi
mode="$1"
shift
case $mode in
os)
if [ $# -lt 2 ]; then
help
exit 1
fi
wrapped-nixos-rebuild "$1" "$2"
;;
install)
if [ $# -lt 1 ]; then
help
exit 1
fi
wrapped-nixos-install "$1"
;;
help | *)
help
;;
esac