diff --git a/build-all-nixos.sh b/build-all-nixos.sh new file mode 100755 index 0000000..1caca63 --- /dev/null +++ b/build-all-nixos.sh @@ -0,0 +1,22 @@ +#!/bin/sh +mkdir -p results + +nix flake show --json | jq -r -c '.nixosConfigurations | keys[]' | while read i; do + echo "[[SKYG]] Building current $i" + sudo nixos-rebuild build --flake .#$i + rm -f results/$i-result + mv result results/$i-result +done + +nix flake update + +rm -f diffs +mkdir diffs +nix flake show --json | jq -r -c '.nixosConfigurations | keys[]' | while read i; do + echo "[[SKYG]] Building new $i" + sudo nixos-rebuild build --flake .#$i + rm -f results/$i-result-post + mv result results/$i-result-post + nvd diff results/$i-result results/$i-result-post > diffs/$i +done + diff --git a/build-nixos.sh b/build-nixos.sh new file mode 100755 index 0000000..886bec9 --- /dev/null +++ b/build-nixos.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +rm -f .built_via_skg +sudo nixos-rebuild build --flake . +touch .built_via_skg +nvd diff /run/current-system result \ No newline at end of file diff --git a/build-remote-nixos.sh b/build-remote-nixos.sh new file mode 100755 index 0000000..a397b87 --- /dev/null +++ b/build-remote-nixos.sh @@ -0,0 +1,58 @@ +#!/bin/sh +export NIX_SSHOPTS="-o RequestTTY=force" + +target=${1} +target_host=root@$target.lab.internal +profile=hl-$target + +valid_profiles=$(nix flake show --json | jq -r -c '.nixosConfigurations | keys[]' | grep "hl") + +function print_valid_targets { + echo "valid targets:" + while IFS= read -r line; do + echo $line | sed -r 's/.*hl-/ - /g' + done <<< "$valid_profiles" +} + +if [ -z $target ]; then + echo "must specify a target!" + print_valid_targets + exit 1 +fi + +if echo "$valid_profiles" | grep -qFx "$profile"; then + echo "Using [$profile]" +else + echo "Invalid target! '$profile'" + print_valid_targets + exit 1 +fi + +function run { + cmd=${1} + echo "$cmd on $target_host with $profile through $build_host" + nixos-rebuild \ + --target-host $target_host \ + --use-remote-sudo \ + $cmd \ + --flake \ + .#$profile +} + +valid_cmds=( build switch test dry-activate ) + +cmd=${2} +case $cmd in + "test" | "dry-activate" | "run" | "switch") run $cmd;; + "build") + output=$(run $cmd) + echo $output + echo "_" + echo $output | grep "nixos" + echo "_" + ;; + *) + echo "invalid command" + exit 1 + ;; +esac diff --git a/switch-nixos.sh b/switch-nixos.sh new file mode 100755 index 0000000..6e5799e --- /dev/null +++ b/switch-nixos.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +if [ ! -f .built_via_skg ]; then + ./build-nixos.sh + echo "Do you want to continue? (y/N)" + read -r answer + if [[ $answer =~ ^[yY]$ ]]; then + echo "Continuing..." + else + echo "Exiting." + exit 1 + fi +fi + +sudo nixos-rebuild switch --flake . +git cap +rm -f .built_via_skg