nixos/modules/base/ssh.nix

76 lines
2.2 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}";
};
2025-02-26 15:26:31 +01:00
server = {
hostname = "x.nickolaj.com";
user = "server";
};
2025-02-18 20:17:57 +01:00
# Work hostnames definded in ./networking.nix
2025-03-24 09:49:44 +01:00
"bastion.ao" = {
2025-02-18 20:17:57 +01:00
user = "nij";
identityFile = "${config.age.secrets.ssh-key-ao.path}";
};
2025-03-24 09:49:44 +01:00
"clickhouse.ao" = {
user = "ubuntu";
2025-04-15 20:13:15 +02:00
hostname = "51.158.205.48";
2025-03-24 09:49:44 +01:00
identityFile = "${config.age.secrets.ssh-key-ao.path}";
};
2025-02-18 20:17:57 +01:00
"flex.ao" = {
2025-03-24 09:49:44 +01:00
user = "nij";
2025-02-18 20:17:57 +01:00
hostname = "192.168.2.5";
proxyJump = "bastion.ao";
2025-03-24 09:49:44 +01:00
identityFile = "${config.age.secrets.ssh-key-ao.path}";
};
"scw.ao" = {
user = "nij";
proxyJump = lib.mkDefault "dev.ao";
identityFile = "${config.age.secrets.ssh-key-ao.path}";
};
"dev.ao" = {
user = "nij";
2025-04-01 21:13:44 +02:00
hostname = "192.168.2.28";
2025-03-24 09:49:44 +01:00
proxyJump = lib.mkDefault "bastion.ao";
identityFile = "${config.age.secrets.ssh-key-ao.path}";
2025-02-18 20:17:57 +01:00
};
};
};
};
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
}