mirror of
https://codeberg.org/leana8959/.files.git
synced 2026-02-02 06:59:39 +00:00
71 lines
1.3 KiB
Bash
Executable file
71 lines
1.3 KiB
Bash
Executable file
#!/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
|