Skip to content

Commit

Permalink
flake: expose {darwin,nixos}Modules automatically
Browse files Browse the repository at this point in the history
Co-authored-by: Jonas Chevalier <zimbatm@zimbatm.com>
  • Loading branch information
zowoq and zimbatm committed Nov 12, 2024
1 parent 872b09a commit c8673ea
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 23 deletions.
24 changes: 1 addition & 23 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
systems = import inputs.systems;

imports = [
./modules
inputs.lite-config.flakeModule
inputs.treefmt-nix.flakeModule
];
Expand Down Expand Up @@ -149,28 +150,5 @@
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 changes: 46 additions & 0 deletions modules/default.nix
Original file line number Diff line number Diff line change
@@ -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";
};
}

0 comments on commit c8673ea

Please sign in to comment.