From 2316693e8883e0e4400f5b47cefc8d9c88e30067 Mon Sep 17 00:00:00 2001 From: John Lotoski Date: Thu, 18 Jan 2024 13:55:37 -0600 Subject: [PATCH 1/2] imp: add pre- and post- process-compose hooks --- nix/process-compose/cli.nix | 10 ++++++++++ nix/process-compose/default.nix | 13 +++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/nix/process-compose/cli.nix b/nix/process-compose/cli.nix index 095310a..f45ce2f 100644 --- a/nix/process-compose/cli.nix +++ b/nix/process-compose/cli.nix @@ -10,6 +10,11 @@ in default = true; description = "Enable or disable process-compose's Swagger API."; }; + preHook = mkOption { + type = types.lines; + default = ""; + description = "Shell commands to run before process-compose starts."; + }; port = mkOption { type = types.int; default = 0; @@ -17,6 +22,11 @@ in Port to serve process-compose's Swagger API on. ''; }; + postHook = mkOption { + type = types.lines; + default = ""; + description = "Shell commands to run after process-compose completes."; + }; tui = mkOption { type = types.bool; default = true; diff --git a/nix/process-compose/default.nix b/nix/process-compose/default.nix index 3f09416..cedb89b 100644 --- a/nix/process-compose/default.nix +++ b/nix/process-compose/default.nix @@ -37,7 +37,7 @@ in config.outputs = let - mkProcessComposeWrapper = { name, tui, apiServer, port, configFile }: + mkProcessComposeWrapper = { name, tui, apiServer, port, configFile, preHook, postHook }: pkgs.writeShellApplication { inherit name; runtimeInputs = [ config.package ]; @@ -50,7 +50,12 @@ in if tui then "" else "export PC_DISABLE_TUI=true" } ${if apiServer then "" else "export PC_NO_SERVER=true"} - exec process-compose -p ${toString port} "$@" + + ${preHook} + + process-compose -p ${toString port} "$@" + + ${postHook} ''; }; in @@ -59,7 +64,7 @@ in mkProcessComposeWrapper { inherit name; - inherit (config) tui apiServer port; + inherit (config) tui apiServer port preHook postHook; configFile = config.outputs.settingsYaml; }; testPackage = @@ -69,7 +74,7 @@ in mkProcessComposeWrapper { name = "${name}-test"; - inherit (config) tui apiServer port; + inherit (config) tui apiServer port preHook postHook; configFile = config.outputs.settingsTestYaml; } else null; From 472dd20466520c2ad348ff15d03fbbd11c41e774 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar <3998+srid@users.noreply.github.com> Date: Fri, 19 Jan 2024 02:51:10 -0500 Subject: [PATCH 2/2] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c84779c..89295b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ - New options - #52: Add `is_foreground` option - #54: Add `apiServer` option to control REST API server + - #56: Add `preHook` and `postHook` for running commands before and after launching process-compose respectively. - Fixes - #19: Reintroduce the `shell` option so process-compose doesn't rely on user's global bash (which doesn't exist nixosTest runners). - #22: `command` option is no longer wrapped in `writeShellApplication`.