refactor(ssh): centralize SSH config into ssh module

This commit is contained in:
2026-07-12 13:43:11 +02:00
parent 0fd3fe2570
commit beb894e97c
4 changed files with 34 additions and 22 deletions
+32 -9
View File
@@ -2,11 +2,17 @@
config,
lib,
pkgs,
myUtils,
...
}:
let
cfg = config.ssh;
hostDir = ../../../hosts;
hostsWithKeys = lib.filter (hostname: builtins.pathExists (hostDir + "/${hostname}/ssh_host.pub")) (
myUtils.dirNames hostDir
);
in
{
options.ssh.enable = lib.mkEnableOption "ssh";
@@ -14,6 +20,8 @@ in
config = lib.mkIf cfg.enable {
home.packages = with pkgs; [ sshfs ];
home.file.".ssh/control/.keep".text = "";
services.ssh-agent.enable = true;
systemd.user.services.ssh-agent.Service.Environment = [
@@ -25,16 +33,31 @@ in
enable = true;
enableDefaultConfig = false;
settings = {
"*" = {
AddKeysToAgent = "yes";
ForwardAgent = false;
identityFile = [
"~/.ssh/id_ed25519_sk"
"~/.ssh/id_ed25519_sk_bak"
];
settings =
lib.genAttrs hostsWithKeys (
hostname:
let
meta = myUtils.hostMeta (hostDir + "/${hostname}");
in
{
User = meta.host.username;
HostName = hostname;
}
)
// {
"*" = {
AddKeysToAgent = "yes";
ForwardAgent = false;
identityFile = [
"~/.ssh/id_ed25519_sk"
"~/.ssh/id_ed25519_sk_bak"
];
IdentitiesOnly = true;
ControlMaster = "auto";
ControlPath = "~/.ssh/control/%C";
ControlPersist = "10m";
};
};
};
};
};
}