devos/shell/flk.sh
Timothy DeHerrera d51cd34fb7
subflakes: make first class citizens
Subflakes should provide their wares as outputs, so wire up the pkgs
flake to reflect that.

Due to the unstable nature of flakes, updating the root flake doesn't
currently update the subflake lock file. Therefore, add additional
logic to flk update script in order to do this behind the scenes.

Nix is now pulled in from the "nix" registry flake in order for users
to take advantage of improvements to the UI since its last update in
nixpkgs.
2021-03-14 21:27:58 -06:00

98 lines
2.2 KiB
Bash
Executable file

#!/usr/bin/env bash
[[ -d "$DEVSHELL_ROOT" ]] ||
{
echo "This script must be run from devos's devshell" >&2
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" \
"update [INPUT]" "Update and commit the lock file" \
"get (core|community) [DEST]" "Copy the desired template to DEST" \
"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" \
"HOST (switch|boot|test)" "Shortcut for nixos-rebuild"
}
case "$1" in
""|"-h"|"help"|*(-)"help")
usage
;;
"up")
mkdir -p "$DEVSHELL_ROOT/up"
nixos-generate-config --dir "$DEVSHELL_ROOT/up/$HOSTNAME"
printf "%s\n" \
"{ suites, ... }:" \
"{" \
" imports = [" \
" ../up/$HOSTNAME/configuration.nix" \
" ] ++ suites.core;" \
"}" > "$DEVSHELL_ROOT/hosts/up-$HOSTNAME.nix"
git add -f \
"$DEVSHELL_ROOT/up/$HOSTNAME" \
"$DEVSHELL_ROOT/hosts/up-$HOSTNAME.nix"
;;
"update")
if [[ -n "$2" ]]; then
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"
else
nix flake update "$DEVSHELL_ROOT"
fi
;;
"get")
if [[ "$2" == "core" || "$2" == "community" ]]; then
nix flake new -t "github:divnix/devos/$2" "${3:-flk}"
else
echo "flk get (core|community) [DEST]"
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")
ref="$DEVSHELL_ROOT/#hmActivationPackages.$2.$3"
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