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} + ''} ''; }