diff --git a/docs/reference/options.md b/docs/reference/options.md index d1e457d10..58eab4774 100644 --- a/docs/reference/options.md +++ b/docs/reference/options.md @@ -34969,7 +34969,7 @@ lazy attribute set of (null or package) -## process.after +## process.manager.after @@ -34990,125 +34990,95 @@ strings concatenated with “\\n” -## process.before +## process.manager.args -Bash code to execute before starting processes. +Additional arguments to pass to the process manager. *Type:* -strings concatenated with “\\n” - - - -*Default:* -` "" ` +attribute set *Declared by:* - [https://github.com/cachix/devenv/blob/main/src/modules/processes.nix](https://github.com/cachix/devenv/blob/main/src/modules/processes.nix) -## process.implementation +## process.manager.before -The implementation used when performing ` devenv up `. +Bash code to execute before starting processes. *Type:* -one of “honcho”, “overmind”, “process-compose”, “hivemind” +strings concatenated with “\\n” *Default:* -` "process-compose" ` - - - -*Example:* -` "overmind" ` +` "" ` *Declared by:* - [https://github.com/cachix/devenv/blob/main/src/modules/processes.nix](https://github.com/cachix/devenv/blob/main/src/modules/processes.nix) -## process.process-compose +## process.manager.implementation -Top-level process-compose.yaml options when that implementation is used. +The process manager to use when running processes with ` devenv up `. *Type:* -attribute set +one of “hivemind”, “honcho”, “overmind”, “process-compose” *Default:* - -``` -{ - version = "0.5"; - unix-socket = "${config.devenv.runtime}/pc.sock"; - tui = true; -} - -``` +` "process-compose" ` *Example:* - -``` -{ - log_level = "fatal"; - log_location = "/path/to/combined/output/logfile.log"; - version = "0.5"; -} -``` +` "overmind" ` *Declared by:* - [https://github.com/cachix/devenv/blob/main/src/modules/processes.nix](https://github.com/cachix/devenv/blob/main/src/modules/processes.nix) -## process-managers.hivemind.enable +## process.managers.hivemind.package -Whether to enable hivemind as process-manager. +The hivemind package to use. *Type:* -boolean +package *Default:* -` false ` - - - -*Example:* -` true ` +` pkgs.hivemind ` *Declared by:* - [https://github.com/cachix/devenv/blob/main/src/modules/process-managers/hivemind.nix](https://github.com/cachix/devenv/blob/main/src/modules/process-managers/hivemind.nix) -## process-managers.hivemind.package +## process.managers.honcho.package -The hivemind package to use. +The honcho package to use. @@ -35118,44 +35088,39 @@ package *Default:* -` pkgs.hivemind ` +` pkgs.honcho ` *Declared by:* - - [https://github.com/cachix/devenv/blob/main/src/modules/process-managers/hivemind.nix](https://github.com/cachix/devenv/blob/main/src/modules/process-managers/hivemind.nix) + - [https://github.com/cachix/devenv/blob/main/src/modules/process-managers/honcho.nix](https://github.com/cachix/devenv/blob/main/src/modules/process-managers/honcho.nix) -## process-managers.honcho.enable +## process.managers.overmind.package -Whether to enable honcho as process-manager. +The overmind package to use. *Type:* -boolean +package *Default:* -` false ` - - - -*Example:* -` true ` +` pkgs.overmind ` *Declared by:* - - [https://github.com/cachix/devenv/blob/main/src/modules/process-managers/honcho.nix](https://github.com/cachix/devenv/blob/main/src/modules/process-managers/honcho.nix) + - [https://github.com/cachix/devenv/blob/main/src/modules/process-managers/overmind.nix](https://github.com/cachix/devenv/blob/main/src/modules/process-managers/overmind.nix) -## process-managers.honcho.package +## process.managers.process-compose.package -The honcho package to use. +The process-compose package to use. @@ -35165,65 +35130,86 @@ package *Default:* -` pkgs.honcho ` +` pkgs.process-compose ` *Declared by:* - - [https://github.com/cachix/devenv/blob/main/src/modules/process-managers/honcho.nix](https://github.com/cachix/devenv/blob/main/src/modules/process-managers/honcho.nix) + - [https://github.com/cachix/devenv/blob/main/src/modules/process-managers/process-compose.nix](https://github.com/cachix/devenv/blob/main/src/modules/process-managers/process-compose.nix) -## process-managers.overmind.enable +## process.managers.process-compose.port -Whether to enable overmind as process-manager. +The port to bind the process-compose server to. + +Not used when ` unixSocket.enable ` is true. *Type:* -boolean +signed integer *Default:* -` false ` - - - -*Example:* -` true ` +` 8080 ` *Declared by:* - - [https://github.com/cachix/devenv/blob/main/src/modules/process-managers/overmind.nix](https://github.com/cachix/devenv/blob/main/src/modules/process-managers/overmind.nix) + - [https://github.com/cachix/devenv/blob/main/src/modules/process-managers/process-compose.nix](https://github.com/cachix/devenv/blob/main/src/modules/process-managers/process-compose.nix) -## process-managers.overmind.package +## process.managers.process-compose.settings -The overmind package to use. +Top-level process-compose.yaml options + +Example: https://github.com/F1bonacc1/process-compose/blob/main/process-compose.yaml\` *Type:* -package +YAML value *Default:* -` pkgs.overmind ` +` { } ` + + + +*Example:* + +``` +{ + availability = { + backoff_seconds = 2; + max_restarts = 5; + restart = "on_failure"; + }; + depends_on = { + some-other-process = { + condition = "process_completed_successfully"; + }; + }; + environment = [ + "ENVVAR_FOR_THIS_PROCESS_ONLY=foobar" + ]; +} +``` *Declared by:* - - [https://github.com/cachix/devenv/blob/main/src/modules/process-managers/overmind.nix](https://github.com/cachix/devenv/blob/main/src/modules/process-managers/overmind.nix) + - [https://github.com/cachix/devenv/blob/main/src/modules/process-managers/process-compose.nix](https://github.com/cachix/devenv/blob/main/src/modules/process-managers/process-compose.nix) -## process-managers.process-compose.enable +## process.managers.process-compose.tui.enable -Whether to enable process-compose as process-manager. +Enable the TUI (Terminal User Interface) @@ -35233,11 +35219,6 @@ boolean *Default:* -` false ` - - - -*Example:* ` true ` *Declared by:* @@ -35245,66 +35226,47 @@ boolean -## process-managers.process-compose.package +## process.managers.process-compose.unixSocket.enable -The process-compose package to use. +Whether to enable running the process-compose server over unix domain sockets instead of tcp. *Type:* -package +boolean *Default:* -` pkgs.process-compose ` +` true ` + + + +*Example:* +` true ` *Declared by:* - [https://github.com/cachix/devenv/blob/main/src/modules/process-managers/process-compose.nix](https://github.com/cachix/devenv/blob/main/src/modules/process-managers/process-compose.nix) -## process-managers.process-compose.settings +## process.managers.process-compose.unixSocket.path -process-compose.yaml specific process attributes. - -Example: https://github.com/F1bonacc1/process-compose/blob/main/process-compose.yaml\` +Override the path to the unix socket. *Type:* -YAML value +string *Default:* -` { } ` - - - -*Example:* - -``` -{ - availability = { - backoff_seconds = 2; - max_restarts = 5; - restart = "on_failure"; - }; - depends_on = { - some-other-process = { - condition = "process_completed_successfully"; - }; - }; - environment = [ - "ENVVAR_FOR_THIS_PROCESS_ONLY=foobar" - ]; -} -``` +` ${config.devenv.runtime}/pc.sock ` *Declared by:* - [https://github.com/cachix/devenv/blob/main/src/modules/process-managers/process-compose.nix](https://github.com/cachix/devenv/blob/main/src/modules/process-managers/process-compose.nix) @@ -35315,7 +35277,7 @@ YAML value -Processes can be started with ` devenv up ` and run in foreground mode. +Processes can be started with ` devenv up ` and run in the foreground. @@ -35356,7 +35318,7 @@ process-compose.yaml specific process attributes. Example: https://github.com/F1bonacc1/process-compose/blob/main/process-compose.yaml\` -Only used when using ` process.implementation = "process-compose"; ` +Only used when using ` process.manager.implementation = "process-compose"; ` diff --git a/docs/supported-process-managers/hivemind.md b/docs/supported-process-managers/hivemind.md index a47fabeca..22002682e 100644 --- a/docs/supported-process-managers/hivemind.md +++ b/docs/supported-process-managers/hivemind.md @@ -3,30 +3,7 @@ [comment]: # (Please add your documentation on top of this line) -## process-managers\.hivemind\.enable - -Whether to enable hivemind as process-manager\. - - - -*Type:* -boolean - - - -*Default:* -` false ` - - - -*Example:* -` true ` - - - -## process-managers\.hivemind\.package - - +## process\.managers\.hivemind\.package The hivemind package to use\. diff --git a/docs/supported-process-managers/honcho.md b/docs/supported-process-managers/honcho.md index dc6d2b690..f5832f9d6 100644 --- a/docs/supported-process-managers/honcho.md +++ b/docs/supported-process-managers/honcho.md @@ -3,30 +3,7 @@ [comment]: # (Please add your documentation on top of this line) -## process-managers\.honcho\.enable - -Whether to enable honcho as process-manager\. - - - -*Type:* -boolean - - - -*Default:* -` false ` - - - -*Example:* -` true ` - - - -## process-managers\.honcho\.package - - +## process\.managers\.honcho\.package The honcho package to use\. diff --git a/docs/supported-process-managers/overmind.md b/docs/supported-process-managers/overmind.md index a59e792d4..0001de686 100644 --- a/docs/supported-process-managers/overmind.md +++ b/docs/supported-process-managers/overmind.md @@ -3,30 +3,7 @@ [comment]: # (Please add your documentation on top of this line) -## process-managers\.overmind\.enable - -Whether to enable overmind as process-manager\. - - - -*Type:* -boolean - - - -*Default:* -` false ` - - - -*Example:* -` true ` - - - -## process-managers\.overmind\.package - - +## process\.managers\.overmind\.package The overmind package to use\. diff --git a/docs/supported-process-managers/process-compose.md b/docs/supported-process-managers/process-compose.md index 221149741..6df390ea8 100644 --- a/docs/supported-process-managers/process-compose.md +++ b/docs/supported-process-managers/process-compose.md @@ -3,50 +3,47 @@ [comment]: # (Please add your documentation on top of this line) -## process-managers\.process-compose\.enable +## process\.managers\.process-compose\.package -Whether to enable process-compose as process-manager\. +The process-compose package to use\. *Type:* -boolean +package *Default:* -` false ` - - +` pkgs.process-compose ` -*Example:* -` true ` +## process\.managers\.process-compose\.port -## process-managers\.process-compose\.package +The port to bind the process-compose server to\. -The process-compose package to use\. +Not used when ` unixSocket.enable ` is true\. *Type:* -package +signed integer *Default:* -` pkgs.process-compose ` +` 8080 ` -## process-managers\.process-compose\.settings +## process\.managers\.process-compose\.settings -process-compose\.yaml specific process attributes\. +Top-level process-compose\.yaml options Example: https://github\.com/F1bonacc1/process-compose/blob/main/process-compose\.yaml\` @@ -81,3 +78,62 @@ YAML value ]; } ``` + + + +## process\.managers\.process-compose\.tui\.enable + + + +Enable the TUI (Terminal User Interface) + + + +*Type:* +boolean + + + +*Default:* +` true ` + + + +## process\.managers\.process-compose\.unixSocket\.enable + + + +Whether to enable running the process-compose server over unix domain sockets instead of tcp\. + + + +*Type:* +boolean + + + +*Default:* +` true ` + + + +*Example:* +` true ` + + + +## process\.managers\.process-compose\.unixSocket\.path + + + +Override the path to the unix socket\. + + + +*Type:* +string + + + +*Default:* +` ${config.devenv.runtime}/pc.sock ` diff --git a/flake.nix b/flake.nix index 7df94906b..5c571ec63 100644 --- a/flake.nix +++ b/flake.nix @@ -109,62 +109,61 @@ inherit (pkgs) lib; languageOptions = builtins.mapAttrs (key: _: generateKeyOptions key) evaluatedModules.config.languages; serviceOptions = builtins.mapAttrs (key: _: generateKeyOptions key) evaluatedModules.config.services; - processManagersOptions = builtins.mapAttrs (key: _: generateKeyOptions key) evaluatedModules.config.process-managers; + processManagersOptions = builtins.mapAttrs (key: _: generateKeyOptions key) evaluatedModules.config.process.managers; processedOptions = option: builtins.mapAttrs (key: options: optionsDocs options) option; in pkgs.stdenv.mkDerivation { name = "generate-individual-docs"; src = ./docs/individual-docs; buildPhase = '' - languageDir=./languages - serviceDir=./services - processManagerDir=./process-managers - mkdir -p $out/docs/individual-docs/supported-languages - mkdir -p $out/docs/individual-docs/supported-services - mkdir -p $out/docs/individual-docs/supported-process-managers - AUTOGEN_NOTICE="[comment]: # (Do not edit this file as it is autogenerated. Go to docs/individual-docs if you want to make edits.)" + languageDir=./languages + serviceDir=./services + processManagerDir=./process-managers + mkdir -p $out/docs/individual-docs/supported-languages + mkdir -p $out/docs/individual-docs/supported-services + mkdir -p $out/docs/individual-docs/supported-process-managers + AUTOGEN_NOTICE="[comment]: # (Do not edit this file as it is autogenerated. Go to docs/individual-docs if you want to make edits.)" - ${lib.concatStringsSep "\n" (lib.mapAttrsToList (key: options: '' - content=$(cat ${options.optionsCommonMark}) - file=$languageDir/${key}.md + ${lib.concatStringsSep "\n" (lib.mapAttrsToList (key: options: '' + content=$(cat ${options.optionsCommonMark}) + file=$languageDir/${key}.md - sed -i "1i$AUTOGEN_NOTICE" "$file" - substituteInPlace $file \ - --subst-var-by \ - AUTOGEN_OPTIONS \ - "$content" + sed -i "1i$AUTOGEN_NOTICE" "$file" + substituteInPlace $file \ + --subst-var-by \ + AUTOGEN_OPTIONS \ + "$content" - cp $file $out/docs/individual-docs/supported-languages/${key}.md + cp $file $out/docs/individual-docs/supported-languages/${key}.md - '') ( processedOptions languageOptions ))} + '') ( processedOptions languageOptions ))} ${lib.concatStringsSep "\n" (lib.mapAttrsToList (key: options: '' - content=$(cat ${options.optionsCommonMark}) - file=$serviceDir/${key}.md + content=$(cat ${options.optionsCommonMark}) + file=$serviceDir/${key}.md - sed -i "1i$AUTOGEN_NOTICE" "$file" - substituteInPlace $file \ - --subst-var-by \ - AUTOGEN_OPTIONS \ - "$content" + sed -i "1i$AUTOGEN_NOTICE" "$file" + substituteInPlace $file \ + --subst-var-by \ + AUTOGEN_OPTIONS \ + "$content" - cp $file $out/docs/individual-docs/supported-services/${key}.md + cp $file $out/docs/individual-docs/supported-services/${key}.md - '') ( processedOptions serviceOptions ))} + '') ( processedOptions serviceOptions ))} ${lib.concatStringsSep "\n" (lib.mapAttrsToList (key: options: '' - content=$(cat ${options.optionsCommonMark}) - file=$processManagerDir/${key}.md - - sed -i "1i$AUTOGEN_NOTICE" "$file" - substituteInPlace $file \ - --subst-var-by \ - AUTOGEN_OPTIONS \ - "$content" + content=$(cat ${options.optionsCommonMark}) + file=$processManagerDir/${key}.md - cp $file $out/docs/individual-docs/supported-process-managers/${key}.md - '') ( processedOptions processManagersOptions))} + sed -i "1i$AUTOGEN_NOTICE" "$file" + substituteInPlace $file \ + --subst-var-by \ + AUTOGEN_OPTIONS \ + "$content" + cp $file $out/docs/individual-docs/supported-process-managers/${key}.md + '') ( processedOptions processManagersOptions))} ''; }; }); diff --git a/src/modules/integrations/hostctl.nix b/src/modules/integrations/hostctl.nix index 66e2bdc2b..4fdfcac8d 100644 --- a/src/modules/integrations/hostctl.nix +++ b/src/modules/integrations/hostctl.nix @@ -36,7 +36,7 @@ in }; config = lib.mkIf (hostContent != "") { - process.before = '' + process.manager.before = '' if [[ ! -f "$DEVENV_STATE/hostctl" || "$(cat "$DEVENV_STATE/hostctl")" != "${hostHash}" ]]; then sudo ${pkgs.hostctl}/bin/hostctl replace ${config.hostsProfileName} --from ${file} mkdir -p "$DEVENV_STATE" @@ -44,7 +44,7 @@ in fi ''; - process.after = '' + process.manager.after = '' rm -f "$DEVENV_STATE/hostctl" sudo ${pkgs.hostctl}/bin/hostctl remove ${config.hostsProfileName} ''; diff --git a/src/modules/integrations/mkcert.nix b/src/modules/integrations/mkcert.nix index f52dcdc6d..55c054a9a 100644 --- a/src/modules/integrations/mkcert.nix +++ b/src/modules/integrations/mkcert.nix @@ -18,7 +18,7 @@ in }; config = lib.mkIf (domainList != "") { - process.before = '' + process.manager.before = '' mkdir -p "${config.env.DEVENV_STATE}/mkcert" if [[ ! -f "$DEVENV_STATE/mkcert/rootCA.pem" ]]; then diff --git a/src/modules/process-managers/hivemind.nix b/src/modules/process-managers/hivemind.nix index e285cb7eb..02f447ef6 100644 --- a/src/modules/process-managers/hivemind.nix +++ b/src/modules/process-managers/hivemind.nix @@ -1,10 +1,13 @@ { pkgs, config, lib, ... }: let - cfg = config.process-managers.hivemind; + cfg = config.process.managers.hivemind; in { - options.process-managers.hivemind = { - enable = lib.mkEnableOption "hivemind as process-manager"; + options.process.managers.hivemind = { + enable = lib.mkEnableOption "hivemind as the process manager" // { + internal = true; + }; + package = lib.mkOption { type = lib.types.package; default = pkgs.hivemind; @@ -12,9 +15,16 @@ in description = "The hivemind package to use."; }; }; + config = lib.mkIf cfg.enable { - processManagerCommand = '' - ${cfg.package}/bin/hivemind --print-timestamps "$@" ${config.procfile} & + process.manager.args = { + "print-timestamps" = true; + }; + + process.manager.command = lib.mkDefault '' + ${cfg.package}/bin/hivemind \ + ${lib.cli.toGNUCommandLineShell {} config.process.manager.args} \ + "$@" ${config.procfile} & ''; packages = [ cfg.package ]; diff --git a/src/modules/process-managers/honcho.nix b/src/modules/process-managers/honcho.nix index de88d8070..cb59accd9 100644 --- a/src/modules/process-managers/honcho.nix +++ b/src/modules/process-managers/honcho.nix @@ -1,10 +1,13 @@ { pkgs, config, lib, ... }: let - cfg = config.process-managers.honcho; + cfg = config.process.managers.honcho; in { - options.process-managers.honcho = { - enable = lib.mkEnableOption "honcho as process-manager"; + options.process.managers.honcho = { + enable = lib.mkEnableOption "honcho as the process manager" // { + internal = true; + }; + package = lib.mkOption { type = lib.types.package; default = pkgs.honcho; @@ -12,9 +15,17 @@ in description = "The honcho package to use."; }; }; + config = lib.mkIf cfg.enable { - processManagerCommand = '' - ${cfg.package}/bin/honcho start -f ${config.procfile} --env ${config.procfileEnv} "$@" & + process.manager.args = { + "f" = config.procfile; + "env" = config.procfileEnv; + }; + + process.manager.command = lib.mkDefault '' + ${cfg.package}/bin/honcho start \ + ${lib.cli.toGNUCommandLineShell {} config.process.manager.args} \ + "$@" & ''; packages = [ cfg.package ]; diff --git a/src/modules/process-managers/overmind.nix b/src/modules/process-managers/overmind.nix index 63a7015b5..7679658ba 100644 --- a/src/modules/process-managers/overmind.nix +++ b/src/modules/process-managers/overmind.nix @@ -1,10 +1,13 @@ { pkgs, config, lib, ... }: let - cfg = config.process-managers.overmind; + cfg = config.process.managers.overmind; in { - options.process-managers.overmind = { - enable = lib.mkEnableOption "overmind as process-manager"; + options.process.managers.overmind = { + enable = lib.mkEnableOption "overmind as the process manager" // { + internal = true; + }; + package = lib.mkOption { type = lib.types.package; default = pkgs.overmind; @@ -12,12 +15,18 @@ in description = "The overmind package to use."; }; }; + config = lib.mkIf cfg.enable { - processManagerCommand = '' + process.manager.args = { + "root" = config.env.DEVENV_ROOT; + "socket" = "${config.devenv.runtime}/overmind.sock"; + "procfile" = config.procfile; + }; + + process.manager.command = lib.mkDefault '' OVERMIND_ENV=${config.procfileEnv} ${cfg.package}/bin/overmind start \ - --root ${config.env.DEVENV_ROOT} \ - --socket ${config.devenv.runtime}/overmind.sock \ - --procfile ${config.procfile} "$@" & + ${lib.cli.toGNUCommandLineShell {} config.process.manager.args} \ + "$@" & ''; packages = [ cfg.package ]; diff --git a/src/modules/process-managers/process-compose.nix b/src/modules/process-managers/process-compose.nix index 181b99fff..97c6d7a44 100644 --- a/src/modules/process-managers/process-compose.nix +++ b/src/modules/process-managers/process-compose.nix @@ -1,29 +1,65 @@ { pkgs, config, lib, ... }: let - cfg = config.process-managers.process-compose; + cfg = config.process.managers.process-compose; settingsFormat = pkgs.formats.yaml { }; in { - options.process-managers.process-compose = { - enable = lib.mkEnableOption "process-compose as process-manager"; + options.process.managers.process-compose = { + enable = lib.mkEnableOption "process-compose as the process manager" // { + internal = true; + }; + package = lib.mkOption { type = lib.types.package; default = pkgs.process-compose; defaultText = lib.literalExpression "pkgs.process-compose"; description = "The process-compose package to use."; }; + + port = lib.mkOption { + type = lib.types.int; + default = 8080; + description = '' + The port to bind the process-compose server to. + + Not used when `unixSocket.enable` is true. + ''; + }; + + unixSocket = { + enable = lib.mkEnableOption "running the process-compose server over unix domain sockets instead of tcp" // { + default = true; + }; + + path = lib.mkOption { + type = lib.types.str; + default = "${config.devenv.runtime}/pc.sock"; + defaultText = lib.literalExpression "\${config.devenv.runtime}/pc.sock"; + description = "Override the path to the unix socket."; + }; + }; + + tui = { + enable = lib.mkOption { + type = lib.types.bool; + default = true; + description = "Enable the TUI (Terminal User Interface)"; + }; + }; + configFile = lib.mkOption { type = lib.types.path; internal = true; }; + settings = lib.mkOption { type = settingsFormat.type; - default = { }; description = '' - process-compose.yaml specific process attributes. + Top-level process-compose.yaml options Example: https://github.com/F1bonacc1/process-compose/blob/main/process-compose.yaml` ''; + default = { }; example = { environment = [ "ENVVAR_FOR_THIS_PROCESS_ONLY=foobar" ]; availability = { @@ -36,23 +72,32 @@ in }; }; }; + config = lib.mkIf cfg.enable { - processManagerCommand = '' - ${cfg.package}/bin/process-compose --config ${cfg.configFile} \ - --unix-socket ''${PC_SOCKET_PATH:-${toString config.process.process-compose.unix-socket}} \ - --tui=''${PC_TUI_ENABLED:-${lib.boolToString config.process.process-compose.tui}} \ - -U up "$@" & + process.manager.args = { + "config" = cfg.configFile; + "port" = if !cfg.unixSocket.enable then toString cfg.port else null; + "unix-socket" = + if cfg.unixSocket.enable + then cfg.unixSocket.path + else null; + # TODO: move -t (for tui) here. We need a newer nixpkgs for optionValueSeparator = "=". + }; + + process.manager.command = lib.mkDefault '' + ${cfg.package}/bin/process-compose \ + ${lib.cli.toGNUCommandLineShell { } config.process.manager.args} \ + -t="''${PC_TUI_ENABLED:-${lib.boolToString cfg.tui.enable}}" \ + up "$@" & ''; packages = [ cfg.package ]; - process-managers.process-compose = { - configFile = settingsFormat.generate "process-compose.yaml" cfg.settings; + process.managers.process-compose = { + configFile = lib.mkDefault (settingsFormat.generate "process-compose.yaml" cfg.settings); settings = { - version = "0.5"; - is_strict = true; - port = lib.mkDefault 9999; - tui = lib.mkDefault true; + version = lib.mkDefault "0.5"; + is_strict = lib.mkDefault true; environment = lib.mapAttrsToList (name: value: "${name}=${toString value}") config.env; @@ -70,6 +115,5 @@ in config.processes; }; }; - }; } diff --git a/src/modules/processes.nix b/src/modules/processes.nix index 8ae805566..63560d4ce 100644 --- a/src/modules/processes.nix +++ b/src/modules/processes.nix @@ -1,6 +1,7 @@ -{ config, lib, pkgs, ... }: +{ config, options, lib, pkgs, ... }: let types = lib.types; + processType = types.submodule ({ config, ... }: { options = { exec = lib.mkOption { @@ -8,7 +9,6 @@ let description = "Bash code to run the process."; }; - # TODO: Deprecate this option in favor of `process-managers.process-compose.settings.processes.${name}`. process-compose = lib.mkOption { type = types.attrs; # TODO: type this explicitly? default = { }; @@ -17,7 +17,7 @@ let Example: https://github.com/F1bonacc1/process-compose/blob/main/process-compose.yaml` - Only used when using ``process.implementation = "process-compose";`` + Only used when using ``process.manager.implementation = "process-compose";`` ''; example = { environment = [ "ENVVAR_FOR_THIS_PROCESS_ONLY=foobar" ]; @@ -33,55 +33,40 @@ let }; }); - implementation = config.process.implementation; + supportedImplementations = builtins.attrNames options.process.managers; + + implementation = config.process.manager.implementation; envList = lib.mapAttrsToList (name: value: "${name}=${builtins.toJSON value}") config.env; in { + imports = + (map (name: lib.mkRenamedOptionModule [ "process" name ] [ "process" "manager" name ]) [ "after" "before" "implementation" ]) + ++ [ + (lib.mkRenamedOptionModule [ "process" "process-compose" "tui" ] [ "process" "managers" "process-compose" "tui" "enable" ]) + (lib.mkRenamedOptionModule [ "process" "process-compose" "unix-socket" ] [ "process" "managers" "process-compose" "unixSocket" "path" ]) + (lib.mkRenamedOptionModule [ "processManagerCommand" ] [ "process" "manager" "command" ]) + (lib.mkRenamedOptionModule [ "process-managers" ] [ "process" "managers" ]) + ]; + options = { processes = lib.mkOption { type = types.attrsOf processType; default = { }; description = - "Processes can be started with ``devenv up`` and run in foreground mode."; + "Processes can be started with ``devenv up`` and run in the foreground."; }; - # TODO: Rename this from `process.${option}` to `process-manager.${option}` or `devenv.up.${option}`. - process = { + process.manager = { implementation = lib.mkOption { - type = types.enum [ "honcho" "overmind" "process-compose" "hivemind" ]; - description = "The implementation used when performing ``devenv up``."; + type = types.enum supportedImplementations; + description = "The process manager to use when running processes with ``devenv up``."; default = "process-compose"; example = "overmind"; }; - process-compose = lib.mkOption { - # NOTE: https://github.com/F1bonacc1/process-compose/blob/1c706e7c300df2455de7a9b259dd35dea845dcf3/src/app/config.go#L11-L16 - type = types.attrs; - description = '' - Top-level process-compose.yaml options when that implementation is used. - ''; - default = { - version = "0.5"; - unix-socket = "${config.devenv.runtime}/pc.sock"; - tui = true; - }; - defaultText = lib.literalExpression '' - { - version = "0.5"; - unix-socket = "''${config.devenv.runtime}/pc.sock"; - tui = true; - } - ''; - example = { - version = "0.5"; - log_location = "/path/to/combined/output/logfile.log"; - log_level = "fatal"; - }; - }; - before = lib.mkOption { type = types.lines; description = "Bash code to execute before starting processes."; @@ -93,17 +78,27 @@ in description = "Bash code to execute after stopping processes."; default = ""; }; + + command = lib.mkOption { + type = types.str; + internal = true; + description = '' + The command to run the process manager. + + This is meant to be set by the process.manager.''${implementation}. + If overriding this, ``process.manager.args`` will not be applied. + ''; + }; + + args = lib.mkOption { + type = types.attrs; + description = '' + Additional arguments to pass to the process manager. + ''; + }; }; # INTERNAL - # TODO: Rename these to `process-manager.${option}` - processManagerCommand = lib.mkOption { - type = types.str; - internal = true; - description = '' - The command to run the process-manager. This is meant to be set by the process-manager.''${implementation}. - ''; - }; procfile = lib.mkOption { type = types.package; @@ -111,8 +106,8 @@ in }; procfileEnv = lib.mkOption { - internal = true; type = types.package; + internal = true; }; procfileScript = lib.mkOption { @@ -123,7 +118,22 @@ in }; config = lib.mkIf (config.processes != { }) { - process-managers.${implementation}.enable = lib.mkDefault true; + assertions = [{ + assertion = + let + enabledImplementations = + lib.pipe supportedImplementations [ + (map (name: config.process.managers.${name}.enable)) + (lib.filter lib.id) + ]; + in + lib.length enabledImplementations == 1; + message = '' + Only a single process manager can be enabled at a time. + ''; + }]; + + process.managers.${implementation}.enable = lib.mkDefault true; procfile = pkgs.writeText "procfile" (lib.concatStringsSep "\n" @@ -134,9 +144,9 @@ in pkgs.writeText "procfile-env" (lib.concatStringsSep "\n" envList); procfileScript = pkgs.writeShellScript "devenv-up" '' - ${config.process.before} + ${config.process.manager.before} - ${config.processManagerCommand} + ${config.process.manager.command} backgroundPID=$! @@ -144,7 +154,7 @@ in echo "Stopping processes..." kill -TERM $backgroundPID wait $backgroundPID - ${config.process.after} + ${config.process.manager.after} echo "Processes stopped." }