nix-config/keys/default.nix
Bruno BELANYI 34a3f9a0d6 modules: secrets: centralize agenix keys
If I intend on splitting the keys depending on which host needs to have
access to it, I should have a singular spot to manage the keys.
2023-04-16 19:44:02 +01:00

40 lines
774 B
Nix

# Populate agenix keys from a central location
let
inherit (builtins)
mapAttrs
readDir
readFile
stringLength
substring
;
removeSuffix = suffix: str:
let
sufLen = stringLength suffix;
sLen = stringLength str;
in
if sufLen <= sLen && suffix == substring (sLen - sufLen) sufLen str then
substring 0 (sLen - sufLen) str
else
str;
readKeys = dir:
let
files = readDir dir;
readNoNewlines = f: removeSuffix "\n" (readFile f);
readKey = name: readNoNewlines (dir + "/${name}");
in
mapAttrs (n: _: readKey n) files;
hosts = readKeys ./hosts;
users = readKeys ./users;
in
{
inherit
hosts
users;
all = (builtins.attrValues hosts) ++ (builtins.attrValues users);
}