From f6a49879e6703c289eb5f65fac14e7d01de985c5 Mon Sep 17 00:00:00 2001 From: alexion Date: Wed, 7 Oct 2026 19:39:32 -0400 Subject: [PATCH] refactor(nixos): derive managed SSH targets --- configs/nixos/modules/network/ssh.nix | 53 +++++++++++---------------- 1 file changed, 21 insertions(+), 32 deletions(-) diff --git a/configs/nixos/modules/network/ssh.nix b/configs/nixos/modules/network/ssh.nix index 21de18e..1feb509 100644 --- a/configs/nixos/modules/network/ssh.nix +++ b/configs/nixos/modules/network/ssh.nix @@ -12,7 +12,7 @@ let ); clientKeysFor = names: lib.filter (key: key != null) (map (name: targets.${name}.clientKey) names); - targets = lib.mapAttrs mkTarget defaultTargets; + targets = lib.mapAttrs mkTarget (managedTargets // extraTargets); mkTarget = name: target: { hostName = target.hostName or name; user = target.user or user; @@ -23,7 +23,26 @@ let }; user = config.user.name; - defaultTargets = { + managedTargets = lib.genAttrs managedHostNames (name: { + hostName = registry.address.${name}.self; + clientKey = clientKeyFor name; + hostKeys = hostKeysFor name; + }); + managedHostNames = workstationNames ++ serverNames; + workstationNames = [ + "neogaia" + "zeus" + ]; + serverNames = [ "pikachu" ]; + 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") + ]; + + extraTargets = { # TODO: Pin Gitea's host key after migrating it from Proxmox. gitea = { hostName = "git.alexion.dev"; @@ -34,38 +53,8 @@ let "git.alexion.dev" ]; }; - - neogaia = { - hostName = registry.address.neogaia.self; - clientKey = clientKeyFor "neogaia"; - hostKeys = hostKeysFor "neogaia"; - }; - - zeus = { - hostName = registry.address.zeus.self; - clientKey = clientKeyFor "zeus"; - hostKeys = hostKeysFor "zeus"; - }; - - pikachu = { - hostName = registry.address.pikachu.self; - clientKey = clientKeyFor "pikachu"; - hostKeys = hostKeysFor "pikachu"; - }; }; - 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") - ]; - workstationNames = [ - "neogaia" - "zeus" - ]; isServer = lib.elem config.networking.hostName serverNames; - serverNames = [ "pikachu" ]; knownHosts = lib.listToAttrs ( lib.concatLists (