fix(nixos): scope SSH lint suppressions

This commit is contained in:
2026-10-07 20:10:44 -04:00
parent dbd3fc8bae
commit 1b682b430f

View File

@@ -6,82 +6,72 @@
}: }:
# Configures inbound and outbound SSH access. # Configures inbound and outbound SSH access.
let let
cfg = config.modules.network.ssh; # NOLINT(let_order) cfg = config.modules.network.ssh;
defaultAuthorizedKeys = lib.flatten ( user = config.user.name; # NOLINT(let_order)
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 = # NOLINT(let_order)
# Keep fleet policy and target construction in conceptual order. workstationNames = [
# NOLINT(let_order) "neogaia"
let "zeus"
workstationNames = [ ];
"neogaia" serverNames = [ "pikachu" ];
"zeus" managedHostNames = workstationNames ++ serverNames; # NOLINT(let_order)
isWorkstation = lib.elem config.networking.hostName workstationNames; # NOLINT(let_order)
isServer = lib.elem config.networking.hostName serverNames; # NOLINT(let_order)
# NOLINT(let_order)
clientKeyFor = host: builtins.readFile (../../hosts + "/${host}/ssh_user_ed25519_key.pub");
hostKeysFor =
host:
map builtins.readFile [
(../../hosts + "/${host}/ssh_host_ed25519_key.pub")
(../../hosts + "/${host}/ssh_host_rsa_key.pub")
];
# NOLINT(let_order)
managedTargets = lib.genAttrs managedHostNames (name: {
hostName = registry.address.${name}.self;
clientKey = clientKeyFor name;
hostKeys = hostKeysFor name;
});
extraTargets = {
# TODO: Pin Gitea's host key after migrating it from Proxmox.
gitea = {
hostName = "git.alexion.dev";
port = 2022;
user = "gitea";
aliases = [
"gitea"
"git.alexion.dev"
]; ];
serverNames = [ "pikachu" ];
managedHostNames = workstationNames ++ serverNames;
isWorkstation = lib.elem config.networking.hostName workstationNames;
isServer = lib.elem config.networking.hostName serverNames;
clientKeyFor = host: builtins.readFile (../../hosts + "/${host}/ssh_user_ed25519_key.pub");
hostKeysFor =
host:
map builtins.readFile [
(../../hosts + "/${host}/ssh_host_ed25519_key.pub")
(../../hosts + "/${host}/ssh_host_rsa_key.pub")
];
managedTargets = lib.genAttrs managedHostNames (name: {
hostName = registry.address.${name}.self;
clientKey = clientKeyFor name;
hostKeys = hostKeysFor name;
});
extraTargets = {
# TODO: Pin Gitea's host key after migrating it from Proxmox.
gitea = {
hostName = "git.alexion.dev";
port = 2022;
user = "gitea";
aliases = [
"gitea"
"git.alexion.dev"
];
};
};
mkTarget = name: target: {
hostName = target.hostName or name;
user = target.user or user;
port = target.port or 22;
aliases = target.aliases or [ name ];
clientKey = target.clientKey or null;
hostKeys = target.hostKeys or [ ];
};
targets = lib.mapAttrs mkTarget (managedTargets // extraTargets);
outboundTargetNames =
let
groupTargets =
if isServer then
[ "gitea" ] ++ serverNames
else if isWorkstation then
[ "gitea" ] ++ serverNames ++ workstationNames
else
[ "gitea" ];
in
lib.filter (name: name != config.networking.hostName) groupTargets;
in
{
inherit
isServer
outboundTargetNames
serverNames
targets
workstationNames
;
}; };
user = config.user.name; };
# NOLINT(let_order)
mkTarget = name: target: {
hostName = target.hostName or name;
user = target.user or user;
port = target.port or 22;
aliases = target.aliases or [ name ];
clientKey = target.clientKey or null;
hostKeys = target.hostKeys or [ ];
};
targets = lib.mapAttrs mkTarget (managedTargets // extraTargets); # NOLINT(let_order)
clientKeysFor = names: lib.filter (key: key != null) (map (name: targets.${name}.clientKey) names); # NOLINT(let_order)
# NOLINT(let_order)
defaultAuthorizedKeys = lib.flatten (
clientKeysFor workstationNames ++ lib.optional isServer (clientKeysFor serverNames)
);
outboundTargetNames = # NOLINT(let_order)
let
groupTargets =
if isServer then
[ "gitea" ] ++ serverNames
else if isWorkstation then
[ "gitea" ] ++ serverNames ++ workstationNames
else
[ "gitea" ];
in
lib.filter (name: name != config.networking.hostName) groupTargets;
knownHosts = lib.listToAttrs ( knownHosts = lib.listToAttrs (
lib.concatLists ( lib.concatLists (
@@ -94,7 +84,7 @@ let
publicKey = keyWithoutComment key; publicKey = keyWithoutComment key;
} }
) target.hostKeys ) target.hostKeys
) fleet.targets ) targets
) )
); );
knownHostNamesFor = knownHostNamesFor =
@@ -109,7 +99,7 @@ let
sshSettingsFor = sshSettingsFor =
name: name:
let let
target = fleet.targets.${name}; target = targets.${name};
in in
{ {
header = "Host ${lib.concatStringsSep " " target.aliases}"; header = "Host ${lib.concatStringsSep " " target.aliases}";
@@ -174,7 +164,7 @@ in
enable = true; enable = true;
enableDefaultConfig = false; enableDefaultConfig = false;
settings = lib.mapAttrs (name: _: sshSettingsFor name) ( settings = lib.mapAttrs (name: _: sshSettingsFor name) (
lib.genAttrs fleet.outboundTargetNames (name: name) lib.genAttrs outboundTargetNames (name: name)
); );
}; };
} }