Skip to content

Commit 7d49fbd

Browse files
authored
Allow per-config tui/port options (#14)
To do this, we must restructure the options such as that the top-level option is an attrset of submodules. Each submodule then can have its own port/tui (cli) options.
1 parent a1fb056 commit 7d49fbd

File tree

4 files changed

+23
-21
lines changed

4 files changed

+23
-21
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ Let's say you want to have a `devShell` that makes a command `watch-server` avai
2727

2828
To achieve this using `process-compose-flake` you can simply add the following code to the `perSystem` function in your `flake-parts` flake.
2929
```nix
30-
process-compose.configs = {
31-
watch-server.processes = {
30+
process-compose.watch-server = {
31+
settings.processes = {
3232
backend-server.command = "${self'.apps.backend-server.program} --port 9000";
3333
frontend-server.command = "${self'.apps.frontend-server.program} --port 9001";
3434
proxy-server.command =

example/flake.nix

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
inputs.process-compose-flake.flakeModule
1717
];
1818
perSystem = { pkgs, lib, ... }: {
19-
process-compose = {
20-
# This adds a `self.packages.default`
21-
configs."default" = {
19+
# This adds a `self.packages.default`
20+
process-compose."default" = {
21+
settings = {
2222
processes = {
2323

2424
# Print a pony every 2 seconds, because why not.

nix/flake-module.nix

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ in
1717
process-compose-flake: creates [process-compose](https://github.com/F1bonacc1/process-compose)
1818
executables from process-compose configurations written as Nix attribute sets.
1919
'';
20-
type = types.submodule {
20+
type = types.attrsOf (types.submodule ({ config, ... }: {
2121
options = {
2222
package = mkOption {
2323
type = types.package;
@@ -27,11 +27,10 @@ in
2727
The process-compose package to bundle up in the command package and flake app.
2828
'';
2929
};
30-
configs = mkOption {
31-
type = types.attrsOf (pkgs.formats.yaml { }).type;
32-
default = { };
30+
settings = mkOption {
31+
type = (pkgs.formats.yaml { }).type;
3332
example =
34-
# apps.${system}.watch-server and packages.${system}.watch-server become available
33+
# packages.${system}.watch-server becomes available
3534
# execute `nix run .#watch-server` or incude packages.${system}.watch-server
3635
# as a nativeBuildInput to your devShell
3736
literalExpression ''
@@ -64,12 +63,12 @@ in
6463
extraCliArgs =
6564
let
6665
cliArgsAttr = {
67-
port = "-p ${toString config.process-compose.port}";
68-
tui = "-t=${lib.boolToString config.process-compose.tui}";
66+
port = "-p ${toString config.port}";
67+
tui = "-t=${lib.boolToString config.tui}";
6968
};
7069
getCliArgs =
7170
lib.mapAttrsToList
72-
(opt: arg: lib.optionalString (config.process-compose.${opt} != null) arg)
71+
(opt: arg: lib.optionalString (config.${opt} != null) arg)
7372
cliArgsAttr;
7473
in
7574
mkOption {
@@ -82,7 +81,7 @@ in
8281
'';
8382
};
8483
};
85-
};
84+
}));
8685
};
8786
});
8887
};
@@ -95,16 +94,19 @@ in
9594
yq -P '.' ${pkgs.writeTextFile { name = "tmp.json"; text = (builtins.toJSON attrs); }} > $out
9695
'';
9796
packages = pkgs.lib.mapAttrs
98-
(name: processComposeConfig:
97+
(name: cfg:
9998
pkgs.writeShellApplication {
10099
inherit name;
101-
runtimeInputs = [ config.process-compose.package ];
100+
runtimeInputs = [ cfg.package ];
102101
text = ''
103-
process-compose up -f ${toYAMLFile processComposeConfig} ${config.process-compose.extraCliArgs} "$@"
102+
process-compose up \
103+
-f ${toYAMLFile cfg.settings} \
104+
${cfg.extraCliArgs} \
105+
"$@"
104106
'';
105107
}
106108
)
107-
config.process-compose.configs;
109+
config.process-compose;
108110
in
109111
{
110112
inherit packages;

test/flake.nix

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
inputs.process-compose-flake.flakeModule
1414
];
1515
perSystem = { pkgs, lib, ... }: {
16-
process-compose = {
16+
# This adds a `self.packages.default`
17+
process-compose."default" = {
1718
tui = false;
18-
# This adds a `self.packages.default`
19-
configs."default" = {
19+
settings = {
2020
processes = {
2121

2222
# Create a simple sqlite db

0 commit comments

Comments
 (0)