-
Notifications
You must be signed in to change notification settings - Fork 1
/
secrets.nix
68 lines (64 loc) · 1.69 KB
/
secrets.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
let
flake = (import ./default.nix);
system = builtins.currentSystem;
lib = flake.lib;
# The SSH private (user) keys on these hosts will be able to decrypt all secrets
globalKeyHosts = [ "hurricane" "meteor" "pulsar" ];
in
with builtins; with lib;
(
let
globalKeys = map (host: readFile' (./host + "/${host}/ssh/id_ed25519.pub")) globalKeyHosts;
hostKeys = (
mapAttrs'
(name: type:
nameValuePair
name
(
filter
(hasPrefix "ssh-ed25519")
(
mapAttrsToList
(name': type': readFile' (./host-key + "/${name}/${name'}"))
(
filterAttrs
(name': type': (hasSuffix ".pub" name'))
(readDir (./host-key + "/${name}"))
)
)
)
)
(
filterAttrs
(name: type: type == "directory")
(readDir ./host-key)
)
);
allHostKeys = flatten (mapAttrsToList (host: keys: keys) hostKeys);
find = dir: map (path: removePrefix "${toString ./.}/" (toString path)) (findModules "" dir);
genAgeConfig =
keys: dir:
listToAttrs (
map
(file:
nameValuePair
(if hasSuffix ".age" file then file else "${file}.age")
{ publicKeys = keys; }
)
(find dir)
);
in
foldl recursiveUpdate { } (
[
(genAgeConfig (globalKeys ++ allHostKeys) ./asset)
]
++
(
mapAttrsToList
(name: keys:
genAgeConfig (globalKeys ++ keys) (./host + "/${name}")
)
hostKeys
)
)
)