From 7da7a04baf0150c314775a1cd250e689d719dc1f Mon Sep 17 00:00:00 2001 From: zimward Date: Sun, 22 Feb 2026 14:15:41 +0100 Subject: [PATCH] lib/wrapModule: add postHook --- lib/default.nix | 10 ++++++++-- lib/modules/wrapper.nix | 10 ++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/default.nix b/lib/default.nix index a653884..ec93b18 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -380,13 +380,14 @@ let - `flagSeparator`: Separator between flag names and values when generating args from flags (optional, defaults to " ") - `args`: List of command-line arguments like argv in execve (optional, auto-generated from flags if not provided) - `preHook`: Shell script to run before executing the command (optional) + - `postHook`: Shell script to run after executing the command, removes the `exec` call. use with care (optional) - `passthru`: Attribute set to pass through to the wrapped derivation (optional) - `aliases`: List of additional names to symlink to the wrapped executable (optional) - `filesToPatch`: List of file paths (glob patterns) to patch for self-references (optional, defaults to ["share/applications/*.desktop"]) - `filesToExclude`: List of file paths (glob patterns) to exclude from the wrapped package (optional, defaults to []) - `patchHook`: Shell script that runs after patchPhase to modify the wrapper package files (optional) - `wrapper`: Custom wrapper function (optional, defaults to exec'ing the original binary with args) - - Called with { env, flags, args, envString, flagsString, exePath, preHook } + - Called with { env, flags, args, envString, flagsString, exePath, preHook, postHook } # Example @@ -446,6 +447,7 @@ let # " " for "--flag value" or "=" for "--flag=value" args ? generateArgsFromFlags flags flagSeparator, preHook ? "", + postHook ? "", passthru ? { }, aliases ? [ ], # List of file paths (glob patterns) relative to package root to patch for self-references (e.g., ["bin/*", "lib/*.sh"]) @@ -459,12 +461,14 @@ let flagsString, envString, preHook, + postHook, ... }: '' ${envString} ${preHook} - exec ${exePath}${flagsString} "$@" + ${lib.optionalString (postHook == "") "exec"} ${exePath}${flagsString} "$@" + ${postHook} '' ), }@funcArgs: @@ -497,6 +501,7 @@ let flagsString exePath preHook + postHook ; }; @@ -654,6 +659,7 @@ let flags args preHook + postHook aliases ; override = diff --git a/lib/modules/wrapper.nix b/lib/modules/wrapper.nix index d8d42fb..a950d46 100644 --- a/lib/modules/wrapper.nix +++ b/lib/modules/wrapper.nix @@ -99,6 +99,15 @@ Shell script to run before executing the command. ''; }; + options.postHook = lib.mkOption { + type = lib.types.str; + default = ""; + description = '' + Shell script to run after executing the command. + Removes the `exec` call in the wrapper script which will leave a bash process + in the background, therefore use with care. + ''; + }; options.exePath = lib.mkOption { type = lib.types.path; description = '' @@ -138,6 +147,7 @@ filesToPatch = config.filesToPatch; filesToExclude = config.filesToExclude; preHook = config.preHook; + postHook = config.postHook; patchHook = config.patchHook; passthru = { configuration = config;