diff --git a/flake.nix b/flake.nix index d78cfd6..2a8a9bf 100644 --- a/flake.nix +++ b/flake.nix @@ -60,6 +60,7 @@ systems = import inputs.systems; imports = [ + ./modules inputs.lite-config.flakeModule inputs.treefmt-nix.flakeModule ]; @@ -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; - }; }; } diff --git a/modules/default.nix b/modules/default.nix new file mode 100644 index 0000000..34967b1 --- /dev/null +++ b/modules/default.nix @@ -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"; + }; +}