puter
This commit is contained in:
parent
5f017e6a4e
commit
5d0c0b9757
3 changed files with 97 additions and 12 deletions
72
common/puter/puter.bash
Normal file
72
common/puter/puter.bash
Normal 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
13
common/puter/puter.nix
Normal 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
|
||||
];
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue