mirror of
https://gitlab.com/rensa-nix/devtools.git
synced 2026-02-02 07:15:08 +01:00
refactor(modules)!: allow multiple instances for taskfile & process-compose
This commit is contained in:
parent
25fb9162ff
commit
5262901404
6 changed files with 199 additions and 134 deletions
|
|
@ -4,44 +4,79 @@
|
|||
config,
|
||||
...
|
||||
}: let
|
||||
inherit (lib) mkEnableOption mkOption mkIf types;
|
||||
cfg = config.process-compose;
|
||||
|
||||
configFile = (pkgs.formats.yaml {}).generate "process-compose.yaml" cfg.config;
|
||||
pcAlias = pkgs.writeTextFile {
|
||||
name = "pc-alias";
|
||||
destination = "/bin/${cfg.alias}";
|
||||
executable = true;
|
||||
text =
|
||||
# sh
|
||||
''
|
||||
${pkgs.process-compose}/bin/process-compose --config "${configFile}" ''${@:1}
|
||||
'';
|
||||
};
|
||||
inherit (lib) mkOption types;
|
||||
in {
|
||||
options.process-compose = {
|
||||
enable =
|
||||
mkEnableOption "Process-Compose"
|
||||
// {
|
||||
default = cfg.config != {};
|
||||
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;
|
||||
};
|
||||
};
|
||||
alias = mkOption {
|
||||
type = types.str;
|
||||
default = "pc";
|
||||
description = ''
|
||||
Alias for `process-compose`.
|
||||
'';
|
||||
};
|
||||
config = mkOption {
|
||||
type = types.attrs;
|
||||
default = {};
|
||||
description = ''
|
||||
Configure process-compose here.
|
||||
'';
|
||||
};
|
||||
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.
|
||||
'';
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
packages = [pcAlias];
|
||||
};
|
||||
config.packages = map (val: val.pcAlias) (builtins.attrValues config.process-compose);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue