2024-04-06 16:15:47 +02:00
|
|
|
{
|
|
|
|
tflib,
|
|
|
|
pkgs,
|
|
|
|
}: {
|
|
|
|
name,
|
|
|
|
flake ? "$FLAKE_ROOT",
|
2024-04-06 16:40:33 +02:00
|
|
|
hosts ? [],
|
2024-04-06 16:15:47 +02:00
|
|
|
}: {
|
|
|
|
lib,
|
|
|
|
config,
|
|
|
|
...
|
|
|
|
}: let
|
|
|
|
inherit
|
|
|
|
(tflib)
|
|
|
|
tf
|
|
|
|
;
|
|
|
|
inherit
|
|
|
|
(lib)
|
|
|
|
singleton
|
2024-04-06 16:40:33 +02:00
|
|
|
concatMapStringsSep
|
2024-04-06 16:15:47 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
flakePath = "${flake}#nixngConfigurations.${name}.config.system.build.toplevel.outPath";
|
|
|
|
in {
|
|
|
|
data."external"."nixng-system-${name}" = {
|
|
|
|
program = singleton (pkgs.writeShellScript "build_nixng_system_${name}.sh" ''
|
|
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
_system_path="$(nix eval --raw "${flakePath}")"
|
|
|
|
|
|
|
|
jq -n --arg _system_path "$_system_path" '{"out":$_system_path}'
|
|
|
|
'');
|
|
|
|
};
|
|
|
|
|
|
|
|
resource."terraform_data"."nixng-system-${name}-copy" = {
|
2024-04-23 13:03:11 +02:00
|
|
|
triggers_replace = [
|
|
|
|
(tf "data.external.nixng-system-${name}.result.out")
|
|
|
|
];
|
2024-04-06 16:15:47 +02:00
|
|
|
provisioner."local-exec" = {
|
|
|
|
interpreter = [
|
|
|
|
(pkgs.writeShellScript "copy_nixng_system_${name}.sh" ''
|
|
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
_system_path="$1"
|
|
|
|
|
|
|
|
cd $FLAKE_ROOT
|
|
|
|
nix build "${flakePath}"
|
2024-04-06 16:40:33 +02:00
|
|
|
${concatMapStringsSep "\n" (host: ''
|
2024-04-27 19:07:26 +02:00
|
|
|
flock /tmp/terranix/${host} -x nix copy "$_system_path" --to ssh-ng://${host} -s --no-check-sigs
|
2024-04-06 16:40:33 +02:00
|
|
|
'')
|
|
|
|
hosts}
|
|
|
|
|
2024-04-06 16:15:47 +02:00
|
|
|
'')
|
|
|
|
(tf "data.external.nixng-system-${name}.result.out")
|
|
|
|
];
|
|
|
|
command = "ignoreme";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|