remote-builders -> known-hosts, add aliases

This commit is contained in:
2024-10-11 14:24:31 +02:00
parent b9615589b4
commit c602b45922
12 changed files with 55 additions and 30 deletions

View File

@@ -1,20 +1,37 @@
{ config, lib, ... }:
# TODO: make a remote-build user on nixos boxes, instead of giving access to pbsds
# TODO: https://exozy.me/quickstart
# TODO: https://github.com/winterqt/darwin-build-box
# TODO: https://exozy.me/about
let
inherit (builtins) map fromTOML readFile elem attrNames attrValues;
inherit (lib) mkIf;
known-hosts' = lib.importTOML ../hosts/known-hosts.toml; # TODO: eww
known-hosts = lib.pipe known-hosts' [
(lib.flip lib.removeAttrs ["__default__"])
(lib.mapAttrs (name: host:
lib.recursiveUpdate (known-hosts'."__default__" or {}) host
))
];
known-hosts = let
known-hosts' = lib.importTOML ../hosts/known-hosts.toml; # TODO: eww
in
lib.pipe known-hosts' [
(lib.flip lib.removeAttrs ["__default__"])
(lib.mapAttrs (fqdn: host:
lib.recursiveUpdate (
(known-hosts'."__default__" or {})
// { isAlias = false; }
) host
))
(lib.mapAttrsToList (fqdn: host: let
allHostnames = [ fqdn ] ++ host.aliases;
in lib.forEach allHostnames (alias:
lib.nameValuePair
alias
(host // {
aliases = lib.remove alias allHostnames;
isAlias = fqdn != alias;
})
)
))
lib.flatten
lib.listToAttrs
];
hostNames = attrNames known-hosts;
thisHost = known-hosts.${config.networking.fqdn};
thisHostIsBuilder = thisHost.buildMachine.maxJobs > 0;
@@ -30,12 +47,18 @@ let
};
thatHostIsBuilder = thatHost.buildMachine.maxJobs > 0;
thatHostIsConsumer = thatHost.ssh ? userPublicKey && thisHostIsBuilder;
thatHostIsThis = fqdn == config.networking.fqdn;
thatHostIsThis = builtins.elem config.networking.fqdn ([ fqdn ] ++ thatHost.aliases);
in mkIf (!thatHostIsThis) ( lib.mkMerge [
# out
(lib.mkIf (thisHostIsConsumer && thatHostIsBuilder) {
nix.buildMachines = [ buildMachine ];
# TODO: Allow setting speedFactor for local builds, as local is currently fixed to 0
# https://github.com/NixOS/nix/issues/2457
nix.distributedBuilds = true;
# useful when the builder has a faster internet connection than i do
nix.settings.builders-use-substitutes = true;
nix.buildMachines = lib.mkIf (!thatHost.isAlias) [ buildMachine ];
})
# out or jump
@@ -46,7 +69,7 @@ let
# timeouts are great when remote is unresponsive. nix doesn't care, lix is way and tests each remote only once
programs.ssh.extraConfig = ''
Host ${fqdn}
ConnectTimeout 3
ConnectTimeout ${builtins.toString thatHost.ssh.connectTimeout}
Port ${builtins.toString thatHost.ssh.listenPort}
${lib.optionalString (thatHost.ssh ? proxyJump) ''
ProxyJump ${thatJump.ssh.listenUser}@${thatHost.ssh.proxyJump}:${builtins.toString thatJump.ssh.listenPort}
@@ -77,14 +100,6 @@ let
in {
nix.distributedBuilds = true;
# TODO: Allow setting speedFactor for local builds, as local is currently fixed to 0
# https://github.com/NixOS/nix/issues/2457
# useful when the builder has a faster internet connection than i do
nix.settings.builders-use-substitutes = true;
imports = lib.forEach hostNames mkRemoteConfig;
}