-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: import configuration based on convention
- Loading branch information
Showing
2 changed files
with
46 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{lib, ...}: let | ||
enumerateModules = basePath: fileName: let | ||
inherit (builtins) readDir; | ||
inherit (lib) attrNames filter filterAttrs pathExists foldl'; | ||
inherit (lib.trivial) pipe; | ||
|
||
packagePaths = path: attrNames (filterAttrs (_: type: type == "directory") (readDir path)); | ||
modulesInPackage = package: [package "${fileName}.nix"]; | ||
renderPath = foldl' (path: elem: path + "/${elem}"); | ||
|
||
modules = pipe (packagePaths basePath) [ | ||
(map modulesInPackage) | ||
(map (renderPath basePath)) | ||
(filter pathExists) | ||
]; | ||
in | ||
{...}: { | ||
imports = modules; | ||
}; | ||
|
||
importConfig = path: let | ||
createModule = enumerateModules path; | ||
in { | ||
options = createModule "options"; | ||
nixDarwin = createModule "darwin-module"; | ||
homeManager = createModule "hm-module"; | ||
}; | ||
|
||
# If a path is specified, | ||
main = configuration: | ||
if configuration.path != null && configuration.scheme == "flat" | ||
then importConfig configuration.path | ||
else configuration; | ||
in | ||
configurations: builtins.mapAttrs (c: v: main v) configurations |