From 61e7f31625152a988c1932db520c7e1efec70f64 Mon Sep 17 00:00:00 2001 From: connerohnesorge Date: Mon, 13 Oct 2025 19:00:48 -0500 Subject: [PATCH] feat: Add post-generation hooks support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add support for running bash commands after protobuf code generation completes. - Add hooks.postGeneration option for bash commands to run after all generation - Add hooks.onFailure option to control behavior when hooks fail (continue/stop) - Set environment variables for hook context (BUFRNIX_ROOT, enabled languages, etc.) - Integrate with existing debug logging system - Maintain backward compatibility (hooks are optional) Usage example: hooks = { postGeneration = '' echo "Running post-generation tasks..." find . -name "*.pb.go" -exec gofmt -w {} + cd gen/go && go mod tidy ''; onFailure = "continue"; }; 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- src/lib/bufrnix-options.nix | 20 ++++++++++++++++++++ src/lib/mkBufrnix.nix | 17 +++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/src/lib/bufrnix-options.nix b/src/lib/bufrnix-options.nix index 7416206..8d7f488 100644 --- a/src/lib/bufrnix-options.nix +++ b/src/lib/bufrnix-options.nix @@ -53,6 +53,26 @@ with lib; { }; }; + # Post-generation hooks configuration + hooks = { + postGeneration = mkOption { + type = types.str; + default = ""; + description = "Bash commands to run after all code generation completes"; + example = '' + echo "All generation completed!" + find . -name "*.pb.go" -exec gofmt -w {} + + cd gen/go && go mod tidy + ''; + }; + + onFailure = mkOption { + type = types.enum ["continue" "stop"]; + default = "continue"; + description = "What to do if any hook fails (continue or stop execution)"; + }; + }; + # protoc options protoc = { sourceDirectories = mkOption { diff --git a/src/lib/mkBufrnix.nix b/src/lib/mkBufrnix.nix index a68c3fb..9b7c48a 100644 --- a/src/lib/mkBufrnix.nix +++ b/src/lib/mkBufrnix.nix @@ -387,5 +387,22 @@ in generateProtocCommands} ${debug.log 1 "Multiple output path code generation completed successfully" cfg} + + # Execute post-generation hooks if configured + ${optionalString (cfg.hooks.postGeneration != "") '' + ${debug.log 1 "Executing post-generation hooks..." cfg} + + # Set environment variables for hooks + export BUFRNIX_ROOT="${cfg.root}" + export BUFRNIX_ENABLED_LANGUAGES="${concatStringsSep " " (filter (lang: cfg.languages.${lang}.enable) languageNames)}" + export BUFRNIX_DEBUG_ENABLE="${if cfg.debug.enable then "true" else "false"}" + export BUFRNIX_DEBUG_VERBOSITY="${toString cfg.debug.verbosity}" + + # Execute post-generation hooks + echo "🚀 Running post-generation hooks..." + ${cfg.hooks.postGeneration} + echo "✅ Post-generation hooks completed successfully" + ${debug.log 1 "Post-generation hooks completed successfully" cfg} + ''} ''; }