From c2acac6f3e10cf3d746652be61c40adec9970280 Mon Sep 17 00:00:00 2001 From: RGBCube Date: Fri, 28 Feb 2025 18:58:15 +0300 Subject: [PATCH] feat: automatically generate ssh matchblocks --- modules/common/ssh/default.nix | 36 +++++++++++++--------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/modules/common/ssh/default.nix b/modules/common/ssh/default.nix index dbdd035..cbfca51 100644 --- a/modules/common/ssh/default.nix +++ b/modules/common/ssh/default.nix @@ -1,7 +1,19 @@ { self, config, lib, pkgs, ... }: let - inherit (lib) enabled mkIf; + inherit (lib) enabled mkIf filterAttrs attrNames mapAttrs head remove; controlPath = "~/.ssh/control"; + + hosts = self.nixosConfigurations + |> filterAttrs (_: value: value.config.services.openssh.enable) + |> mapAttrs (_: value: { + hostname = value.config.networking.ipv4.address; + + user = value.config.users.users + |> attrNames + |> remove "root" + |> remove "backup" + |> head; + }); in { secrets.sshConfig = { file = ./config.age; @@ -24,33 +36,13 @@ in { includes = [ config.secrets.sshConfig.path ]; - matchBlocks = { + matchBlocks = hosts // { "*" = { setEnv.COLORTERM = "truecolor"; setEnv.TERM = "xterm-256color"; identityFile = "~/.ssh/id"; }; - - # TODO: Maybe autogenerate these? - - best = { - hostname = self.best.networking.ipv4.address; - user = "the"; - port = 2222; - }; - - disk = { - hostname = self.disk.networking.ipv4.address; - user = "floppy"; - port = 2222; - }; - - nine = { - hostname = self.nine.networking.ipv4.address; - user = "seven"; - port = 2222; - }; }; }; }];