load modules from dir

This commit is contained in:
Hendrik Sokolowski 2023-11-11 01:04:57 +01:00
parent 81610d70f3
commit 660b1a1335

61
modules/default.nix Normal file
View file

@ -0,0 +1,61 @@
{
self,
lib,
inputs,
...
}:
let
mkNixosModule = name: [{ ${name} = import ./${name}; }];
mkBaseImport = name: [ self.nixosModules.${name} ];
# create a list of directory names from given folder
filterModules = dir: builtins.attrNames (lib.attrsets.filterAttrs (n: v: v == "directory") (builtins.readDir dir));
# create nixosModules imports from list
flakeNixosModulesList = modules: lib.attrsets.mergeAttrsList (builtins.concatMap mkNixosModule modules);
flakeNixosBaseImports = modules: lib.lists.flatten (builtins.concatMap mkBaseImport modules);
in
{
# Configuration common to all Linux systems
flake = {
nixosModules = rec {} //
(flakeNixosModulesList (filterModules ./.)) //
{
base.imports = [
self.nixosModules.home-manager
inputs.agenix.nixosModules.default
inputs.musnix.nixosModules.musnix
({
flake,
pkgs,
lib,
unstable,
master,
...
}: {
nixpkgs.overlays = (import ../overlays) ++ [
(prev: next: {
scan2paperless = inputs.scan2paperless.legacyPackages.${prev.system}.scan2paperless;
nixd = inputs.unstable.legacyPackages.${prev.system}.nixd;
factorio-headless = inputs.master.legacyPackages.${prev.system}.factorio-headless;
paperless-ngx = inputs.master.legacyPackages.${prev.system}.paperless-ngx;
waybar = inputs.master.legacyPackages.${prev.system}.waybar;
element-desktop = inputs.master.legacyPackages.${prev.system}.element-desktop;
adlist = inputs.adblock-unbound.packages.${prev.system};
})
];
nix.nixPath = [
"nixpkgs=${inputs.nixpkgs}"
"nixos-config=${../lib/compat/nixos}"
"home-manager=${inputs.home-manager}"
];
})
] ++ (flakeNixosBaseImports (filterModules ./.));
};
};
}