From ab370ae9fb4fe17511b14f12e2c4411fb07d46f8 Mon Sep 17 00:00:00 2001 From: Pyjacpp Date: Sat, 21 Nov 2026 18:56:55 +0100 Subject: [PATCH] feat: known hosts via les infos.nix --- hosts/physiques/cephiroth/info.nix | 1 + modules/crans/ssh.nix | 47 ++++++++++++++++++++++++++++-- modules/info/default.nix | 2 +- 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/hosts/physiques/cephiroth/info.nix b/hosts/physiques/cephiroth/info.nix index 658f166..b0cc869 100644 --- a/hosts/physiques/cephiroth/info.nix +++ b/hosts/physiques/cephiroth/info.nix @@ -3,6 +3,7 @@ description = "Serveur de stockage ceph"; id = 3; + enable = true; # Sous Nix mais dans une autre branche isDebian = true; diff --git a/modules/crans/ssh.nix b/modules/crans/ssh.nix index 3bea073..57520fd 100644 --- a/modules/crans/ssh.nix +++ b/modules/crans/ssh.nix @@ -1,5 +1,19 @@ -{ ... }: - +{ + infra, + lib, + hosts, + ... +}: +let + inherit (lib) + attrNames + concatMap + optional + mapAttrs' + mkIf + nameValuePair + ; +in { services.openssh = { enable = true; @@ -7,5 +21,34 @@ settings = { PermitRootLogin = "yes"; }; + + # knownHosts : + # { + # "host" = { + # hostNames = ["host.adm.crans.org" 172.16.10.2 …] + # publicKey = "ssh-ed25519…" + # } + # } + knownHosts = mapAttrs' ( + n: conf: + nameValuePair n ( + mkIf (conf.publicSsh != null) { + publicKey = conf.publicSsh; + + hostNames = [ + "${n}.adm.crans.org" + ] + ++ concatMap ( + vlan: + let + netv = conf.networking.${vlan}; + in + optional (netv.enable && (netv.ipv4.address or null) != null) netv.ipv4.address + ++ optional (netv.enable && (netv.ipv6.address or null) != null) netv.ipv6.address + ) (attrNames infra.vlans); + } + ) + ) hosts; + }; } diff --git a/modules/info/default.nix b/modules/info/default.nix index 8fd8502..27bdfa0 100644 --- a/modules/info/default.nix +++ b/modules/info/default.nix @@ -27,7 +27,7 @@ in example = true; description = "Activer la configuration Crans par défaut"; # On n’utilise pas mkEnableOption pour forcer la définition de enable à true - # ou false (et limiter les oublis) + # ou false (et limiter les oublis). }; config = mkIf config.enable { homeNounou.enable = mkDefault true;