refactor(nixos): isolate SSH fleet configuration

This commit is contained in:
2026-10-07 20:05:55 -04:00
parent 879d17dce8
commit dbd3fc8bae

View File

@@ -5,12 +5,19 @@
... ...
}: }:
# Configures inbound and outbound SSH access. # Configures inbound and outbound SSH access.
# Keep bindings grouped by purpose rather than dependency traversal. let
cfg = config.modules.network.ssh; # NOLINT(let_order)
defaultAuthorizedKeys = lib.flatten (
clientKeysFor fleet.workstationNames
++ lib.optional fleet.isServer (clientKeysFor fleet.serverNames)
);
clientKeysFor =
names: lib.filter (key: key != null) (map (name: fleet.targets.${name}.clientKey) names);
fleet =
# Keep fleet policy and target construction in conceptual order.
# NOLINT(let_order) # NOLINT(let_order)
let let
cfg = config.modules.network.ssh;
user = config.user.name;
workstationNames = [ workstationNames = [
"neogaia" "neogaia"
"zeus" "zeus"
@@ -53,11 +60,6 @@ let
hostKeys = target.hostKeys or [ ]; hostKeys = target.hostKeys or [ ];
}; };
targets = lib.mapAttrs mkTarget (managedTargets // extraTargets); targets = lib.mapAttrs mkTarget (managedTargets // extraTargets);
clientKeysFor = names: lib.filter (key: key != null) (map (name: targets.${name}.clientKey) names);
defaultAuthorizedKeys = lib.flatten (
clientKeysFor workstationNames ++ lib.optional isServer (clientKeysFor serverNames)
);
outboundTargetNames = outboundTargetNames =
let let
groupTargets = groupTargets =
@@ -69,6 +71,17 @@ let
[ "gitea" ]; [ "gitea" ];
in in
lib.filter (name: name != config.networking.hostName) groupTargets; lib.filter (name: name != config.networking.hostName) groupTargets;
in
{
inherit
isServer
outboundTargetNames
serverNames
targets
workstationNames
;
};
user = config.user.name;
knownHosts = lib.listToAttrs ( knownHosts = lib.listToAttrs (
lib.concatLists ( lib.concatLists (
@@ -81,7 +94,7 @@ let
publicKey = keyWithoutComment key; publicKey = keyWithoutComment key;
} }
) target.hostKeys ) target.hostKeys
) targets ) fleet.targets
) )
); );
knownHostNamesFor = knownHostNamesFor =
@@ -96,7 +109,7 @@ let
sshSettingsFor = sshSettingsFor =
name: name:
let let
target = targets.${name}; target = fleet.targets.${name};
in in
{ {
header = "Host ${lib.concatStringsSep " " target.aliases}"; header = "Host ${lib.concatStringsSep " " target.aliases}";
@@ -161,7 +174,7 @@ in
enable = true; enable = true;
enableDefaultConfig = false; enableDefaultConfig = false;
settings = lib.mapAttrs (name: _: sshSettingsFor name) ( settings = lib.mapAttrs (name: _: sshSettingsFor name) (
lib.genAttrs outboundTargetNames (name: name) lib.genAttrs fleet.outboundTargetNames (name: name)
); );
}; };
} }