forked from Platonic-Systems/process-compose-flake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake-module.nix
87 lines (86 loc) · 2.81 KB
/
flake-module.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
{ self, lib, flake-parts-lib, ... }:
let
inherit (flake-parts-lib)
mkPerSystemOption;
inherit (lib)
mdDoc
mkOption
types
literalExpression;
in
{
options = {
perSystem = mkPerSystemOption
({ config, self', inputs', pkgs, system, ... }: {
options.process-compose = mkOption {
description = mdDoc ''
process-compose-flake: creates [process-compose](https://github.com/F1bonacc1/process-compose)
executables from process-compose configurations written as Nix attribute sets.
'';
type = types.submodule {
options = {
package = mkOption {
type = types.package;
default = pkgs.process-compose;
};
configs = mkOption {
type = types.attrsOf (pkgs.formats.yaml { }).type;
default = { };
example =
# apps.${system}.watch-server and packages.${system}.watch-server become available
# execute `nix run .#watch-server` or incude packages.${system}.watch-server
# as a nativeBuildInput to your devShell
literalExpression ''
{
watch-server = {
processes = {
backend = "''${pkgs.simple-http-server}";
frontend = "''${pkgs.simple-http-server}";
};
};
};
'';
description = mdDoc ''
For each attribute `x = process-compose config` a flake app and package `x` is added to the flake.
Which runs process-compose with the declared config.
'';
};
};
};
};
});
};
config = {
perSystem = { config, self', inputs', pkgs, ... }:
let
toYAMLFile =
attrs:
pkgs.runCommand "toYamlFile" { buildInputs = [ pkgs.yq-go ]; } ''
yq -P '.' ${pkgs.writeTextFile { name = "tmp.json"; text = (builtins.toJSON attrs); }} > $out
'';
packages = pkgs.lib.mapAttrs
(name: processComposeConfig:
pkgs.writeShellApplication {
inherit name;
runtimeInputs = [ config.process-compose.package ];
text = ''
process-compose -f ${toYAMLFile processComposeConfig} "$@"
'';
}
)
config.process-compose.configs;
in
{
inherit packages;
apps = pkgs.lib.mapAttrs'
(name: _: {
inherit name;
value = {
type = "app";
program = packages.${name};
};
})
config.process-compose.configs;
};
};
}