Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/lib/bufrnix-options.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
17 changes: 17 additions & 0 deletions src/lib/mkBufrnix.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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}
''}
'';
}