mirror of
https://codeberg.org/leana8959/.files.git
synced 2026-02-03 15:39:41 +00:00
chore: rewrite manage in bash
This commit is contained in:
parent
e701910524
commit
f90dd5bde6
1 changed files with 71 additions and 0 deletions
71
manage.sh
Executable file
71
manage.sh
Executable 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
|
||||||
Loading…
Add table
Add a link
Reference in a new issue