|
9 | 9 | literalExpression; |
10 | 10 | in |
11 | 11 | { |
12 | | - options = { |
13 | | - perSystem = mkPerSystemOption |
14 | | - ({ config, self', inputs', pkgs, system, ... }: { |
15 | | - options.process-compose = mkOption { |
16 | | - description = mdDoc '' |
17 | | - process-compose-flake: creates [process-compose](https://github.com/F1bonacc1/process-compose) |
18 | | - executables from process-compose configurations written as Nix attribute sets. |
19 | | - ''; |
20 | | - type = types.attrsOf (types.submodule ({ config, ... }: { |
21 | | - options = { |
22 | | - package = mkOption { |
23 | | - type = types.package; |
24 | | - default = pkgs.process-compose; |
25 | | - defaultText = lib.literalExpression "pkgs.process-compose"; |
26 | | - description = '' |
27 | | - The process-compose package to bundle up in the command package and flake app. |
28 | | - ''; |
29 | | - }; |
30 | | - settings = mkOption { |
31 | | - type = (pkgs.formats.yaml { }).type; |
32 | | - example = |
33 | | - # packages.${system}.watch-server becomes available |
34 | | - # execute `nix run .#watch-server` or incude packages.${system}.watch-server |
35 | | - # as a nativeBuildInput to your devShell |
36 | | - literalExpression '' |
37 | | - { |
38 | | - watch-server = { |
39 | | - processes = { |
40 | | - backend = "''${pkgs.simple-http-server}"; |
41 | | - frontend = "''${pkgs.simple-http-server}"; |
42 | | - }; |
43 | | - }; |
44 | | - }; |
45 | | - ''; |
46 | | - description = mdDoc '' |
47 | | - For each attribute `x = process-compose config` a flake app and package `x` is added to the flake. |
48 | | - Which runs process-compose with the declared config. |
49 | | - ''; |
50 | | - }; |
51 | | - port = mkOption { |
52 | | - type = types.nullOr types.int; |
53 | | - default = null; |
54 | | - description = '' |
55 | | - Port to serve process-compose's Swagger API on. |
56 | | - ''; |
57 | | - }; |
58 | | - tui = mkOption { |
59 | | - type = types.nullOr types.bool; |
60 | | - default = null; |
61 | | - description = "Enable or disable the TUI for the application."; |
62 | | - }; |
63 | | - extraCliArgs = |
64 | | - let |
65 | | - cliArgsAttr = { |
66 | | - port = "-p ${toString config.port}"; |
67 | | - tui = "-t=${lib.boolToString config.tui}"; |
68 | | - }; |
69 | | - getCliArgs = |
70 | | - lib.mapAttrsToList |
71 | | - (opt: arg: lib.optionalString (config.${opt} != null) arg) |
72 | | - cliArgsAttr; |
73 | | - in |
74 | | - mkOption { |
75 | | - type = types.str; |
76 | | - default = lib.concatStringsSep " " getCliArgs; |
77 | | - internal = true; |
78 | | - readOnly = true; |
79 | | - description = '' |
80 | | - Extra command-line arguments to pass to process-compose. |
81 | | - ''; |
82 | | - }; |
83 | | - }; |
84 | | - })); |
| 12 | + options.perSystem = mkPerSystemOption ({ config, pkgs, lib, ... }: |
| 13 | + let |
| 14 | + submoduleWithPkgs = mod: |
| 15 | + types.submoduleWith { |
| 16 | + specialArgs = { inherit pkgs lib; }; |
| 17 | + modules = [ mod ]; |
85 | 18 | }; |
86 | | - }); |
87 | | - }; |
88 | | - config = { |
89 | | - perSystem = { config, self', inputs', pkgs, ... }: |
90 | | - let |
91 | | - toYAMLFile = |
92 | | - attrs: |
93 | | - pkgs.runCommand "toYamlFile" { buildInputs = [ pkgs.yq-go ]; } '' |
94 | | - yq -P '.' ${pkgs.writeTextFile { name = "tmp.json"; text = (builtins.toJSON attrs); }} > $out |
95 | | - ''; |
96 | | - packages = pkgs.lib.mapAttrs |
97 | | - (name: cfg: |
98 | | - pkgs.writeShellApplication { |
99 | | - inherit name; |
100 | | - runtimeInputs = [ cfg.package ]; |
101 | | - text = '' |
102 | | - process-compose up \ |
103 | | - -f ${toYAMLFile cfg.settings} \ |
104 | | - ${cfg.extraCliArgs} \ |
105 | | - "$@" |
106 | | - ''; |
107 | | - } |
108 | | - ) |
109 | | - config.process-compose; |
110 | | - in |
111 | | - { |
112 | | - inherit packages; |
| 19 | + in |
| 20 | + { |
| 21 | + options.process-compose = mkOption { |
| 22 | + description = mdDoc '' |
| 23 | + process-compose-flake: creates [process-compose](https://github.com/F1bonacc1/process-compose) |
| 24 | + executables from process-compose configurations written as Nix attribute sets. |
| 25 | + ''; |
| 26 | + type = types.attrsOf (submoduleWithPkgs { |
| 27 | + imports = [ |
| 28 | + ./process-compose |
| 29 | + ]; |
| 30 | + }); |
113 | 31 | }; |
114 | | - }; |
| 32 | + |
| 33 | + config.packages = lib.mapAttrs |
| 34 | + (name: cfg: cfg.outputs.package) |
| 35 | + config.process-compose; |
| 36 | + }); |
115 | 37 | } |
116 | 38 |
|
0 commit comments