From d4849ed55989df12fb706f2282f536986666ad1b Mon Sep 17 00:00:00 2001 From: Sander Date: Mon, 2 Sep 2024 14:00:36 +0000 Subject: [PATCH 01/21] process: run process.after on exit --- src/modules/processes.nix | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/modules/processes.nix b/src/modules/processes.nix index 8ae805566..1c61e9b21 100644 --- a/src/modules/processes.nix +++ b/src/modules/processes.nix @@ -142,13 +142,13 @@ in down() { echo "Stopping processes..." - kill -TERM $backgroundPID - wait $backgroundPID ${config.process.after} + kill -TERM $backgroundPID &> /dev/null || true + wait $backgroundPID &> /dev/null || true echo "Processes stopped." } - trap down SIGINT SIGTERM + trap down EXIT wait ''; From bfc6f2863d55af481bc12fb38464ccc0f9320ebf Mon Sep 17 00:00:00 2001 From: Sander Date: Mon, 2 Sep 2024 14:01:56 +0000 Subject: [PATCH 02/21] process: fixup and migrate process.manager and process-compose settings --- src/modules/integrations/hostctl.nix | 4 +- src/modules/integrations/mkcert.nix | 2 +- src/modules/process-managers/hivemind.nix | 19 +++- src/modules/process-managers/honcho.nix | 20 +++- src/modules/process-managers/overmind.nix | 22 ++++- .../process-managers/process-compose.nix | 65 ++++++++++--- src/modules/processes.nix | 92 ++++++++++--------- 7 files changed, 154 insertions(+), 70 deletions(-) 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..5137404d0 100644 --- a/src/modules/process-managers/hivemind.nix +++ b/src/modules/process-managers/hivemind.nix @@ -4,7 +4,13 @@ let in { options.process-managers.hivemind = { - enable = lib.mkEnableOption "hivemind as process-manager"; + enable = lib.mkOption { + type = lib.types.bool; + internal = true; + default = false; + description = "Whether to use hivemind as the process manager"; + }; + package = lib.mkOption { type = lib.types.package; default = pkgs.hivemind; @@ -12,9 +18,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.concatStringsSep " " (lib.cli.toGNUCommandLine {} 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..7c1eda348 100644 --- a/src/modules/process-managers/honcho.nix +++ b/src/modules/process-managers/honcho.nix @@ -4,7 +4,13 @@ let in { options.process-managers.honcho = { - enable = lib.mkEnableOption "honcho as process-manager"; + enable = lib.mkOption { + type = lib.types.bool; + internal = true; + default = false; + description = "Whether to use honcho as the process manager"; + }; + package = lib.mkOption { type = lib.types.package; default = pkgs.honcho; @@ -12,9 +18,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.concatStringsSep " " (lib.cli.toGNUCommandLine {} 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..6b4e301bb 100644 --- a/src/modules/process-managers/overmind.nix +++ b/src/modules/process-managers/overmind.nix @@ -4,7 +4,13 @@ let in { options.process-managers.overmind = { - enable = lib.mkEnableOption "overmind as process-manager"; + enable = lib.mkOption { + type = lib.types.bool; + internal = true; + default = false; + description = "Whether to use overmind as the process manager"; + }; + package = lib.mkOption { type = lib.types.package; default = pkgs.overmind; @@ -12,12 +18,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.concatStringsSep " " (lib.cli.toGNUCommandLine {} 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..009bdcfc0 100644 --- a/src/modules/process-managers/process-compose.nix +++ b/src/modules/process-managers/process-compose.nix @@ -4,26 +4,63 @@ let settingsFormat = pkgs.formats.yaml { }; in { + imports = [ + (lib.mkRenamedOptionModule [ "process-managers" "process-compose" "settings" "port" ] [ "process-managers" "process-compose" "port" ]) + (lib.mkRenamedOptionModule [ "process-managers" "process-compose" "settings" "tui" ] [ "process-managers" "process-compose" "tui" "enable" ]) + ]; + options.process-managers.process-compose = { - enable = lib.mkEnableOption "process-compose as process-manager"; + enable = lib.mkOption { + type = lib.types.bool; + internal = true; + default = false; + description = "Whether to use process-compose as the process manager"; + }; + 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; + }; + + unixSocket = { + enable = lib.mkEnableOption "unix domain sockets instead of tcp"; + + path = lib.mkOption { + type = lib.types.nullOr 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"; + }; + }; + 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 +73,28 @@ 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; + "U" = cfg.unixSocket.enable; + "unix-socket" = "\${PC_SOCKET_PATH:-${toString cfg.unixSocket.path}}"; + "tui" = "\${PC_TUI_ENABLED:-${lib.boolToString cfg.tui.enable}}"; + }; + + process.manager.command = lib.mkDefault '' + ${cfg.package}/bin/process-compose \ + ${lib.concatStringsSep " " (lib.cli.toGNUCommandLine {} config.process.manager.args)} \ + up "$@" & ''; packages = [ cfg.package ]; process-managers.process-compose = { - configFile = settingsFormat.generate "process-compose.yaml" cfg.settings; + 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; environment = lib.mapAttrsToList (name: value: "${name}=${toString value}") config.env; @@ -70,6 +112,5 @@ in config.processes; }; }; - }; } diff --git a/src/modules/processes.nix b/src/modules/processes.nix index 1c61e9b21..96b7490f7 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 = { }; @@ -33,55 +33,37 @@ 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 = [ + (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" ]) + ]; + 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 +75,24 @@ 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}. + ''; + }; + + args = lib.mkOption { + type = types.attrsOf types.str; + 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; @@ -123,6 +112,21 @@ in }; config = lib.mkIf (config.processes != { }) { + 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 = @@ -134,17 +138,17 @@ 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=$! down() { echo "Stopping processes..." - ${config.process.after} kill -TERM $backgroundPID &> /dev/null || true wait $backgroundPID &> /dev/null || true + ${config.process.manager.after} echo "Processes stopped." } From bfb9c51fd6615e12f68e8a290dd016580c97796a Mon Sep 17 00:00:00 2001 From: Sander Date: Mon, 2 Sep 2024 14:17:50 +0000 Subject: [PATCH 03/21] process-compose: remove unused migrations --- src/modules/process-managers/process-compose.nix | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/modules/process-managers/process-compose.nix b/src/modules/process-managers/process-compose.nix index 009bdcfc0..7f3904936 100644 --- a/src/modules/process-managers/process-compose.nix +++ b/src/modules/process-managers/process-compose.nix @@ -4,11 +4,6 @@ let settingsFormat = pkgs.formats.yaml { }; in { - imports = [ - (lib.mkRenamedOptionModule [ "process-managers" "process-compose" "settings" "port" ] [ "process-managers" "process-compose" "port" ]) - (lib.mkRenamedOptionModule [ "process-managers" "process-compose" "settings" "tui" ] [ "process-managers" "process-compose" "tui" "enable" ]) - ]; - options.process-managers.process-compose = { enable = lib.mkOption { type = lib.types.bool; From ac1df56b8b8b51904e401e9841aa33016c552a2b Mon Sep 17 00:00:00 2001 From: Sander Date: Mon, 2 Sep 2024 14:23:08 +0000 Subject: [PATCH 04/21] process: fix process.manager.args type --- src/modules/processes.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/processes.nix b/src/modules/processes.nix index 96b7490f7..72b20acdc 100644 --- a/src/modules/processes.nix +++ b/src/modules/processes.nix @@ -85,7 +85,7 @@ in }; args = lib.mkOption { - type = types.attrsOf types.str; + type = types.attrs; description = '' Additional arguments to pass to the process manager. ''; From 86a488151f602764b6422ccfef61d2be2b0f5b97 Mon Sep 17 00:00:00 2001 From: Sander Date: Mon, 2 Sep 2024 14:34:29 +0000 Subject: [PATCH 05/21] chore: simplify process-manager enable options --- src/modules/process-managers/hivemind.nix | 5 +---- src/modules/process-managers/honcho.nix | 5 +---- src/modules/process-managers/overmind.nix | 5 +---- src/modules/process-managers/process-compose.nix | 5 +---- 4 files changed, 4 insertions(+), 16 deletions(-) diff --git a/src/modules/process-managers/hivemind.nix b/src/modules/process-managers/hivemind.nix index 5137404d0..b231542e8 100644 --- a/src/modules/process-managers/hivemind.nix +++ b/src/modules/process-managers/hivemind.nix @@ -4,11 +4,8 @@ let in { options.process-managers.hivemind = { - enable = lib.mkOption { - type = lib.types.bool; + enable = lib.mkEnableOption "hivemind as the process manager" // { internal = true; - default = false; - description = "Whether to use hivemind as the process manager"; }; package = lib.mkOption { diff --git a/src/modules/process-managers/honcho.nix b/src/modules/process-managers/honcho.nix index 7c1eda348..d33fd27c7 100644 --- a/src/modules/process-managers/honcho.nix +++ b/src/modules/process-managers/honcho.nix @@ -4,11 +4,8 @@ let in { options.process-managers.honcho = { - enable = lib.mkOption { - type = lib.types.bool; + enable = lib.mkEnableOption "honcho as the process manager" // { internal = true; - default = false; - description = "Whether to use honcho as the process manager"; }; package = lib.mkOption { diff --git a/src/modules/process-managers/overmind.nix b/src/modules/process-managers/overmind.nix index 6b4e301bb..5ed3b6d0d 100644 --- a/src/modules/process-managers/overmind.nix +++ b/src/modules/process-managers/overmind.nix @@ -4,11 +4,8 @@ let in { options.process-managers.overmind = { - enable = lib.mkOption { - type = lib.types.bool; + enable = lib.mkEnableOption "overmind as the process manager" // { internal = true; - default = false; - description = "Whether to use overmind as the process manager"; }; package = lib.mkOption { diff --git a/src/modules/process-managers/process-compose.nix b/src/modules/process-managers/process-compose.nix index 7f3904936..1961fbca0 100644 --- a/src/modules/process-managers/process-compose.nix +++ b/src/modules/process-managers/process-compose.nix @@ -5,11 +5,8 @@ let in { options.process-managers.process-compose = { - enable = lib.mkOption { - type = lib.types.bool; + enable = lib.mkEnableOption "process-compose as the process manager" // { internal = true; - default = false; - description = "Whether to use process-compose as the process manager"; }; package = lib.mkOption { From aa55bebc38205e784aa6f6c950e511c1a1ca6b14 Mon Sep 17 00:00:00 2001 From: Sander Date: Mon, 2 Sep 2024 14:35:22 +0000 Subject: [PATCH 06/21] process-compose: fixup types --- src/modules/process-managers/process-compose.nix | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/modules/process-managers/process-compose.nix b/src/modules/process-managers/process-compose.nix index 1961fbca0..de46c550b 100644 --- a/src/modules/process-managers/process-compose.nix +++ b/src/modules/process-managers/process-compose.nix @@ -19,13 +19,16 @@ in port = lib.mkOption { type = lib.types.int; default = 8080; + description = "The port to bind the process-compose server to."; }; unixSocket = { - enable = lib.mkEnableOption "unix domain sockets instead of tcp"; + enable = lib.mkEnableOption "running the process-compose server over unix domain sockets instead of tcp" // { + default = true; + }; path = lib.mkOption { - type = lib.types.nullOr lib.types.str; + 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."; From 7e9383f2edf202b3bf1f753aff521c07dbda0144 Mon Sep 17 00:00:00 2001 From: Sander Date: Mon, 2 Sep 2024 15:04:26 +0000 Subject: [PATCH 07/21] process-compose: improve unix socket logic --- src/modules/process-managers/process-compose.nix | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/modules/process-managers/process-compose.nix b/src/modules/process-managers/process-compose.nix index de46c550b..0343711d0 100644 --- a/src/modules/process-managers/process-compose.nix +++ b/src/modules/process-managers/process-compose.nix @@ -19,7 +19,11 @@ in port = lib.mkOption { type = lib.types.int; default = 8080; - description = "The port to bind the process-compose server to."; + description = '' + The port to bind the process-compose server to. + + Not used when `unixSocket.enable` is true. + ''; }; unixSocket = { @@ -28,7 +32,7 @@ in }; path = lib.mkOption { - type = lib.types.str; + type = lib.types.nullOr 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."; @@ -72,8 +76,9 @@ in config = lib.mkIf cfg.enable { process.manager.args = { "config" = cfg.configFile; - "U" = cfg.unixSocket.enable; - "unix-socket" = "\${PC_SOCKET_PATH:-${toString cfg.unixSocket.path}}"; + # -U enables automatic UDS mode, creating the socket in $TMP. + "U" = cfg.unixSocket.enable && cfg.unixSocket.path == null; + "unix-socket" = cfg.unixSocket.path; "tui" = "\${PC_TUI_ENABLED:-${lib.boolToString cfg.tui.enable}}"; }; From d1520140b8d6a8cb7e0c2c09457a6b7ddaddeec3 Mon Sep 17 00:00:00 2001 From: Sander Date: Mon, 2 Sep 2024 15:08:16 +0000 Subject: [PATCH 08/21] process: migrate manager options --- src/modules/processes.nix | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/modules/processes.nix b/src/modules/processes.nix index 72b20acdc..7cfdb5d7a 100644 --- a/src/modules/processes.nix +++ b/src/modules/processes.nix @@ -42,11 +42,13 @@ let config.env; in { - imports = [ - (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" ]) - ]; + 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" ]) + ]; options = { processes = lib.mkOption { From f49d029a594be12de45de9deae1bf8db410f4c8c Mon Sep 17 00:00:00 2001 From: Sander Date: Mon, 2 Sep 2024 15:23:26 +0000 Subject: [PATCH 09/21] docs: fixup processes..process-compose description --- src/modules/processes.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/processes.nix b/src/modules/processes.nix index 7cfdb5d7a..8fd80fd6b 100644 --- a/src/modules/processes.nix +++ b/src/modules/processes.nix @@ -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" ]; From b5a5bd3167d89a9c6eff6dae0996b28e5eb4248a Mon Sep 17 00:00:00 2001 From: Sander Date: Tue, 3 Sep 2024 18:03:02 +0000 Subject: [PATCH 10/21] chore: cleanup process --- src/modules/processes.nix | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/modules/processes.nix b/src/modules/processes.nix index 8fd80fd6b..75f627d89 100644 --- a/src/modules/processes.nix +++ b/src/modules/processes.nix @@ -82,7 +82,10 @@ in type = types.str; internal = true; description = '' - The command to run the process manager. This is meant to be set by the process.manager.''${implementation}. + 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. ''; }; @@ -102,8 +105,8 @@ in }; procfileEnv = lib.mkOption { - internal = true; type = types.package; + internal = true; }; procfileScript = lib.mkOption { From 7cee185f5159d35639240370ba31147f55b4afa0 Mon Sep 17 00:00:00 2001 From: Sander Date: Tue, 3 Sep 2024 19:42:20 +0000 Subject: [PATCH 11/21] process: improve shutdown stderr redirect --- src/modules/processes.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/processes.nix b/src/modules/processes.nix index 75f627d89..14911f6c5 100644 --- a/src/modules/processes.nix +++ b/src/modules/processes.nix @@ -151,8 +151,8 @@ in down() { echo "Stopping processes..." - kill -TERM $backgroundPID &> /dev/null || true - wait $backgroundPID &> /dev/null || true + kill -TERM $backgroundPID 2>&1 /dev/null || true + wait $backgroundPID 2>&1 /dev/null || true ${config.process.manager.after} echo "Processes stopped." } From 06d6744cf011813c2e034b3c2e209cb6cbafcad6 Mon Sep 17 00:00:00 2001 From: Sander Date: Tue, 10 Sep 2024 10:54:16 +0000 Subject: [PATCH 12/21] process-managers: move to process.managers --- flake.nix | 73 +++++++++---------- src/modules/process-managers/hivemind.nix | 4 +- src/modules/process-managers/honcho.nix | 4 +- src/modules/process-managers/overmind.nix | 4 +- .../process-managers/process-compose.nix | 6 +- src/modules/processes.nix | 11 +-- 6 files changed, 51 insertions(+), 51 deletions(-) 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/process-managers/hivemind.nix b/src/modules/process-managers/hivemind.nix index b231542e8..acaa70a3f 100644 --- a/src/modules/process-managers/hivemind.nix +++ b/src/modules/process-managers/hivemind.nix @@ -1,9 +1,9 @@ { pkgs, config, lib, ... }: let - cfg = config.process-managers.hivemind; + cfg = config.process.managers.hivemind; in { - options.process-managers.hivemind = { + options.process.managers.hivemind = { enable = lib.mkEnableOption "hivemind as the process manager" // { internal = true; }; diff --git a/src/modules/process-managers/honcho.nix b/src/modules/process-managers/honcho.nix index d33fd27c7..bfa99a940 100644 --- a/src/modules/process-managers/honcho.nix +++ b/src/modules/process-managers/honcho.nix @@ -1,9 +1,9 @@ { pkgs, config, lib, ... }: let - cfg = config.process-managers.honcho; + cfg = config.process.managers.honcho; in { - options.process-managers.honcho = { + options.process.managers.honcho = { enable = lib.mkEnableOption "honcho as the process manager" // { internal = true; }; diff --git a/src/modules/process-managers/overmind.nix b/src/modules/process-managers/overmind.nix index 5ed3b6d0d..661209aee 100644 --- a/src/modules/process-managers/overmind.nix +++ b/src/modules/process-managers/overmind.nix @@ -1,9 +1,9 @@ { pkgs, config, lib, ... }: let - cfg = config.process-managers.overmind; + cfg = config.process.managers.overmind; in { - options.process-managers.overmind = { + options.process.managers.overmind = { enable = lib.mkEnableOption "overmind as the process manager" // { internal = true; }; diff --git a/src/modules/process-managers/process-compose.nix b/src/modules/process-managers/process-compose.nix index 0343711d0..0dae4f36d 100644 --- a/src/modules/process-managers/process-compose.nix +++ b/src/modules/process-managers/process-compose.nix @@ -1,10 +1,10 @@ { 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 = { + options.process.managers.process-compose = { enable = lib.mkEnableOption "process-compose as the process manager" // { internal = true; }; @@ -90,7 +90,7 @@ in packages = [ cfg.package ]; - process-managers.process-compose = { + process.managers.process-compose = { configFile = lib.mkDefault (settingsFormat.generate "process-compose.yaml" cfg.settings); settings = { version = "0.5"; diff --git a/src/modules/processes.nix b/src/modules/processes.nix index 14911f6c5..dc590839f 100644 --- a/src/modules/processes.nix +++ b/src/modules/processes.nix @@ -33,7 +33,7 @@ let }; }); - supportedImplementations = builtins.attrNames options.process-managers; + supportedImplementations = builtins.attrNames options.process.managers; implementation = config.process.manager.implementation; envList = @@ -45,9 +45,10 @@ 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 [ "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 = { @@ -122,7 +123,7 @@ in let enabledImplementations = lib.pipe supportedImplementations [ - (map (name: config.process-managers.${name}.enable)) + (map (name: config.process.managers.${name}.enable)) (lib.filter lib.id) ]; in @@ -132,7 +133,7 @@ in ''; }]; - process-managers.${implementation}.enable = lib.mkDefault true; + process.managers.${implementation}.enable = lib.mkDefault true; procfile = pkgs.writeText "procfile" (lib.concatStringsSep "\n" From 3e5c38c92d51a1710ae3a37cd190cd27fc3aa6d6 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 10 Sep 2024 10:56:49 +0000 Subject: [PATCH 13/21] Auto generate docs/reference/options.md --- docs/reference/options.md | 204 ++++++++++++++++---------------------- 1 file changed, 83 insertions(+), 121 deletions(-) diff --git a/docs/reference/options.md b/docs/reference/options.md index d1e457d10..485e6361c 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 @@ -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 +null or 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"; ` From a7775d2c6f12f03dafc4dd950d232d087ce0db04 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 10 Sep 2024 10:57:38 +0000 Subject: [PATCH 14/21] Auto generate docs and examples --- docs/supported-process-managers/hivemind.md | 25 +----- docs/supported-process-managers/honcho.md | 25 +----- docs/supported-process-managers/overmind.md | 25 +----- .../process-compose.md | 84 +++++++++++++++---- 4 files changed, 73 insertions(+), 86 deletions(-) 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..8867e831a 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 + + + +*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:* +null or string + + + +*Default:* +` ${config.devenv.runtime}/pc.sock ` From acc4da6bc2297543c3159919c2417c4fc0074288 Mon Sep 17 00:00:00 2001 From: Sander Date: Mon, 7 Oct 2024 15:02:59 +0400 Subject: [PATCH 15/21] process: undo exit trap changes Needs more testing. --- src/modules/processes.nix | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/modules/processes.nix b/src/modules/processes.nix index dc590839f..63560d4ce 100644 --- a/src/modules/processes.nix +++ b/src/modules/processes.nix @@ -152,13 +152,13 @@ in down() { echo "Stopping processes..." - kill -TERM $backgroundPID 2>&1 /dev/null || true - wait $backgroundPID 2>&1 /dev/null || true + kill -TERM $backgroundPID + wait $backgroundPID ${config.process.manager.after} echo "Processes stopped." } - trap down EXIT + trap down SIGINT SIGTERM wait ''; From 057c6d1a23aa99746555c3f3e988ab6ef23cbe11 Mon Sep 17 00:00:00 2001 From: Sander Date: Mon, 7 Oct 2024 15:03:32 +0400 Subject: [PATCH 16/21] process-compose: fix tui args --- src/modules/process-managers/process-compose.nix | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/modules/process-managers/process-compose.nix b/src/modules/process-managers/process-compose.nix index 0dae4f36d..f1ec22303 100644 --- a/src/modules/process-managers/process-compose.nix +++ b/src/modules/process-managers/process-compose.nix @@ -78,13 +78,14 @@ in "config" = cfg.configFile; # -U enables automatic UDS mode, creating the socket in $TMP. "U" = cfg.unixSocket.enable && cfg.unixSocket.path == null; - "unix-socket" = cfg.unixSocket.path; - "tui" = "\${PC_TUI_ENABLED:-${lib.boolToString cfg.tui.enable}}"; + "unix-socket" = "'${cfg.unixSocket.path}'"; + # TODO: move -t (for tui) here. We need a newer nixpkgs for optionValueSeparator = "=". }; process.manager.command = lib.mkDefault '' ${cfg.package}/bin/process-compose \ - ${lib.concatStringsSep " " (lib.cli.toGNUCommandLine {} config.process.manager.args)} \ + ${lib.cli.toGNUCommandLineShell { } config.process.manager.args} \ + -t="''${PC_TUI_ENABLED:-${lib.boolToString cfg.tui.enable}}" \ up "$@" & ''; From c294d9835f86dc4ae5768e0a5c2808cb881d593e Mon Sep 17 00:00:00 2001 From: Sander Date: Mon, 7 Oct 2024 15:24:17 +0400 Subject: [PATCH 17/21] process-compose: simplify settings - Drop -U mode: we already provide a default socket for you - Make socket path non-null - Simplify escapes - Pass port --- src/modules/process-managers/process-compose.nix | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/modules/process-managers/process-compose.nix b/src/modules/process-managers/process-compose.nix index f1ec22303..2c7ce80b8 100644 --- a/src/modules/process-managers/process-compose.nix +++ b/src/modules/process-managers/process-compose.nix @@ -32,7 +32,7 @@ in }; path = lib.mkOption { - type = lib.types.nullOr lib.types.str; + 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."; @@ -76,9 +76,11 @@ in config = lib.mkIf cfg.enable { process.manager.args = { "config" = cfg.configFile; - # -U enables automatic UDS mode, creating the socket in $TMP. - "U" = cfg.unixSocket.enable && cfg.unixSocket.path == null; - "unix-socket" = "'${cfg.unixSocket.path}'"; + "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 = "=". }; From c412b237347a5ba5a50f19a0b1cf97eeabb9eecf Mon Sep 17 00:00:00 2001 From: Sander Date: Mon, 7 Oct 2024 15:29:15 +0400 Subject: [PATCH 18/21] process-managers: simplify arg building --- src/modules/process-managers/hivemind.nix | 2 +- src/modules/process-managers/honcho.nix | 2 +- src/modules/process-managers/overmind.nix | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/modules/process-managers/hivemind.nix b/src/modules/process-managers/hivemind.nix index acaa70a3f..02f447ef6 100644 --- a/src/modules/process-managers/hivemind.nix +++ b/src/modules/process-managers/hivemind.nix @@ -23,7 +23,7 @@ in process.manager.command = lib.mkDefault '' ${cfg.package}/bin/hivemind \ - ${lib.concatStringsSep " " (lib.cli.toGNUCommandLine {} config.process.manager.args)} \ + ${lib.cli.toGNUCommandLineShell {} config.process.manager.args} \ "$@" ${config.procfile} & ''; diff --git a/src/modules/process-managers/honcho.nix b/src/modules/process-managers/honcho.nix index bfa99a940..cb59accd9 100644 --- a/src/modules/process-managers/honcho.nix +++ b/src/modules/process-managers/honcho.nix @@ -24,7 +24,7 @@ in process.manager.command = lib.mkDefault '' ${cfg.package}/bin/honcho start \ - ${lib.concatStringsSep " " (lib.cli.toGNUCommandLine {} config.process.manager.args)} \ + ${lib.cli.toGNUCommandLineShell {} config.process.manager.args} \ "$@" & ''; diff --git a/src/modules/process-managers/overmind.nix b/src/modules/process-managers/overmind.nix index 661209aee..7679658ba 100644 --- a/src/modules/process-managers/overmind.nix +++ b/src/modules/process-managers/overmind.nix @@ -25,7 +25,7 @@ in process.manager.command = lib.mkDefault '' OVERMIND_ENV=${config.procfileEnv} ${cfg.package}/bin/overmind start \ - ${lib.concatStringsSep " " (lib.cli.toGNUCommandLine {} config.process.manager.args)} \ + ${lib.cli.toGNUCommandLineShell {} config.process.manager.args} \ "$@" & ''; From 3dfe5e4f0568cff614a5c753ecddd97b5b0dcbb4 Mon Sep 17 00:00:00 2001 From: Sander Date: Mon, 7 Oct 2024 15:55:21 +0400 Subject: [PATCH 19/21] process-compose: mark default settings --- src/modules/process-managers/process-compose.nix | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/modules/process-managers/process-compose.nix b/src/modules/process-managers/process-compose.nix index 2c7ce80b8..97c6d7a44 100644 --- a/src/modules/process-managers/process-compose.nix +++ b/src/modules/process-managers/process-compose.nix @@ -43,7 +43,7 @@ in enable = lib.mkOption { type = lib.types.bool; default = true; - description = "Enable the TUI"; + description = "Enable the TUI (Terminal User Interface)"; }; }; @@ -96,8 +96,8 @@ in process.managers.process-compose = { configFile = lib.mkDefault (settingsFormat.generate "process-compose.yaml" cfg.settings); settings = { - version = "0.5"; - is_strict = true; + version = lib.mkDefault "0.5"; + is_strict = lib.mkDefault true; environment = lib.mapAttrsToList (name: value: "${name}=${toString value}") config.env; From 1fd850ce9a212fe1f3ce1be84332e83c1eb9950f Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 7 Oct 2024 12:46:41 +0000 Subject: [PATCH 20/21] Auto generate docs/reference/options.md --- docs/reference/options.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/reference/options.md b/docs/reference/options.md index 485e6361c..58eab4774 100644 --- a/docs/reference/options.md +++ b/docs/reference/options.md @@ -35209,7 +35209,7 @@ YAML value -Enable the TUI +Enable the TUI (Terminal User Interface) @@ -35261,7 +35261,7 @@ Override the path to the unix socket. *Type:* -null or string +string From ce335f1e20eee296ef8be4b3977d8e580c0a1a07 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 7 Oct 2024 12:47:39 +0000 Subject: [PATCH 21/21] Auto generate docs and examples --- docs/supported-process-managers/process-compose.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/supported-process-managers/process-compose.md b/docs/supported-process-managers/process-compose.md index 8867e831a..6df390ea8 100644 --- a/docs/supported-process-managers/process-compose.md +++ b/docs/supported-process-managers/process-compose.md @@ -85,7 +85,7 @@ YAML value -Enable the TUI +Enable the TUI (Terminal User Interface) @@ -131,7 +131,7 @@ Override the path to the unix socket\. *Type:* -null or string +string