feat(scripts): Unify behaviour and improve generation
All checks were successful
Build all the nodes / bridge01 (push) Successful in 1m17s
Build all the nodes / geo01 (push) Successful in 1m16s
Build all the nodes / geo02 (push) Successful in 1m22s
Build all the nodes / compute01 (push) Successful in 1m38s
Build all the nodes / storage01 (push) Successful in 1m13s
Build all the nodes / rescue01 (push) Successful in 1m22s
Build all the nodes / vault01 (push) Successful in 1m20s
Run pre-commit on all files / check (push) Successful in 24s
Build all the nodes / web01 (push) Successful in 1m46s
Build all the nodes / web02 (push) Successful in 1m6s
Build all the nodes / web03 (push) Successful in 1m9s

This commit is contained in:
Tom Hubrecht 2024-11-14 22:01:58 +01:00
parent 2ffd7732ba
commit 6fbda40e5e
Signed by: thubrecht
SSH key fingerprint: SHA256:r+nK/SIcWlJ0zFZJGHtlAoRwq1Rm+WcKAm5ADYMoQPc
6 changed files with 93 additions and 96 deletions

View file

@ -114,7 +114,7 @@ in
(pkgs.callPackage "${sources.agenix}/pkgs/agenix.nix" { }) (pkgs.callPackage "${sources.agenix}/pkgs/agenix.nix" { })
(pkgs.callPackage "${sources.lon}/nix/packages/lon.nix" { }) (pkgs.callPackage "${sources.lon}/nix/packages/lon.nix" { })
] ++ (import ./scripts { inherit pkgs; }); ] ++ (pkgs.callPackage ./scripts { });
shellHook = '' shellHook = ''
${git-checks.shellHook} ${git-checks.shellHook}

View file

@ -1,6 +1,9 @@
set -eu -o pipefail set -o errexit
set -o nounset
set -o pipefail
shopt -s lastpipe
drv=$("@colmena@/bin/colmena" eval --instantiate -E "{ nodes, ... }: nodes.${BUILD_NODE}.config.system.build.toplevel") drv=$(colmena eval --instantiate -E "{ nodes, ... }: nodes.${BUILD_NODE}.config.system.build.toplevel")
# Build the derivation and send it to the great beyond # Build the derivation and send it to the great beyond
nix-store --query --requisites --force-realise --include-outputs "$drv" | grep -v '.*\.drv' >paths.txt nix-store --query --requisites --force-realise --include-outputs "$drv" | grep -v '.*\.drv' >paths.txt

View file

@ -1,7 +1,3 @@
#!/usr/bin/env bash
#!@bash@/bin/bash
# shellcheck shell=bash
set -o errexit set -o errexit
set -o nounset set -o nounset
set -o pipefail set -o pipefail
@ -82,19 +78,18 @@ retrieve_current_system () {
ssh -n "root@$1" "readlink -f /run/current-system" ssh -n "root@$1" "readlink -f /run/current-system"
} }
return_status=0 return_status=0
echo "$RESULTS" | @jq@/bin/jq -c '.[]' | echo "$RESULTS" | jq -c '.[]' |
while IFS=$'\n' read -r c; do while IFS=$'\n' read -r c; do
machine=$(echo "$c" | @jq@/bin/jq -r '.machine') machine=$(echo "$c" | jq -r '.machine')
if [[ -n ${node-} ]] && [[ "$machine" != "$node" ]]; then if [[ -n ${node-} ]] && [[ "$machine" != "$node" ]]; then
echo "Skipping ${machine}" echo "Skipping ${machine}"
continue continue
fi fi
expected_path=$(echo "$c" | @jq@/bin/jq -r '.path') expected_path=$(echo "$c" | jq -r '.path')
domain=$(echo "$c" | @jq@/bin/jq -r '.domain') domain=$(echo "$c" | jq -r '.domain')
drv_path=$(echo "$c" | @jq@/bin/jq -r '.drv') drv_path=$(echo "$c" | jq -r '.drv')
err=0 err=0
current_path=$(retrieve_current_system "$domain") || err=1 current_path=$(retrieve_current_system "$domain") || err=1
@ -109,7 +104,7 @@ while IFS=$'\n' read -r c; do
nix-copy-closure --from "root@$domain" "$current_path" nix-copy-closure --from "root@$domain" "$current_path"
nix-store -r "$drv_path" nix-store -r "$drv_path"
echo "$machine -> error. nvd output:" echo "$machine -> error. nvd output:"
@nvd@/bin/nvd diff "$expected_path" "$current_path" nvd diff "$expected_path" "$current_path"
return_status=1 return_status=1
else else
echo "☠️ $machine -> error:" echo "☠️ $machine -> error:"

View file

@ -1,39 +1,34 @@
{ pkgs, ... }: {
lib,
writeShellApplication,
# Dependencies
colmena,
jq,
nvd,
...
}:
let let
substitutions = { inherit (lib) mapAttrsToList;
inherit (pkgs)
bash scripts = {
cache-node = [ colmena ];
check-deployment = [
colmena colmena
coreutils
nvd
git
jq jq
; nvd
};
mkShellScript =
name:
(pkgs.substituteAll (
{
inherit name;
src = ./. + "/${name}.sh";
dir = "/bin/";
isExecutable = true;
checkPhase = ''
${pkgs.stdenv.shellDryRun} "$target"
'';
}
// substitutions
));
scripts = [
"cache-node"
"check-deployment"
"launch-vm"
"list-nodes"
]; ];
launch-vm = [ colmena ];
list-nodes = [ jq ];
};
in in
builtins.map mkShellScript scripts mapAttrsToList (
name: runtimeInputs:
writeShellApplication {
inherit name runtimeInputs;
text = builtins.readFile ./${name}.sh;
}
) scripts

View file

@ -1,8 +1,7 @@
#!@bash@/bin/bash
# shellcheck shell=bash
set -o errexit set -o errexit
set -o nounset set -o nounset
set -o pipefail set -o pipefail
shopt -s lastpipe
MACHINE="" MACHINE=""
HOSTFWD="" HOSTFWD=""
@ -25,9 +24,12 @@ while getopts 'p:o:h' opt; do
done done
shift "$((OPTIND - 1))" shift "$((OPTIND - 1))"
if [ -z "$MACHINE" ]; then echo "-o option needed"; exit 1; fi if [ -z "$MACHINE" ]; then
echo "-o option needed"
exit 1
fi
DRV_PATH=$(@colmena@/bin/colmena eval --instantiate -E "{nodes, ...}: nodes.$MACHINE.config.system.build.vm") DRV_PATH=$(colmena eval --instantiate -E "{nodes, ...}: nodes.$MACHINE.config.system.build.vm")
echo "Realising $DRV_PATH" echo "Realising $DRV_PATH"
RESULT=$(nix-store -r "$DRV_PATH") RESULT=$(nix-store -r "$DRV_PATH")

View file

@ -1,6 +1,8 @@
#!@bash@/bin/bash set -o errexit
# shellcheck shell=bash set -o nounset
set -o pipefail
shopt -s lastpipe
cd $(@git@/bin/git rev-parse --show-toplevel) cd "$(git rev-parse --show-toplevel)"
nix-instantiate --strict --eval --json -A nodes | @jq@/bin/jq . nix-instantiate --strict --eval --json -A nodes | jq .