flake: expose {darwin,nixos}Modules automatically
Co-authored-by: Jonas Chevalier <zimbatm@zimbatm.com>
This commit is contained in:
parent
872b09a8a1
commit
c8673ead6f
2 changed files with 47 additions and 23 deletions
24
flake.nix
24
flake.nix
|
@ -60,6 +60,7 @@
|
||||||
systems = import inputs.systems;
|
systems = import inputs.systems;
|
||||||
|
|
||||||
imports = [
|
imports = [
|
||||||
|
./modules
|
||||||
inputs.lite-config.flakeModule
|
inputs.lite-config.flakeModule
|
||||||
inputs.treefmt-nix.flakeModule
|
inputs.treefmt-nix.flakeModule
|
||||||
];
|
];
|
||||||
|
@ -149,28 +150,5 @@
|
||||||
nixosTests-hydra = pkgs.nixosTests.hydra.hydra;
|
nixosTests-hydra = pkgs.nixosTests.hydra.hydra;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
flake.darwinModules = {
|
|
||||||
builder = ./modules/darwin/builder.nix;
|
|
||||||
community-builder = ./modules/darwin/community-builder;
|
|
||||||
hercules-ci = ./modules/darwin/hercules-ci.nix;
|
|
||||||
remote-builder = ./modules/darwin/remote-builder.nix;
|
|
||||||
};
|
|
||||||
|
|
||||||
flake.nixosModules = {
|
|
||||||
backup = ./modules/nixos/backup.nix;
|
|
||||||
buildbot = ./modules/nixos/buildbot.nix;
|
|
||||||
builder = ./modules/nixos/builder.nix;
|
|
||||||
community-builder = ./modules/nixos/community-builder;
|
|
||||||
disko-zfs = ./modules/nixos/disko-zfs.nix;
|
|
||||||
github-org-backup = ./modules/nixos/github-org-backup.nix;
|
|
||||||
hercules-ci = ./modules/nixos/hercules-ci.nix;
|
|
||||||
hydra = ./modules/nixos/hydra.nix;
|
|
||||||
monitoring = ./modules/nixos/monitoring;
|
|
||||||
nginx = ./modules/nixos/nginx.nix;
|
|
||||||
nur-update = ./modules/nixos/nur-update.nix;
|
|
||||||
remote-builder = ./modules/nixos/remote-builder.nix;
|
|
||||||
watch-store = ./modules/nixos/watch-store.nix;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
46
modules/default.nix
Normal file
46
modules/default.nix
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
{ inputs, lib, ... }:
|
||||||
|
# https://github.com/numtide/blueprint/blob/19df68dde6fe1aeaf15c747b16708136b40d2ab7/lib/default.nix
|
||||||
|
let
|
||||||
|
importDir =
|
||||||
|
path: fn:
|
||||||
|
let
|
||||||
|
entries = builtins.readDir path;
|
||||||
|
|
||||||
|
onlyDirs = lib.filterAttrs (
|
||||||
|
name: type:
|
||||||
|
type == "directory"
|
||||||
|
&&
|
||||||
|
# filter `common` dir
|
||||||
|
(name != "common")
|
||||||
|
) entries;
|
||||||
|
dirPaths = lib.mapAttrs (name: type: {
|
||||||
|
path = path + "/${name}";
|
||||||
|
inherit type;
|
||||||
|
}) onlyDirs;
|
||||||
|
|
||||||
|
nixPaths = builtins.removeAttrs (lib.mapAttrs' (
|
||||||
|
name: type:
|
||||||
|
let
|
||||||
|
nixName = builtins.match "(.*)\\.nix" name;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
name = if type == "directory" || nixName == null then "__junk" else (builtins.head nixName);
|
||||||
|
value = {
|
||||||
|
path = path + "/${name}";
|
||||||
|
inherit type;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
) entries) [ "__junk" ];
|
||||||
|
|
||||||
|
combined = dirPaths // nixPaths;
|
||||||
|
in
|
||||||
|
lib.optionalAttrs (builtins.pathExists path) (fn combined);
|
||||||
|
|
||||||
|
modules = path: importDir path (lib.mapAttrs (_name: { path, type }: path));
|
||||||
|
in
|
||||||
|
{
|
||||||
|
flake = {
|
||||||
|
darwinModules = modules "${inputs.self}/modules/darwin";
|
||||||
|
nixosModules = modules "${inputs.self}/modules/nixos";
|
||||||
|
};
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue