Skip to content

Commit c8673ea

Browse files
zowoqzimbatm
andcommitted
flake: expose {darwin,nixos}Modules automatically
Co-authored-by: Jonas Chevalier <[email protected]>
1 parent 872b09a commit c8673ea

File tree

2 files changed

+47
-23
lines changed

2 files changed

+47
-23
lines changed

flake.nix

+1-23
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
systems = import inputs.systems;
6161

6262
imports = [
63+
./modules
6364
inputs.lite-config.flakeModule
6465
inputs.treefmt-nix.flakeModule
6566
];
@@ -149,28 +150,5 @@
149150
nixosTests-hydra = pkgs.nixosTests.hydra.hydra;
150151
};
151152
};
152-
153-
flake.darwinModules = {
154-
builder = ./modules/darwin/builder.nix;
155-
community-builder = ./modules/darwin/community-builder;
156-
hercules-ci = ./modules/darwin/hercules-ci.nix;
157-
remote-builder = ./modules/darwin/remote-builder.nix;
158-
};
159-
160-
flake.nixosModules = {
161-
backup = ./modules/nixos/backup.nix;
162-
buildbot = ./modules/nixos/buildbot.nix;
163-
builder = ./modules/nixos/builder.nix;
164-
community-builder = ./modules/nixos/community-builder;
165-
disko-zfs = ./modules/nixos/disko-zfs.nix;
166-
github-org-backup = ./modules/nixos/github-org-backup.nix;
167-
hercules-ci = ./modules/nixos/hercules-ci.nix;
168-
hydra = ./modules/nixos/hydra.nix;
169-
monitoring = ./modules/nixos/monitoring;
170-
nginx = ./modules/nixos/nginx.nix;
171-
nur-update = ./modules/nixos/nur-update.nix;
172-
remote-builder = ./modules/nixos/remote-builder.nix;
173-
watch-store = ./modules/nixos/watch-store.nix;
174-
};
175153
};
176154
}

modules/default.nix

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{ inputs, lib, ... }:
2+
# https://github.com/numtide/blueprint/blob/19df68dde6fe1aeaf15c747b16708136b40d2ab7/lib/default.nix
3+
let
4+
importDir =
5+
path: fn:
6+
let
7+
entries = builtins.readDir path;
8+
9+
onlyDirs = lib.filterAttrs (
10+
name: type:
11+
type == "directory"
12+
&&
13+
# filter `common` dir
14+
(name != "common")
15+
) entries;
16+
dirPaths = lib.mapAttrs (name: type: {
17+
path = path + "/${name}";
18+
inherit type;
19+
}) onlyDirs;
20+
21+
nixPaths = builtins.removeAttrs (lib.mapAttrs' (
22+
name: type:
23+
let
24+
nixName = builtins.match "(.*)\\.nix" name;
25+
in
26+
{
27+
name = if type == "directory" || nixName == null then "__junk" else (builtins.head nixName);
28+
value = {
29+
path = path + "/${name}";
30+
inherit type;
31+
};
32+
}
33+
) entries) [ "__junk" ];
34+
35+
combined = dirPaths // nixPaths;
36+
in
37+
lib.optionalAttrs (builtins.pathExists path) (fn combined);
38+
39+
modules = path: importDir path (lib.mapAttrs (_name: { path, type }: path));
40+
in
41+
{
42+
flake = {
43+
darwinModules = modules "${inputs.self}/modules/darwin";
44+
nixosModules = modules "${inputs.self}/modules/nixos";
45+
};
46+
}

0 commit comments

Comments
 (0)