1
0
Fork 0
This commit is contained in:
Lukas Wurzinger 2024-12-29 00:06:13 +01:00
parent 5f017e6a4e
commit 5d0c0b9757
No known key found for this signature in database
3 changed files with 97 additions and 12 deletions

72
common/puter/puter.bash Normal file
View file

@ -0,0 +1,72 @@
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
progname=$0
error() {
for line in "$@"; do
printf '%s\n' "$progname: $line" 1>&2
done
exit 1
}
args=$(getopt --options f --longoptions=flake: --name "$progname" -- "$@")
eval set -- "$args"
flake=git+https://forgejo@tea.wrz.one/lukas/puter.git#$(hostname)
flags=()
while true; do
case $1 in
(-f | --flake)
flake=$2
shift 2
;;
(-v | --verbose)
flags+=(--verbose)
shift
;;
(--)
shift
break
;;
esac
done
if (( $# == 0 )); then
error 'a subcommand is required'
fi
subcommand=$1
nixos-rebuild() {
command nixos-rebuild "${flags[@]}" --flake "$flake" --no-write-lock-file "$@"
}
case $subcommand in
(s | switch)
shift
if (( $# > 0 )); then
error 'too many arguments'
fi
nixos-rebuild switch
;;
(b | boot)
shift
if (( $# > 0 )); then
error 'too many arguments'
fi
nixos-rebuild boot
;;
(*)
error 'invalid subcommand'
;;
esac

13
common/puter/puter.nix Normal file
View file

@ -0,0 +1,13 @@
{pkgs, ...}: let
puter = pkgs.writeShellScriptBin {
name = "puter";
runtimeInputs = [
pkgs.nixos-rebuild
];
text = builtins.readFile ./puter.bash;
};
in {
environment.systemPackages = [
puter
];
}