oizys/styx

124 lines
2.1 KiB
Text
Raw Normal View History

2024-01-23 11:51:13 -06:00
#!/usr/bin/env bash
set -e
# rewrite as python script?
2024-01-24 13:33:48 -06:00
HOSTNAME=${HOSTNAME:-$(hostname)}
2024-01-24 14:12:52 -06:00
FLAKE_PATH=${FLAKE_PATH:-$HOME/nixcfg}
2024-01-23 11:51:13 -06:00
DIM="$(tput dim)"
BOLD="$(tput bold)"
RED="$(tput setaf 1)"
GREEN="$(tput setaf 2)"
YELLOW="$(tput setaf 3)"
CYAN="$(tput setaf 4)"
RESET="$(tput sgr0)"
PREFIX="${CYAN}styx${RESET}"
log() {
printf "%s | %s\n" "$PREFIX" "$*"
}
error() {
printf "%s | %s | %s\n" "$PREFIX" "${RED}error${RESET}" "$*"
}
help() {
cat <<EOF
styx <cmd> [-h]
${DIM}sister moon to nix on pluto
sister software to nix in this repo${RESET}
${BOLD}commands${RESET}:
EOF
printf "${GREEN}%8s${RESET} | ${YELLOW}%s${RESET}\n" \
fmt "format *.nix" \
build "build and monitor with nom" \
boot "evaluate flake for next boot" \
switch "perform nixos rebuild" \
2024-01-24 14:12:52 -06:00
store "run some store cleanup" \
cache "nix build and push to daylin.cachix.org"
2024-01-23 11:51:13 -06:00
exit
}
fmt() {
alejandra . "$@"
}
boot() {
sudo nixos-rebuild boot --flake "$FLAKE_PATH" "$@"
}
switch() {
sudo nixos-rebuild switch --flake "$FLAKE_PATH" "$@"
}
store() {
nix store optimise "$@"
}
build() {
nom build "$FLAKE_PATH#nixosConfigurations.$(hostname).config.system.build.toplevel"
case "$1" in
switch | boot | test ) sudo ./result/bin/switch-to-configuration "$1";;
esac
}
2024-01-23 15:36:31 -06:00
dry() {
# poor mans nix flake check
nix build "$FLAKE_PATH#nixosConfigurations.$(hostname).config.system.build.toplevel" --dry-run
}
2024-01-24 13:33:48 -06:00
cache() {
cachix watch-exec daylin \
-- \
nix build "$FLAKE_PATH#nixosConfigurations.${HOSTNAME}.config.system.build.toplevel" \
--print-build-logs
}
2024-01-23 11:51:13 -06:00
if [[ $# -eq 0 ]]; then
log no command specified see below for help
help
fi
while [[ $# -gt 0 ]]; do
case $1 in
2024-01-24 13:33:48 -06:00
fmt | boot | switch | store | build | dry | cache)
2024-01-23 11:51:13 -06:00
cmd=$1
shift
;;
2024-01-24 13:33:48 -06:00
-f | --flake)
FLAKE_PATH="$2"
shift; shift;
2024-01-23 11:51:13 -06:00
;;
2024-01-24 13:33:48 -06:00
-h | --host)
HOSTNAME="$2"
shift; shift;
;;
--help)
help
2024-01-24 14:12:52 -06:00
;;
--)
shift
break
2024-01-23 11:51:13 -06:00
;;
-*,--*)
error "unknown flag: ${BOLD}$1${RESET}"
exit 1
;;
*)
error "unknown command: ${BOLD}$1${RESET}"
exit 1
;;
esac
done
if [[ $# -gt 0 ]]; then
echo "forwarding args: ${BOLD}$*${RESET}"
fi
2024-01-24 13:33:48 -06:00
2024-01-23 11:51:13 -06:00
$cmd "$@"