Created
September 28, 2025 18:32
-
-
Save orzklv/0f7a31486a7cde4948fbc8e59ada19f4 to your computer and use it in GitHub Desktop.
Generate nix module config out of list
This file contains hidden or 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
| { | |
| lib, | |
| config, | |
| inputs, | |
| ... | |
| }: let | |
| cfg = config.kolyma.www; | |
| bnest = mod: lib.strings.splitString "." mod; | |
| nest = keys: value: | |
| if keys == [] | |
| then value | |
| else {${builtins.head keys} = nest (builtins.tail keys) value;}; | |
| # Generate an app configuration | |
| generate = app: {...}: let | |
| nested = | |
| "services.${app.option}" | |
| |> bnest | |
| |> nest; | |
| in { | |
| imports = [ | |
| inputs.${app.inputs}.nixosModules.${app.module} | |
| ]; | |
| config = { | |
| ${nested} = { | |
| enable = true; | |
| proxy = { | |
| enable = true; | |
| inherit (app) domain; | |
| }; | |
| }; | |
| }; | |
| }; | |
| # Each app is following this | |
| # { | |
| # inputs = "example"; | |
| # module = "default"; | |
| # option = "some.example"; | |
| # domain = "example.com"; | |
| # secrets = {}; | |
| # } | |
| convert = map generate cfg.apps; | |
| in { | |
| imports = lib.mkIf cfg.enable convert; | |
| options.kolyma.www.apps = lib.kotype.apps; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment