Skip to content

Commit c5cd60e

Browse files
committed
Decouple individual process-compose module
Also add a 'outputs.package' option.
1 parent ed02f6b commit c5cd60e

File tree

3 files changed

+78
-58
lines changed

3 files changed

+78
-58
lines changed

nix/flake-module.nix

Lines changed: 4 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -23,68 +23,15 @@ in
2323
process-compose-flake: creates [process-compose](https://github.com/F1bonacc1/process-compose)
2424
executables from process-compose configurations written as Nix attribute sets.
2525
'';
26-
type = types.attrsOf (submoduleWithPkgs ({ config, ... }: {
26+
type = types.attrsOf (submoduleWithPkgs {
2727
imports = [
28-
./settings.nix
28+
./process-compose
2929
];
30-
options = {
31-
package = mkOption {
32-
type = types.package;
33-
default = pkgs.process-compose;
34-
defaultText = lib.literalExpression "pkgs.process-compose";
35-
description = ''
36-
The process-compose package to bundle up in the command package and flake app.
37-
'';
38-
};
39-
port = mkOption {
40-
type = types.nullOr types.int;
41-
default = null;
42-
description = ''
43-
Port to serve process-compose's Swagger API on.
44-
'';
45-
};
46-
tui = mkOption {
47-
type = types.nullOr types.bool;
48-
default = null;
49-
description = "Enable or disable the TUI for the application.";
50-
};
51-
extraCliArgs =
52-
let
53-
cliArgsAttr = {
54-
port = "-p ${toString config.port}";
55-
tui = "-t=${lib.boolToString config.tui}";
56-
};
57-
getCliArgs =
58-
lib.mapAttrsToList
59-
(opt: arg: lib.optionalString (config.${opt} != null) arg)
60-
cliArgsAttr;
61-
in
62-
mkOption {
63-
type = types.str;
64-
default = lib.concatStringsSep " " getCliArgs;
65-
internal = true;
66-
readOnly = true;
67-
description = ''
68-
Extra command-line arguments to pass to process-compose.
69-
'';
70-
};
71-
};
72-
}));
30+
});
7331
};
7432

7533
config.packages = lib.mapAttrs
76-
(name: cfg:
77-
pkgs.writeShellApplication {
78-
inherit name;
79-
runtimeInputs = [ cfg.package ];
80-
text = ''
81-
process-compose up \
82-
-f ${cfg.settingsYaml} \
83-
${cfg.extraCliArgs} \
84-
"$@"
85-
'';
86-
}
87-
)
34+
(name: cfg: cfg.outputs.package)
8835
config.process-compose;
8936
});
9037
}

nix/process-compose/default.nix

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{ name, config, pkgs, lib, ... }:
2+
3+
let
4+
inherit (lib) types mkOption literalExpression;
5+
in
6+
{
7+
imports = [
8+
./settings.nix
9+
];
10+
11+
options = {
12+
package = mkOption {
13+
type = types.package;
14+
default = pkgs.process-compose;
15+
defaultText = lib.literalExpression "pkgs.process-compose";
16+
description = ''
17+
The process-compose package to bundle up in the command package and flake app.
18+
'';
19+
};
20+
port = mkOption {
21+
type = types.nullOr types.int;
22+
default = null;
23+
description = ''
24+
Port to serve process-compose's Swagger API on.
25+
'';
26+
};
27+
tui = mkOption {
28+
type = types.nullOr types.bool;
29+
default = null;
30+
description = "Enable or disable the TUI for the application.";
31+
};
32+
extraCliArgs =
33+
let
34+
cliArgsAttr = {
35+
port = "-p ${toString config.port}";
36+
tui = "-t=${lib.boolToString config.tui}";
37+
};
38+
getCliArgs =
39+
lib.mapAttrsToList
40+
(opt: arg: lib.optionalString (config.${opt} != null) arg)
41+
cliArgsAttr;
42+
in
43+
mkOption {
44+
type = types.str;
45+
default = lib.concatStringsSep " " getCliArgs;
46+
internal = true;
47+
readOnly = true;
48+
description = ''
49+
Extra command-line arguments to pass to process-compose.
50+
'';
51+
};
52+
outputs.package = mkOption {
53+
type = types.package;
54+
description = ''
55+
The final package that will run 'process-compose up' for this configuration.
56+
'';
57+
};
58+
};
59+
60+
config.outputs.package =
61+
pkgs.writeShellApplication {
62+
inherit name;
63+
runtimeInputs = [ config.package ];
64+
text = ''
65+
process-compose up \
66+
-f ${config.settingsYaml} \
67+
${config.extraCliArgs} \
68+
"$@"
69+
'';
70+
};
71+
}
72+
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{ name, config, pkgs, lib, ... }:
22
let
33
inherit (lib) types mkOption literalExpression;
4-
in {
4+
in
5+
{
56
options = {
67
settings = mkOption {
78
type = (pkgs.formats.yaml { }).type;

0 commit comments

Comments
 (0)