Skip to content

Commit 16bef56

Browse files
committed
contrib: format Nix code with Alejandra
1 parent 99e0963 commit 16bef56

File tree

6 files changed

+240
-221
lines changed

6 files changed

+240
-221
lines changed

modules/age.nix

Lines changed: 52 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
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
69
cfg = config.age;
710

811
# we need at least rage 0.5.0 to support ssh keys
912
rage =
1013
if lib.versionOlder pkgs.rage.version "0.5.0"
11-
then pkgs.callPackage ../pkgs/rage.nix { }
14+
then pkgs.callPackage ../pkgs/rage.nix {}
1215
else pkgs.rage;
1316
ageBin = config.age.ageBin;
1417

@@ -28,11 +31,15 @@ let
2831
identities = builtins.concatStringsSep " " (map (path: "-i ${path}") cfg.identityPaths);
2932

3033
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+
}
3643
'';
3744

3845
installSecret = secretType: ''
@@ -55,9 +62,11 @@ let
5562
''}
5663
'';
5764

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;
6170

6271
cleanupAndLink = ''
6372
_agenix_generation="$(basename "$(readlink ${cfg.secretsDir})" || echo 0)"
@@ -72,10 +81,10 @@ let
7281
'';
7382

7483
installSecrets = builtins.concatStringsSep "\n" (
75-
[ "echo '[agenix] decrypting secrets...'" ]
84+
["echo '[agenix] decrypting secrets...'"]
7685
++ testIdentities
7786
++ (map installSecret (builtins.attrValues cfg.secrets))
78-
++ [ cleanupAndLink ]
87+
++ [cleanupAndLink]
7988
);
8089

8190
chownSecret = secretType: ''
@@ -90,11 +99,12 @@ let
9099
'';
91100

92101
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+
);
96106

97-
secretType = types.submodule ({ config, ... }: {
107+
secretType = types.submodule ({config, ...}: {
98108
options = {
99109
name = mkOption {
100110
type = types.str;
@@ -137,14 +147,12 @@ let
137147
Group of the decrypted secret.
138148
'';
139149
};
140-
symlink = mkEnableOption "symlinking secrets to their destination" // { default = true; };
150+
symlink = mkEnableOption "symlinking secrets to their destination" // {default = true;};
141151
};
142152
});
143-
in
144-
{
145-
153+
in {
146154
imports = [
147-
(mkRenamedOptionModule [ "age" "sshKeyPaths" ] [ "age" "identityPaths" ])
155+
(mkRenamedOptionModule ["age" "sshKeyPaths"] ["age" "identityPaths"])
148156
];
149157

150158
options.age = {
@@ -157,7 +165,7 @@ in
157165
};
158166
secrets = mkOption {
159167
type = types.attrsOf secretType;
160-
default = { };
168+
default = {};
161169
description = ''
162170
Attrset of secrets.
163171
'';
@@ -170,11 +178,13 @@ in
170178
'';
171179
};
172180
secretsMountPoint = mkOption {
173-
type = types.addCheck types.str
181+
type =
182+
types.addCheck types.str
174183
(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)";};
178188
default = "/run/agenix.d";
179189
defaultText = "/run/agenix.d";
180190
description = ''
@@ -184,20 +194,22 @@ in
184194
identityPaths = mkOption {
185195
type = types.listOf types.path;
186196
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 [];
190200
description = ''
191201
Path to SSH keys to be used as identities in age decryption.
192202
'';
193203
};
194204
};
195205

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+
];
201213

202214
# Create a new directory full of secrets for symlinking (this helps
203215
# ensure removed secrets are actually removed, or at least become
@@ -218,7 +230,7 @@ in
218230
};
219231

220232
# So user passwords can be encrypted.
221-
system.activationScripts.users.deps = [ "agenixInstall" ];
233+
system.activationScripts.users.deps = ["agenixInstall"];
222234

223235
# Change ownership and group after users and groups are made.
224236
system.activationScripts.agenixChown = {
@@ -232,8 +244,7 @@ in
232244
# So other activation scripts can depend on agenix being done.
233245
system.activationScripts.agenix = {
234246
text = "";
235-
deps = [ "agenixChown"];
247+
deps = ["agenixChown"];
236248
};
237249
};
238-
239250
}

overlay.nix

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
final: prev:
2-
{
3-
agenix = prev.callPackage ./pkgs/agenix.nix { };
1+
final: prev: {
2+
agenix = prev.callPackage ./pkgs/agenix.nix {};
43
}

0 commit comments

Comments
 (0)