2021-02-19 23:25:28 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2021-02-14 09:29:17 +00:00
|
|
|
[[ -d "$DEVSHELL_ROOT" ]] ||
|
|
|
|
{
|
2021-02-18 01:31:33 +00:00
|
|
|
echo "This script must be run from devos's devshell" >&2
|
2021-02-14 09:29:17 +00:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
shopt -s extglob
|
|
|
|
|
|
|
|
HOSTNAME="$(hostname)"
|
|
|
|
|
|
|
|
usage () {
|
|
|
|
printf "%b\n" \
|
|
|
|
"\e[4mUsage\e[0m: $(basename $0) COMMAND [ARGS]\n" \
|
|
|
|
"\e[4mCommands\e[0m:"
|
|
|
|
|
|
|
|
printf " %-30s %s\n\n" \
|
|
|
|
"up" "Generate $DEVSHELL_ROOT/hosts/up-$HOSTNAME.nix" \
|
2021-03-16 21:43:55 +00:00
|
|
|
"update [INPUT]" "Update and commit the lock file, or specific input" \
|
2021-02-23 02:49:31 +00:00
|
|
|
"get (core|community) [DEST]" "Copy the desired template to DEST" \
|
2021-02-14 09:29:17 +00:00
|
|
|
"iso HOST" "Generate an ISO image of HOST" \
|
|
|
|
"install HOST [ARGS]" "Shortcut for nixos-install" \
|
|
|
|
"home HOST USER [switch]" "Home-manager config of USER from HOST" \
|
2021-02-23 02:49:31 +00:00
|
|
|
"HOST (switch|boot|test)" "Shortcut for nixos-rebuild"
|
2021-02-14 09:29:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
""|"-h"|"help"|*(-)"help")
|
|
|
|
usage
|
|
|
|
;;
|
|
|
|
|
|
|
|
"up")
|
|
|
|
mkdir -p "$DEVSHELL_ROOT/up"
|
|
|
|
|
|
|
|
nixos-generate-config --dir "$DEVSHELL_ROOT/up/$HOSTNAME"
|
|
|
|
|
2021-02-16 06:30:18 +00:00
|
|
|
printf "%s\n" \
|
|
|
|
"{ suites, ... }:" \
|
|
|
|
"{" \
|
|
|
|
" imports = [" \
|
|
|
|
" ../up/$HOSTNAME/configuration.nix" \
|
|
|
|
" ] ++ suites.core;" \
|
|
|
|
"}" > "$DEVSHELL_ROOT/hosts/up-$HOSTNAME.nix"
|
2021-02-14 09:29:17 +00:00
|
|
|
|
|
|
|
git add -f \
|
|
|
|
"$DEVSHELL_ROOT/up/$HOSTNAME" \
|
|
|
|
"$DEVSHELL_ROOT/hosts/up-$HOSTNAME.nix"
|
|
|
|
;;
|
|
|
|
|
|
|
|
"update")
|
2021-02-23 02:49:31 +00:00
|
|
|
if [[ -n "$2" ]]; then
|
2021-03-15 03:27:58 +00:00
|
|
|
if [[ -n "$3" ]]; then
|
|
|
|
(cd $2; nix flake list-inputs --update-input "$3")
|
|
|
|
else
|
|
|
|
(cd $2; nix flake update)
|
|
|
|
fi
|
|
|
|
nix flake list-inputs --update-input "$2" "$DEVSHELL_ROOT"
|
2021-02-23 02:49:31 +00:00
|
|
|
else
|
2021-03-15 03:27:58 +00:00
|
|
|
nix flake update "$DEVSHELL_ROOT"
|
2021-02-23 02:49:31 +00:00
|
|
|
fi
|
2021-02-14 09:29:17 +00:00
|
|
|
;;
|
|
|
|
|
|
|
|
"get")
|
|
|
|
if [[ "$2" == "core" || "$2" == "community" ]]; then
|
2021-02-18 01:31:33 +00:00
|
|
|
nix flake new -t "github:divnix/devos/$2" "${3:-flk}"
|
2021-02-14 09:29:17 +00:00
|
|
|
else
|
2021-02-23 02:49:31 +00:00
|
|
|
echo "flk get (core|community) [DEST]"
|
2021-02-14 09:29:17 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
|
|
|
|
"iso")
|
|
|
|
nix build \
|
|
|
|
"$DEVSHELL_ROOT#nixosConfigurations.$2.config.system.build.iso" \
|
|
|
|
"${@:3}"
|
|
|
|
;;
|
|
|
|
|
|
|
|
"install")
|
|
|
|
sudo nixos-install --flake "$DEVSHELL_ROOT#$2" "${@:3}"
|
|
|
|
;;
|
|
|
|
|
|
|
|
"home")
|
2021-04-11 17:24:00 +00:00
|
|
|
ref="$DEVSHELL_ROOT/#homeConfigurations.$3@$2.activationPackage"
|
2021-02-14 09:29:17 +00:00
|
|
|
|
|
|
|
if [[ "$4" == "switch" ]]; then
|
|
|
|
nix build "$ref" && result/activate &&
|
|
|
|
unlink result
|
|
|
|
|
|
|
|
else
|
|
|
|
nix build "$ref" "${@:4}"
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
|
|
|
|
*)
|
|
|
|
sudo nixos-rebuild --flake "$DEVSHELL_ROOT#$1" "${@:2}"
|
|
|
|
;;
|
|
|
|
esac
|