nixos/modules/base/ssh.nix

57 lines
1.6 KiB
Nix
Raw Normal View History

2025-02-18 20:17:57 +01:00
{
config,
username,
hostname,
lib,
...
}: let
2025-02-20 22:50:06 +01:00
# Load all public keys from ../../secrets/hosts/*/id_ed25519.pub
allHosts = lib.attrNames (lib.filterAttrs (_: type: type == "directory") (builtins.readDir ../../secrets/hosts));
publicKeys = map (x: builtins.readFile (../../secrets/hosts + ("/" + x) + "/id_ed25519.pub")) allHosts;
2025-02-18 20:17:57 +01:00
in {
age.secrets.ssh-key = {
2025-02-20 22:50:06 +01:00
rekeyFile = ../../secrets/hosts + ("/" + hostname) + /id_ed25519.age;
path = "/home/" + username + "/.ssh/id_ed25519";
2025-02-18 20:17:57 +01:00
mode = "0600";
owner = username;
};
age.secrets.ssh-key-ao = {
2025-02-20 22:50:06 +01:00
rekeyFile = ../../secrets/ssh-key-ao.age;
2025-02-18 20:17:57 +01:00
mode = "0600";
owner = username;
};
fireproof.home-manager = {
2025-02-20 22:50:06 +01:00
home.file.".ssh/id_ed25519.pub".source = ../../secrets/hosts + ("/" + hostname) + "/id_ed25519.pub";
2025-02-18 20:17:57 +01:00
programs.ssh = {
enable = true;
forwardAgent = true;
matchBlocks = {
"*" = {
identityFile = "${config.age.secrets.ssh-key.path}";
};
# Work hostnames definded in ./networking.nix
"*.ao" = {
user = "nij";
identityFile = "${config.age.secrets.ssh-key-ao.path}";
};
2025-02-19 23:42:24 +01:00
"dev.ao".proxyJump = "bastion.ao";
"scw.ao".proxyJump = "bastion.ao";
2025-02-18 20:17:57 +01:00
"clickhouse.ao".user = "ubuntu";
"flex.ao" = {
hostname = "192.168.2.5";
proxyJump = "bastion.ao";
};
};
};
};
2025-02-03 07:55:17 +01:00
programs.ssh.startAgent = true;
services.openssh = {
enable = true;
settings.PasswordAuthentication = false;
settings.KbdInteractiveAuthentication = false;
};
2025-02-18 20:17:57 +01:00
users.users.${username}.openssh.authorizedKeys.keys = publicKeys;
2025-02-03 07:55:17 +01:00
}