Skip to content

Commit 20bf0c7

Browse files
committed
config(pre-commit/nix): Switch to nixfmt-rfc-style for *.nix files
Nix RFC 166 [1] has been officially accepted and `nixfmt-rfc-style` [2] is the official formatter implementation conforming to the rules agreed upon in the RFC. This commit configures the the Devenv `pre-commit` [3] options to replace our previous formatter `alejandra` [4] with `nixfmt-rfc-style` [2].
1 parent 30b16fa commit 20bf0c7

File tree

30 files changed

+1413
-1210
lines changed

30 files changed

+1413
-1210
lines changed

flake.nix

Lines changed: 56 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -209,49 +209,67 @@
209209
};
210210
};
211211

212-
outputs = inputs @ {
213-
self,
214-
nixpkgs,
215-
flake-parts,
216-
...
217-
}: let
218-
lib = import "${nixpkgs}/lib";
219-
flake = import "${self}/flake.nix";
220-
in
221-
flake-parts.lib.mkFlake {inherit inputs;} {
212+
outputs =
213+
inputs@{
214+
self,
215+
nixpkgs,
216+
flake-parts,
217+
...
218+
}:
219+
let
220+
lib = import "${nixpkgs}/lib";
221+
flake = import "${self}/flake.nix";
222+
in
223+
flake-parts.lib.mkFlake { inherit inputs; } {
222224
imports = [
223225
./modules
224226
./packages
225227
];
226-
systems = ["x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin"];
227-
perSystem = {
228-
system,
229-
pkgs,
230-
inputs',
231-
...
232-
}: {
233-
_module.args.pkgs = import nixpkgs {
234-
inherit system;
235-
config.allowUnfree = true;
236-
};
237-
devShells.default = import ./shells/default.nix {inherit pkgs flake inputs';};
238-
devShells.ci = import ./shells/ci.nix {inherit pkgs;};
239-
};
240-
flake.lib.create = {
241-
rootDir,
242-
machinesDir ? null,
243-
usersDir ? null,
244-
}: {
245-
dirs = {
246-
lib = self + "/lib";
247-
services = self + "/services";
248-
modules = self + "/modules";
249-
machines = rootDir + "/machines";
228+
systems = [
229+
"x86_64-linux"
230+
"aarch64-linux"
231+
"x86_64-darwin"
232+
"aarch64-darwin"
233+
];
234+
perSystem =
235+
{
236+
system,
237+
pkgs,
238+
inputs',
239+
...
240+
}:
241+
{
242+
_module.args.pkgs = import nixpkgs {
243+
inherit system;
244+
config.allowUnfree = true;
245+
};
246+
devShells.default = import ./shells/default.nix { inherit pkgs flake inputs'; };
247+
devShells.ci = import ./shells/ci.nix { inherit pkgs; };
250248
};
251-
libs = {
252-
make-config = import ./lib/make-config.nix {inherit lib rootDir machinesDir usersDir;};
253-
utils = import ./lib {inherit usersDir rootDir machinesDir;};
249+
flake.lib.create =
250+
{
251+
rootDir,
252+
machinesDir ? null,
253+
usersDir ? null,
254+
}:
255+
{
256+
dirs = {
257+
lib = self + "/lib";
258+
services = self + "/services";
259+
modules = self + "/modules";
260+
machines = rootDir + "/machines";
261+
};
262+
libs = {
263+
make-config = import ./lib/make-config.nix {
264+
inherit
265+
lib
266+
rootDir
267+
machinesDir
268+
usersDir
269+
;
270+
};
271+
utils = import ./lib { inherit usersDir rootDir machinesDir; };
272+
};
254273
};
255-
};
256274
};
257275
}

lib/current-flake.nix

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
let
22
currentFlake = builtins.fromJSON (builtins.readFile ../flake.lock);
3-
inherit (currentFlake.nodes.nixos-2311.locked) owner repo rev narHash;
3+
inherit (currentFlake.nodes.nixos-2311.locked)
4+
owner
5+
repo
6+
rev
7+
narHash
8+
;
49
nixpkgs = builtins.fetchTarball {
510
url = "https://github.com/${owner}/${repo}/archive/${rev}.tar.gz";
611
sha256 = narHash;
712
};
813
flake = import ../flake.nix;
9-
in {
14+
in
15+
{
1016
inherit currentFlake flake;
11-
lib = (import nixpkgs {system = "x86_64-linux";}).lib;
17+
lib = (import nixpkgs { system = "x86_64-linux"; }).lib;
1218
}

lib/default.nix

Lines changed: 54 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,81 +3,90 @@
33
rootDir,
44
machinesDir,
55
...
6-
}: let
6+
}:
7+
let
78
inherit (import ./current-flake.nix) lib;
8-
inherit (builtins) attrValues map filter concatLists length listToAttrs typeOf split tail;
9+
inherit (builtins)
10+
attrValues
11+
map
12+
filter
13+
concatLists
14+
length
15+
listToAttrs
16+
typeOf
17+
split
18+
tail
19+
;
920
inherit (lib) pipe filterAttrs strings;
1021
inherit (strings) concatStringsSep;
11-
in rec {
12-
isSubsetOf = needle: haystack:
13-
length (lib.lists.intersectLists needle haystack)
14-
== length needle;
22+
in
23+
rec {
24+
isSubsetOf = needle: haystack: length (lib.lists.intersectLists needle haystack) == length needle;
1525

16-
haveCommonElements = needle: haystack:
17-
length (lib.lists.intersectLists needle haystack)
18-
> 0;
26+
haveCommonElements = needle: haystack: length (lib.lists.intersectLists needle haystack) > 0;
1927

2028
allUsersMembersOfAllGroups = groups: allUsersMembersOfAllGroups' usersInfo groups;
21-
allUsersMembersOfAllGroups' = users: groups:
22-
if groups == []
23-
then {}
29+
allUsersMembersOfAllGroups' =
30+
users: groups:
31+
if groups == [ ] then
32+
{ }
2433
else
25-
filterAttrs
26-
(key: value: isSubsetOf groups (value.extraGroups or []))
27-
users;
34+
filterAttrs (key: value: isSubsetOf groups (value.extraGroups or [ ])) users;
2835

2936
allUsersMembersOfAnyGroup = groups: allUsersMembersOfAnyGroup' usersInfo groups;
30-
allUsersMembersOfAnyGroup' = users: groups:
31-
if groups == []
32-
then {}
37+
allUsersMembersOfAnyGroup' =
38+
users: groups:
39+
if groups == [ ] then
40+
{ }
3341
else
34-
filterAttrs
35-
(key: value: haveCommonElements groups (value.extraGroups or []))
36-
users;
42+
filterAttrs (key: value: haveCommonElements groups (value.extraGroups or [ ])) users;
3743

38-
missing = attrs: key:
39-
!(attrs ? "${key}");
44+
missing = attrs: key: !(attrs ? "${key}");
4045

4146
allAssignedGroups = predefinedGroups: allAssignedGroups' usersInfo predefinedGroups;
42-
allAssignedGroups' = users: predefinedGroups:
47+
allAssignedGroups' =
48+
users: predefinedGroups:
4349
pipe users [
4450
attrValues
45-
(map (u: u.extraGroups or []))
51+
(map (u: u.extraGroups or [ ]))
4652
concatLists
4753
lib.lists.unique
4854
(filter (g: missing predefinedGroups g))
4955
(map (g: {
5056
name = g;
51-
value = {};
57+
value = { };
5258
}))
5359
listToAttrs
5460
];
5561

5662
allUserKeysForGroup = groups: allUserKeysForGroup' usersInfo groups;
57-
allUserKeysForGroup' = users: groups:
58-
concatLists
59-
(map (value: value.openssh.authorizedKeys.keys or [])
60-
(attrValues (allUsersMembersOfAnyGroup' users groups)));
63+
allUserKeysForGroup' =
64+
users: groups:
65+
concatLists (
66+
map (value: value.openssh.authorizedKeys.keys or [ ]) (
67+
attrValues (allUsersMembersOfAnyGroup' users groups)
68+
)
69+
);
6170

62-
zfsFileSystems = datasetList: let
63-
zfsRoot = "zfs_root";
64-
splitPath = path: filter (x: (typeOf x) == "string") (split "/" path);
65-
pathTail = path: concatStringsSep "/" (tail (splitPath path));
66-
makeZfs = zfsDataset: {
67-
name = "/" + pathTail zfsDataset;
68-
value = {
69-
device = "${zfsRoot}/${zfsDataset}";
70-
fsType = "zfs";
71-
options = ["zfsutil"];
71+
zfsFileSystems =
72+
datasetList:
73+
let
74+
zfsRoot = "zfs_root";
75+
splitPath = path: filter (x: (typeOf x) == "string") (split "/" path);
76+
pathTail = path: concatStringsSep "/" (tail (splitPath path));
77+
makeZfs = zfsDataset: {
78+
name = "/" + pathTail zfsDataset;
79+
value = {
80+
device = "${zfsRoot}/${zfsDataset}";
81+
fsType = "zfs";
82+
options = [ "zfsutil" ];
83+
};
7284
};
73-
};
74-
in
85+
in
7586
listToAttrs (map makeZfs datasetList);
7687

7788
allUsers = builtins.attrNames (
78-
lib.filterAttrs
79-
(n: v: v == "directory")
80-
(builtins.readDir "${usersDir}")
89+
lib.filterAttrs (n: v: v == "directory") (builtins.readDir "${usersDir}")
8190
);
8291

8392
readUserInfo = user: import "${usersDir}/${user}/user-info.nix";

lib/import-agenix.nix

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
moduleName: {
1+
moduleName:
2+
{
23
config,
34
lib,
45
dirs,
56
...
6-
}: let
7+
}:
8+
let
79
machineConfigPath = config.mcl.host-info.configPath;
810
secretDir = "${machineConfigPath}/secrets/${moduleName}";
911
vmSecretDir = "${vmConfig}/secrets/${moduleName}";
1012
secrets = import "${dirs.services}/${moduleName}/agenix.nix";
11-
in {
13+
in
14+
{
1215
age.secrets = secrets secretDir;
1316

1417
virtualisation.vmVariant = {

lib/make-config.nix

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,23 @@
44
machinesDir,
55
usersDir,
66
...
7-
}: rec {
8-
getMachines = type: (lib.pipe (builtins.readDir "${machinesDir}/${type}") [
9-
(lib.filterAttrs (n: v: v == "directory" && !(lib.hasPrefix "_" n)))
10-
builtins.attrNames
11-
]);
7+
}:
8+
rec {
9+
getMachines =
10+
type:
11+
(lib.pipe (builtins.readDir "${machinesDir}/${type}") [
12+
(lib.filterAttrs (n: v: v == "directory" && !(lib.hasPrefix "_" n)))
13+
builtins.attrNames
14+
]);
1215

1316
allServers = getMachines "server";
1417
allDesktops = getMachines "desktop";
1518
allMachines = allServers ++ allDesktops;
1619

17-
nixosConfigurations = machines: configurations:
20+
nixosConfigurations =
21+
machines: configurations:
1822
(lib.genAttrs machines (configurations false))
19-
// (lib.mapAttrs' (name: value: lib.nameValuePair "${name}-vm" value)
20-
(lib.genAttrs machines (configurations true)));
23+
// (lib.mapAttrs' (name: value: lib.nameValuePair "${name}-vm" value) (
24+
lib.genAttrs machines (configurations true)
25+
));
2126
}

lib/shard-attrs.nix

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
lib: {
2-
shardAttrs = attrs: shardSize: let
3-
attrNames = builtins.attrNames attrs;
4-
shardCount = builtins.ceil ((0.0 + (builtins.length attrNames)) / shardSize);
5-
attrNameShards = lib.pipe (lib.range 0 (shardCount - 1)) [
6-
(builtins.map (i: lib.sublist (i * shardSize) shardSize attrNames))
7-
];
8-
shards = lib.pipe attrNameShards [
9-
(lib.imap0 (i: shard: {
10-
name = builtins.toString i;
11-
value = lib.genAttrs shard (key: attrs.${key});
12-
}))
13-
lib.listToAttrs
14-
];
15-
in
2+
shardAttrs =
3+
attrs: shardSize:
4+
let
5+
attrNames = builtins.attrNames attrs;
6+
shardCount = builtins.ceil ((0.0 + (builtins.length attrNames)) / shardSize);
7+
attrNameShards = lib.pipe (lib.range 0 (shardCount - 1)) [
8+
(builtins.map (i: lib.sublist (i * shardSize) shardSize attrNames))
9+
];
10+
shards = lib.pipe attrNameShards [
11+
(lib.imap0 (
12+
i: shard: {
13+
name = builtins.toString i;
14+
value = lib.genAttrs shard (key: attrs.${key});
15+
}
16+
))
17+
lib.listToAttrs
18+
];
19+
in
1620
shards;
1721
}

0 commit comments

Comments
 (0)