feat: generalize SSH key config

This commit is contained in:
2026-04-26 19:40:29 +02:00
parent 0318dd0cf6
commit 52ea09563f
6 changed files with 34 additions and 48 deletions
+2 -2
View File
@@ -17,8 +17,8 @@ in
scope: scope:
let let
email = account.emails.${scope}.address; email = account.emails.${scope}.address;
key = machine.sourceControl.${scope}; key = lib.attrByPath [ scope ] null machine.sshKeys;
hasSigningKey = key != null && key.publicKey != null; hasSigningKey = key != null;
in in
{ {
allowedSigners = lib.optional hasSigningKey "${email} ${key.publicKey}"; allowedSigners = lib.optional hasSigningKey "${email} ${key.publicKey}";
+8 -1
View File
@@ -1,6 +1,11 @@
{ config, ... }: { config, lib, ... }:
let let
account = config.repo.account; account = config.repo.account;
personalPublicKeys =
machines:
map (machine: machine.sshKeys.personal.publicKey) (
lib.filter (machine: machine.sshKeys ? personal) (builtins.attrValues machines)
);
in in
{ {
flake.modules.nixos.ssh-agent-auth = { flake.modules.nixos.ssh-agent-auth = {
@@ -23,5 +28,7 @@ in
AllowUsers = [ account.name ]; AllowUsers = [ account.name ];
}; };
}; };
users.users.${account.name}.openssh.authorizedKeys.keys = personalPublicKeys config.repo.machines;
}; };
} }
+1 -6
View File
@@ -34,11 +34,6 @@ in
./_disk.nix ./_disk.nix
]; ];
users.users.${account.name} = { users.users.${account.name}.linger = true;
linger = true;
openssh.authorizedKeys.keys = [
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAU2LydkXRTtNFY7oyX8JQURwXLVhB71DeK8XzrXeFX1 openpgp:0xA490D93A"
];
};
}; };
} }
+4 -2
View File
@@ -8,8 +8,10 @@ let
in in
{ {
repo.machines.polaris = { repo.machines.polaris = {
sourceControl.personal.publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEVORk45HKkX7gaGGp90KsVyUy6t+fKhbWN/grjkf3cQ kiri@polaris"; sshKeys = {
sourceControl.work.publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIM5DMV6EQzsscgEOE0912mNglUHTEl+LPnaWYjj0y57B kiri@polaris#work"; personal.publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEVORk45HKkX7gaGGp90KsVyUy6t+fKhbWN/grjkf3cQ kiri@polaris";
work.publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIM5DMV6EQzsscgEOE0912mNglUHTEl+LPnaWYjj0y57B kiri@polaris#work";
};
syncthingId = "6HBAKXB-DB3B4H2-BODCAXF-KD23H5W-6X5LGLC-ZJHZHLG-7U7YMGO-BB6IXQ3"; syncthingId = "6HBAKXB-DB3B4H2-BODCAXF-KD23H5W-6X5LGLC-ZJHZHLG-7U7YMGO-BB6IXQ3";
+1 -1
View File
@@ -10,7 +10,7 @@ in
repo.machines.zenith = { repo.machines.zenith = {
portable = true; portable = true;
sourceControl = { sshKeys = {
personal.publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIQy4k04gU7UpjBgyUQ57kUwxOdt79LvMCiCekXZeZhd kiri@zenith"; personal.publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIQy4k04gU7UpjBgyUQ57kUwxOdt79LvMCiCekXZeZhd kiri@zenith";
work.publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIHJz5uHKm0/TiMNh/cmzrODHNZ8NgEEZe+47XnJwQGk kiri@zenith#work"; work.publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIHJz5uHKm0/TiMNh/cmzrODHNZ8NgEEZe+47XnJwQGk kiri@zenith#work";
}; };
+18 -36
View File
@@ -25,6 +25,22 @@ let
} }
); );
sshKeyType = lib.types.submodule (
{ name, ... }:
{
options = {
publicKey = lib.mkOption {
type = lib.types.str;
};
privateKeyPath = lib.mkOption {
type = lib.types.str;
default = "~/.ssh/id_${name}";
};
};
}
);
accountType = lib.types.submodule ( accountType = lib.types.submodule (
{ config, ... }: { config, ... }:
{ {
@@ -107,40 +123,6 @@ let
} }
); );
sourceControlMachineKeyType = lib.types.submodule (
{ name, ... }:
{
options = {
publicKey = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
};
privateKeyPath = lib.mkOption {
type = lib.types.str;
default = "~/.ssh/id_${name}";
};
};
}
);
sourceControlMachineType = lib.types.submodule (
{ ... }:
{
options = {
personal = lib.mkOption {
type = lib.types.nullOr sourceControlMachineKeyType;
default = null;
};
work = lib.mkOption {
type = lib.types.nullOr sourceControlMachineKeyType;
default = null;
};
};
}
);
machineType = lib.types.submodule ( machineType = lib.types.submodule (
{ name, config, ... }: { name, config, ... }:
{ {
@@ -164,8 +146,8 @@ let
default = { }; default = { };
}; };
sourceControl = lib.mkOption { sshKeys = lib.mkOption {
type = sourceControlMachineType; type = lib.types.attrsOf sshKeyType;
default = { }; default = { };
}; };