Simplification de secrets.nix

merge-requests/14/head
RatCornu 2025-06-08 17:02:08 +02:00
parent cedff82836
commit 2136a2a1b2
No known key found for this signature in database
GPG Key ID: B3BE02E379E6E8E2
13 changed files with 51 additions and 68 deletions

View File

@ -1,4 +1,11 @@
let let
inherit (import <nixpkgs> { }) lib;
inherit (lib)
attrsets
filesystem
lists
path
;
# Nounous # Nounous
aeltheos_0 = "age1yubikey1qvn7t9hplvnr2w8nsfezfqudz8gq3v8sq99dkdpzmm4a74rng5qgz4v6wzt"; aeltheos_0 = "age1yubikey1qvn7t9hplvnr2w8nsfezfqudz8gq3v8sq99dkdpzmm4a74rng5qgz4v6wzt";
@ -21,6 +28,7 @@ let
# Machines # Machines
hosts = {
apprentix = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDCJV6jqQWEYuwi+OJ9r/4TbBN/cK9NvYWNiJhpFzcc7 root@apprentix"; apprentix = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDCJV6jqQWEYuwi+OJ9r/4TbBN/cK9NvYWNiJhpFzcc7 root@apprentix";
cephiroth = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOsBGkhiu6l3jeo15cQHMu3dPyL025zXPV2ZH02EDYEt root@nixos"; cephiroth = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOsBGkhiu6l3jeo15cQHMu3dPyL025zXPV2ZH02EDYEt root@nixos";
jitsi = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIB6jVMIZ5y2oXX9HOkw7r5UUjw95MlFaFuu7FnEC0Q8z root@jitsi"; jitsi = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIB6jVMIZ5y2oXX9HOkw7r5UUjw95MlFaFuu7FnEC0Q8z root@jitsi";
@ -30,71 +38,42 @@ let
thot = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFKNg1b8ft1L55+joXQ/7Dt2QTOdkea8opTEnq4xrhPU root@thot"; thot = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFKNg1b8ft1L55+joXQ/7Dt2QTOdkea8opTEnq4xrhPU root@thot";
two = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPpaGf8A+XWXBdNrs69RiC0qPbjPHdtkl31OjxrktmF6 root@nixos"; two = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPpaGf8A+XWXBdNrs69RiC0qPbjPHdtkl31OjxrktmF6 root@nixos";
vaultwarden = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICn6vfDlsZVU6TEWg9vTgq9+Fp3irHjytBTky7A4ErRM root@vaultwarden"; vaultwarden = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICn6vfDlsZVU6TEWg9vTgq9+Fp3irHjytBTky7A4ErRM root@vaultwarden";
hosts = {
inherit
apprentix
cephiroth
jitsi
livre
neo
redite
thot
two
vaultwarden
;
}; };
hostnames = [ hostnames = attrsets.mapAttrsToList (host: _: host) hosts;
"apprentix"
"cephiroth"
"jitsi"
"livre"
"neo"
"redite"
"thot"
"two"
"vaultwarden"
];
# Groupes # Groupes
all = [ all = attrsets.mapAttrsToList (_: key: key) hosts;
apprentix
cephiroth
jitsi
livre
neo
thot
two
vaultwarden
];
acme = [ acme = [
jitsi hosts.jitsi
neo hosts.neo
]; ];
# Secrets
commonSecrets = [ "restic/client_env" ];
acmeSecrets = [ "acme/env" ];
# Fonctions utilitaires # Fonctions utilitaires
remove = el: list: builtins.filter (x: el != x) list; listFilesRelative = dir: map (p: path.removePrefix ./. p) (filesystem.listFilesRecursive dir);
genAttrs = genAttrs =
paths: groups: paths: groups:
builtins.foldl' ( builtins.foldl' (acc: secret: acc // { "${secret}".publicKeys = groups ++ nounous; }) { } paths;
acc: secret: acc // { "secrets/${secret}.age".publicKeys = groups ++ nounous; }
) { } paths; # Secrets
commonSecrets = (listFilesRelative ./secrets/common) ++ [
"./secrets/restic/client_env"
];
acmeSecrets = listFilesRelative ./secrets/acme;
in in
(genAttrs commonSecrets (remove apprentix all)) # Secrets communs à toutes les machines (sauf apprentix)
(genAttrs commonSecrets (lists.remove hosts.apprentix all))
# Secrets pour ACME
// (genAttrs acmeSecrets acme) // (genAttrs acmeSecrets acme)
# Secrets pour restic
// builtins.foldl' ( // builtins.foldl' (
acc: name: acc: name:
acc acc
@ -104,19 +83,23 @@ in
in in
genAttrs genAttrs
[ [
"restic/${name}/base-repo" "./secrets/restic/${name}/base-repo"
"restic/${name}/base-password" "./secrets/restic/${name}/base-password"
] ]
[ key ] [ key ]
) )
) { } (remove "thot" hostnames) ) { } (lists.remove "thot" hostnames)
// builtins.mapAttrs (name: value: { publicKeys = value.publicKeys ++ nounous; }) { // attrsets.foldlAttrs (
"secrets/apprentix/root.age".publicKeys = [ apprentix ]; outacc: host: key:
"secrets/common/root.age".publicKeys = remove apprentix all; let
"secrets/neo/appservice_irc_db_env.age".publicKeys = [ neo ]; secrets = listFilesRelative (path.append ./secrets host);
"secrets/neo/coturn_auth_secret.age".publicKeys = [ neo ]; in
"secrets/neo/database_extra_config.age".publicKeys = [ neo ]; outacc
"secrets/neo/note_oidc_extra_config.age".publicKeys = [ neo ]; // builtins.foldl' (
"secrets/neo/ldap_synapse_password.age".publicKeys = [ neo ]; acc: secret:
"secrets/vaultwarden/env.age".publicKeys = [ vaultwarden ]; acc
} // {
"${secret}".publicKeys = [ key ] ++ nounous;
}
) { } secrets
) { } hosts

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File