2022-05-28 21:24:15 +02:00
|
|
|
{ self, pkgs, lib, boxes }:
|
2022-05-14 20:47:17 +02:00
|
|
|
let
|
2022-05-28 21:24:15 +02:00
|
|
|
# command which generates the update script for that specific machine
|
|
|
|
installScript = (target: (pkgs.writeScript "deploy" ''
|
|
|
|
#!${pkgs.runtimeShell}
|
|
|
|
ssh root@10.13.37.${toString (target + 100)} "ps cax | grep \"nixos-rebuild\" > /dev/null"
|
|
|
|
if [ $? -eq 0 ]
|
|
|
|
then
|
|
|
|
echo "Process is running."
|
|
|
|
exit
|
|
|
|
else
|
|
|
|
echo "Process is not running."
|
|
|
|
nix copy --to ssh://root@10.13.37.${toString (target + 100)} ${self}
|
|
|
|
ssh root@10.13.37.${toString (target + 100)} -- nixos-rebuild switch --flake ${self}#traffic-stop-box-${toString target}
|
|
|
|
fi
|
|
|
|
''));
|
2022-05-14 20:47:17 +02:00
|
|
|
|
2022-05-28 21:24:15 +02:00
|
|
|
# concatanes commands together
|
|
|
|
deployBoxes = (systems: lib.strings.concatStringsSep " "
|
|
|
|
(builtins.map (system: "${(installScript system)}") systems));
|
2022-05-14 20:47:17 +02:00
|
|
|
|
2022-05-28 21:24:15 +02:00
|
|
|
deployAllScript = (pkgs.writeScript "deploy-all" (
|
|
|
|
''
|
2022-05-14 20:47:17 +02:00
|
|
|
#!${pkgs.runtimeShell} -ex
|
|
|
|
${pkgs.parallel}/bin/parallel --citation
|
|
|
|
${pkgs.parallel}/bin/parallel -j10 ::: ${deployBoxes boxes} || echo "Some deployment failed"
|
|
|
|
''
|
2022-05-28 21:24:15 +02:00
|
|
|
));
|
2022-05-14 20:47:17 +02:00
|
|
|
|
2022-05-28 21:24:15 +02:00
|
|
|
individualScripts = lib.foldl (x: y: lib.mergeAttrs x y) { } (builtins.map (number: { "deploy-box-${toString number}" = (installScript number); }) boxes);
|
2022-05-14 20:47:17 +02:00
|
|
|
|
2022-05-28 21:24:15 +02:00
|
|
|
in
|
|
|
|
({
|
2022-05-14 20:47:17 +02:00
|
|
|
deploy-all = deployAllScript;
|
|
|
|
}) #individualScripts
|
|
|
|
|
|
|
|
#in (individualScripts // {
|
|
|
|
# deploy-all = deployAllScript;
|
|
|
|
#})
|