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 | 252927a | 2022-10-18 22:18:15 +0100 | [diff] [blame] | 6 | lib: transformArgs: modules: args @ { pkgs, ... }: |
| 7 | let |
| 8 | resolver = module: |
| 9 | let |
| 10 | importedModule = |
| 11 | if builtins.typeOf module == "path" |
| 12 | then import module |
| 13 | else module; |
| 14 | resolvedModule = |
| 15 | if builtins.typeOf importedModule == "lambda" |
| 16 | then |
| 17 | importedModule |
| 18 | (transformArgs args) |
| 19 | else importedModule; |
| 20 | moduleName = |
| 21 | if builtins.typeOf module == "lambda" |
| 22 | then "<AnonFunction>" |
| 23 | else if builtins.typeOf module == "path" |
| 24 | then builtins.toString module |
| 25 | else builtins.toJSON module; |
Skyler Grey | f649adf | 2022-08-26 06:47:44 +0100 | [diff] [blame] | 26 | in |
Skyler Grey | 252927a | 2022-10-18 22:18:15 +0100 | [diff] [blame] | 27 | lib.warnIfNot |
| 28 | ((lib.pipe resolvedModule [ |
| 29 | builtins.attrNames |
| 30 | (lib.subtractLists [ "home" "config" "imports" "options" "traces" ]) |
| 31 | ]) |
| 32 | == [ ]) |
| 33 | "Module ${moduleName} had attribute names ${builtins.toJSON (builtins.attrNames resolvedModule)} but only home, config, imports and options are resolved" |
| 34 | [ |
| 35 | { |
| 36 | config = lib.recursiveUpdate (resolvedModule.config or { }) { |
| 37 | home-manager.users."${args.username}".imports = |
| 38 | (resolvedModule.config.home-manager.users."${args.username}".imports or [ ]) |
| 39 | ++ [ resolvedModule.home or { } ]; |
Skyler Grey | 345f12d | 2023-01-26 00:39:52 +0000 | [diff] [blame] | 40 | internal.traces = (resolvedModule.traces or [ ]); |
Skyler Grey | 252927a | 2022-10-18 22:18:15 +0100 | [diff] [blame] | 41 | }; |
| 42 | imports = resolvedModule.imports or [ ]; |
| 43 | options = resolvedModule.options or { }; |
| 44 | } |
Skyler Grey | 345f12d | 2023-01-26 00:39:52 +0000 | [diff] [blame] | 45 | ]; |
Skyler Grey | 252927a | 2022-10-18 22:18:15 +0100 | [diff] [blame] | 46 | in |
| 47 | { |
Skyler Grey | bcb2cb7 | 2022-08-21 07:24:35 +0100 | [diff] [blame] | 48 | imports = ( |
| 49 | if builtins.typeOf modules == "list" |
Skyler Grey | f649adf | 2022-08-26 06:47:44 +0100 | [diff] [blame] | 50 | then builtins.concatLists (builtins.map resolver modules) |
| 51 | else resolver modules |
Skyler Grey | bcb2cb7 | 2022-08-21 07:24:35 +0100 | [diff] [blame] | 52 | ); |
| 53 | } |