flake.nix: add support for remote builders

This commit is contained in:
Astro 2021-05-26 18:50:48 +02:00
parent b403a4413c
commit 0aef44118f
1 changed files with 56 additions and 15 deletions

View File

@ -31,8 +31,19 @@
# Generate a small script for copying this flake to the # Generate a small script for copying this flake to the
# remote machine and bulding and switching there. # remote machine and bulding and switching there.
# Can be run with nix run c3d2#deploy-… # Can be run with nix run c3d2#deploy-…
name: host: { name
, host ? "${name}.hq.c3d2.de"
# remote builders to pass
, builders ? null
}:
let target = "root@${host}"; let target = "root@${host}";
rebuildArg =
"--flake ${self}#${name}" +
(if builders != null
then " --builders \"" +
builtins.concatStringsSep " " builders +
"\""
else "");
in pkgs.writeScriptBin "${name}-nixos-rebuild" '' in pkgs.writeScriptBin "${name}-nixos-rebuild" ''
#!${pkgs.runtimeShell} #!${pkgs.runtimeShell}
set -ev set -ev
@ -40,9 +51,9 @@
nix-copy-closure --to ${target} ${self} nix-copy-closure --to ${target} ${self}
if [ "$1" = "--flakify" ]; then if [ "$1" = "--flakify" ]; then
shift shift
exec ssh -t ${target} "nix-shell -p nixFlakes -p git --command \"_NIXOS_REBUILD_REEXEC=1 nixos-rebuild --flake ${self}#${name} \"$@" exec ssh -t ${target} "nix-shell -p nixFlakes -p git --command '_NIXOS_REBUILD_REEXEC=1 nixos-rebuild ${rebuildArg} '$@"
else else
exec ssh -t ${target} nixos-rebuild --flake ${self}#${name} $@ exec ssh -t ${target} nixos-rebuild ${rebuildArg} $@
fi fi
''; '';
mkWake = name: mkWake = name:
@ -55,31 +66,61 @@
in { in {
inherit (pkgs) bmxd; inherit (pkgs) bmxd;
dhcp-nixos-rebuild = mkDeploy "dhcp" hostRegistry.hosts.dhcp.ip4; dhcp-nixos-rebuild = mkDeploy {
name = "dhcp";
host = hostRegistry.hosts.dhcp.ip4;
};
glotzbert-nixos-rebuild = mkDeploy "glotzbert" "glotzbert.hq.c3d2.de"; glotzbert-nixos-rebuild = mkDeploy { name = "glotzbert"; };
glotzbert-wake = mkWake "glotzbert"; glotzbert-wake = mkWake "glotzbert";
pulsebert-nixos-rebuild = mkDeploy "pulsebert" "pulsebert.hq.c3d2.de"; pulsebert-nixos-rebuild = mkDeploy {
name = "pulsebert";
builders = [ "ssh://client@172.22.99.110" ];
};
pulsebert-wake = mkWake "pulsebert"; pulsebert-wake = mkWake "pulsebert";
yggdrasil-nixos-rebuild = mkDeploy "yggdrasil" "172.20.72.62"; yggdrasil-nixos-rebuild = mkDeploy {
name = "yggdrasil";
host = "172.20.72.62";
};
freifunk-nixos-rebuild = mkDeploy "freifunk" "freifunk.core.zentralwerk.org"; freifunk-nixos-rebuild = mkDeploy {
name = "freifunk";
host = "freifunk.core.zentralwerk.org";
};
matemat-nixos-rebuild = mkDeploy "matemat" hostRegistry.hosts.matemat.ip4; matemat-nixos-rebuild = mkDeploy {
name = "matemat";
};
scrape-nixos-rebuild = mkDeploy "scrape" hostRegistry.hosts.scrape.ip4; scrape-nixos-rebuild = mkDeploy {
name = "scrape";
host = hostRegistry.hosts.scrape.ip4;
};
dn42-nixos-rebuild = mkDeploy "dn42" hostRegistry.hosts.dn42.ip4; dn42-nixos-rebuild = mkDeploy {
name = "dn42";
};
grafana-nixos-rebuild = mkDeploy "grafana" "grafana.hq.c3d2.de"; grafana-nixos-rebuild = mkDeploy {
name = "grafana";
};
hydra-nixos-rebuild = mkDeploy "hydra" hostRegistry.hosts.hydra.ip4; hydra-nixos-rebuild = mkDeploy {
name = "hydra";
host = hostRegistry.hosts.hydra.ip4;
};
mucbot-nixos-rebuild = mkDeploy "mucbot" hostRegistry.hosts.mucbot.ip4; mucbot-nixos-rebuild = mkDeploy {
name = "mucbot";
host = hostRegistry.hosts.mucbot.ip4;
};
kibana-nixos-rebuild = mkDeploy "kibana" hostRegistry.hosts.kibana.ip4; kibana-nixos-rebuild = mkDeploy {
name = "kibana";
host = hostRegistry.hosts.kibana.ip4;
};
}); });
nixosConfigurations = let nixosConfigurations = let