Skip to content

Commit 83fffec

Browse files
committed
Added support for mprocs process manager
1 parent 2420f22 commit 83fffec

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
{ pkgs, config, lib, ... }:
2+
let
3+
cfg = config.process.managers.mprocs;
4+
settingsFormat = pkgs.formats.yaml { };
5+
makeImpurePackage = impurePath:
6+
pkgs.runCommandLocal
7+
"${lib.strings.sanitizeDerivationName impurePath}-impure"
8+
{
9+
__impureHostDeps = [ impurePath ];
10+
} "mkdir -p $out/bin && ln -s ${impurePath} $out/bin";
11+
in
12+
{
13+
options.process.managers.mprocs = {
14+
enable = lib.mkEnableOption "mprocs as the process manager" // {
15+
internal = true;
16+
};
17+
18+
package = lib.mkOption {
19+
type = lib.types.package;
20+
default = pkgs.mprocs;
21+
defaultText = lib.literalExpression "pkgs.mprocs";
22+
description = "The mprocs package to use.";
23+
};
24+
25+
configFile = lib.mkOption {
26+
type = lib.types.path;
27+
internal = true;
28+
};
29+
30+
settings = lib.mkOption {
31+
type = settingsFormat.type;
32+
description = ''
33+
Top-level mprocs.yaml options
34+
35+
https://github.com/pvolok/mprocs?tab=readme-ov-file#config
36+
'';
37+
default = { };
38+
};
39+
};
40+
41+
config = lib.mkIf cfg.enable {
42+
process.manager.args = { "config" = cfg.configFile; };
43+
44+
process.manager.command = lib.mkDefault ''
45+
${cfg.package}/bin/mprocs \
46+
${lib.cli.toGNUCommandLineShell { } config.process.manager.args}
47+
'';
48+
49+
packages = [ cfg.package ] ++ lib.optionals pkgs.stdenv.isDarwin
50+
[ (makeImpurePackage "/usr/bin/pbcopy") ];
51+
52+
process.managers.mprocs = {
53+
configFile =
54+
lib.mkDefault (settingsFormat.generate "mprocs.yaml" cfg.settings);
55+
settings = {
56+
procs = lib.mapAttrs
57+
(name: value:
58+
let scriptPath = pkgs.writeShellScript name value.exec;
59+
in { cmd = [ "${scriptPath}" ]; })
60+
config.processes;
61+
};
62+
};
63+
};
64+
}

0 commit comments

Comments
 (0)