|
1 |
| -{ config, options, lib, pkgs, ... }: |
2 |
| - |
3 |
| -with lib; |
4 |
| - |
5 |
| -let |
| 1 | +{ |
| 2 | + config, |
| 3 | + options, |
| 4 | + lib, |
| 5 | + pkgs, |
| 6 | + ... |
| 7 | +}: |
| 8 | +with lib; let |
6 | 9 | cfg = config.age;
|
7 | 10 |
|
8 | 11 | # we need at least rage 0.5.0 to support ssh keys
|
9 | 12 | rage =
|
10 | 13 | if lib.versionOlder pkgs.rage.version "0.5.0"
|
11 |
| - then pkgs.callPackage ../pkgs/rage.nix { } |
| 14 | + then pkgs.callPackage ../pkgs/rage.nix {} |
12 | 15 | else pkgs.rage;
|
13 | 16 | ageBin = config.age.ageBin;
|
14 | 17 |
|
|
28 | 31 | identities = builtins.concatStringsSep " " (map (path: "-i ${path}") cfg.identityPaths);
|
29 | 32 |
|
30 | 33 | setTruePath = secretType: ''
|
31 |
| - ${if secretType.symlink then '' |
32 |
| - _truePath="${cfg.secretsMountPoint}/$_agenix_generation/${secretType.name}" |
33 |
| - '' else '' |
34 |
| - _truePath="${secretType.path}" |
35 |
| - ''} |
| 34 | + ${ |
| 35 | + if secretType.symlink |
| 36 | + then '' |
| 37 | + _truePath="${cfg.secretsMountPoint}/$_agenix_generation/${secretType.name}" |
| 38 | + '' |
| 39 | + else '' |
| 40 | + _truePath="${secretType.path}" |
| 41 | + '' |
| 42 | + } |
36 | 43 | '';
|
37 | 44 |
|
38 | 45 | installSecret = secretType: ''
|
|
55 | 62 | ''}
|
56 | 63 | '';
|
57 | 64 |
|
58 |
| - testIdentities = map (path: '' |
59 |
| - test -f ${path} || echo '[agenix] WARNING: config.age.identityPaths entry ${path} not present!' |
60 |
| - '') cfg.identityPaths; |
| 65 | + testIdentities = |
| 66 | + map (path: '' |
| 67 | + test -f ${path} || echo '[agenix] WARNING: config.age.identityPaths entry ${path} not present!' |
| 68 | + '') |
| 69 | + cfg.identityPaths; |
61 | 70 |
|
62 | 71 | cleanupAndLink = ''
|
63 | 72 | _agenix_generation="$(basename "$(readlink ${cfg.secretsDir})" || echo 0)"
|
|
72 | 81 | '';
|
73 | 82 |
|
74 | 83 | installSecrets = builtins.concatStringsSep "\n" (
|
75 |
| - [ "echo '[agenix] decrypting secrets...'" ] |
| 84 | + ["echo '[agenix] decrypting secrets...'"] |
76 | 85 | ++ testIdentities
|
77 | 86 | ++ (map installSecret (builtins.attrValues cfg.secrets))
|
78 |
| - ++ [ cleanupAndLink ] |
| 87 | + ++ [cleanupAndLink] |
79 | 88 | );
|
80 | 89 |
|
81 | 90 | chownSecret = secretType: ''
|
|
90 | 99 | '';
|
91 | 100 |
|
92 | 101 | chownSecrets = builtins.concatStringsSep "\n" (
|
93 |
| - [ "echo '[agenix] chowning...'" ] |
94 |
| - ++ [ chownMountPoint ] |
95 |
| - ++ (map chownSecret (builtins.attrValues cfg.secrets))); |
| 102 | + ["echo '[agenix] chowning...'"] |
| 103 | + ++ [chownMountPoint] |
| 104 | + ++ (map chownSecret (builtins.attrValues cfg.secrets)) |
| 105 | + ); |
96 | 106 |
|
97 |
| - secretType = types.submodule ({ config, ... }: { |
| 107 | + secretType = types.submodule ({config, ...}: { |
98 | 108 | options = {
|
99 | 109 | name = mkOption {
|
100 | 110 | type = types.str;
|
@@ -137,14 +147,12 @@ let
|
137 | 147 | Group of the decrypted secret.
|
138 | 148 | '';
|
139 | 149 | };
|
140 |
| - symlink = mkEnableOption "symlinking secrets to their destination" // { default = true; }; |
| 150 | + symlink = mkEnableOption "symlinking secrets to their destination" // {default = true;}; |
141 | 151 | };
|
142 | 152 | });
|
143 |
| -in |
144 |
| -{ |
145 |
| - |
| 153 | +in { |
146 | 154 | imports = [
|
147 |
| - (mkRenamedOptionModule [ "age" "sshKeyPaths" ] [ "age" "identityPaths" ]) |
| 155 | + (mkRenamedOptionModule ["age" "sshKeyPaths"] ["age" "identityPaths"]) |
148 | 156 | ];
|
149 | 157 |
|
150 | 158 | options.age = {
|
|
157 | 165 | };
|
158 | 166 | secrets = mkOption {
|
159 | 167 | type = types.attrsOf secretType;
|
160 |
| - default = { }; |
| 168 | + default = {}; |
161 | 169 | description = ''
|
162 | 170 | Attrset of secrets.
|
163 | 171 | '';
|
|
170 | 178 | '';
|
171 | 179 | };
|
172 | 180 | secretsMountPoint = mkOption {
|
173 |
| - type = types.addCheck types.str |
| 181 | + type = |
| 182 | + types.addCheck types.str |
174 | 183 | (s:
|
175 |
| - (builtins.match "[ \t\n]*" s) == null # non-empty |
176 |
| - && (builtins.match ".+/" s) == null) # without trailing slash |
177 |
| - // { description = "${types.str.description} (with check: non-empty without trailing slash)"; }; |
| 184 | + (builtins.match "[ \t\n]*" s) |
| 185 | + == null # non-empty |
| 186 | + && (builtins.match ".+/" s) == null) # without trailing slash |
| 187 | + // {description = "${types.str.description} (with check: non-empty without trailing slash)";}; |
178 | 188 | default = "/run/agenix.d";
|
179 | 189 | defaultText = "/run/agenix.d";
|
180 | 190 | description = ''
|
|
184 | 194 | identityPaths = mkOption {
|
185 | 195 | type = types.listOf types.path;
|
186 | 196 | default =
|
187 |
| - if config.services.openssh.enable then |
188 |
| - map (e: e.path) (lib.filter (e: e.type == "rsa" || e.type == "ed25519") config.services.openssh.hostKeys) |
189 |
| - else [ ]; |
| 197 | + if config.services.openssh.enable |
| 198 | + then map (e: e.path) (lib.filter (e: e.type == "rsa" || e.type == "ed25519") config.services.openssh.hostKeys) |
| 199 | + else []; |
190 | 200 | description = ''
|
191 | 201 | Path to SSH keys to be used as identities in age decryption.
|
192 | 202 | '';
|
193 | 203 | };
|
194 | 204 | };
|
195 | 205 |
|
196 |
| - config = mkIf (cfg.secrets != { }) { |
197 |
| - assertions = [{ |
198 |
| - assertion = cfg.identityPaths != [ ]; |
199 |
| - message = "age.identityPaths must be set."; |
200 |
| - }]; |
| 206 | + config = mkIf (cfg.secrets != {}) { |
| 207 | + assertions = [ |
| 208 | + { |
| 209 | + assertion = cfg.identityPaths != []; |
| 210 | + message = "age.identityPaths must be set."; |
| 211 | + } |
| 212 | + ]; |
201 | 213 |
|
202 | 214 | # Create a new directory full of secrets for symlinking (this helps
|
203 | 215 | # ensure removed secrets are actually removed, or at least become
|
|
218 | 230 | };
|
219 | 231 |
|
220 | 232 | # So user passwords can be encrypted.
|
221 |
| - system.activationScripts.users.deps = [ "agenixInstall" ]; |
| 233 | + system.activationScripts.users.deps = ["agenixInstall"]; |
222 | 234 |
|
223 | 235 | # Change ownership and group after users and groups are made.
|
224 | 236 | system.activationScripts.agenixChown = {
|
|
232 | 244 | # So other activation scripts can depend on agenix being done.
|
233 | 245 | system.activationScripts.agenix = {
|
234 | 246 | text = "";
|
235 |
| - deps = [ "agenixChown"]; |
| 247 | + deps = ["agenixChown"]; |
236 | 248 | };
|
237 | 249 | };
|
238 |
| - |
239 | 250 | }
|
0 commit comments