Skyler Grey | 51e1851 | 2022-08-20 12:24:19 +0100 | [diff] [blame] | 1 | # As our modules have nonstandard properties, we need to have some way of |
| 2 | # properly intepreting them |
| 3 | # This function takes a list of modules, as well as arguments to import them |
| 4 | # with, and returns a list of modules, each with the standard NixOS module |
| 5 | # properties as well as with custom properties as described in /README.md |
Skyler Grey | bcb2cb7 | 2022-08-21 07:24:35 +0100 | [diff] [blame] | 6 | lib: transformArgs: modules: args: let |
Skyler Grey | 51e1851 | 2022-08-20 12:24:19 +0100 | [diff] [blame] | 7 | resolver = module: let |
| 8 | importedModule = |
| 9 | if builtins.typeOf module == "path" |
| 10 | then import module |
| 11 | else module; |
| 12 | resolvedModule = |
| 13 | if builtins.typeOf importedModule == "lambda" |
| 14 | then |
Skyler Grey | bcb2cb7 | 2022-08-21 07:24:35 +0100 | [diff] [blame] | 15 | importedModule |
Skyler Grey | 7dfe5c6 | 2022-08-20 21:41:30 +0100 | [diff] [blame] | 16 | (transformArgs args) |
Skyler Grey | bcb2cb7 | 2022-08-21 07:24:35 +0100 | [diff] [blame] | 17 | else importedModule; |
| 18 | in |
| 19 | lib.warnIfNot ((lib.pipe resolvedModule [ |
| 20 | builtins.attrNames |
| 21 | (lib.subtractLists ["home" "config" "imports" "options"]) |
| 22 | ]) |
| 23 | == []) |
| 24 | "Module ${ |
| 25 | if builtins.typeOf module == "lambda" |
| 26 | then "<AnonFunction>" |
| 27 | else builtins.toString module |
| 28 | } had attribute names ${builtins.toJSON (builtins.attrNames resolvedModule)} but only home, config, imports and options are resolved" { |
| 29 | config = lib.recursiveUpdate (resolvedModule.config or {}) { |
| 30 | home-manager.users."${args.username}".imports = |
| 31 | (resolvedModule.config.home-manager.users."${args.username}".imports or []) |
| 32 | ++ [resolvedModule.home or {}]; |
| 33 | }; |
| 34 | imports = resolvedModule.imports or []; |
| 35 | options = resolvedModule.options or {}; |
Skyler Grey | 51e1851 | 2022-08-20 12:24:19 +0100 | [diff] [blame] | 36 | }; |
Skyler Grey | bcb2cb7 | 2022-08-21 07:24:35 +0100 | [diff] [blame] | 37 | in { |
| 38 | imports = ( |
| 39 | if builtins.typeOf modules == "list" |
| 40 | then builtins.map resolver modules |
| 41 | else [(resolver modules)] |
| 42 | ); |
| 43 | } |