devtools/lib/modules/process_compose.nix

83 lines
2.2 KiB
Nix
Raw Normal View History

2025-12-19 15:04:26 +01:00
{
lib,
pkgs,
config,
...
}: let
inherit (lib) mkOption types;
2025-12-19 15:04:26 +01:00
in {
options.process-compose = mkOption {
type = types.attrsOf (types.submodule ({
config,
name,
...
}: {
options = {
alias = mkOption {
type = types.str;
default =
if name == "default"
then "pc"
else name;
description = ''
Alias for `process-compose`.
Defaults to `"pc"` if `${name}` is `"default"`
'';
};
lazy = mkOption {
type = types.bool;
default = true;
description = ''
Whether the process compose config should be built on-demand/lazily.
It will probably not land in the gcroot and thus might get cleaned up with every gc.
On the other hand, this way loading the devshell is faster. Decide for yourself :)
'';
};
config = mkOption {
type = types.attrs;
default = {};
description = ''
Configure process-compose here.
'';
};
configFile = mkOption {
internal = true;
type = types.package;
};
pcAlias = mkOption {
internal = true;
type = types.package;
};
2025-12-19 15:04:26 +01:00
};
config = rec {
configFile = (pkgs.formats.yaml {}).generate "process-compose.yaml" config.config;
pcAlias = pkgs.writeTextFile {
name = "pc-alias";
destination = "/bin/${config.alias}";
executable = true;
text = let
configScript =
if config.lazy
then
# sh
"$(nix build '${builtins.unsafeDiscardOutputDependency configFile.drvPath}^*' --no-link --print-out-paths)"
else configFile;
in
# sh
''
CONFIG_FILE="${configScript}"
${pkgs.process-compose}/bin/process-compose --config "$CONFIG_FILE" ''${@:1}
'';
};
};
}));
default = {};
description = ''
Define your process-compose instances here.
'';
2025-12-19 15:04:26 +01:00
};
config.packages = map (val: val.pcAlias) (builtins.attrValues config.process-compose);
2025-12-19 15:04:26 +01:00
}