templates

package
v0.0.12 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 25, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package templates provides Nix flake template rendering for build strategies.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTemplateNotFound     = fmt.Errorf("template not found")
	ErrTemplateRenderFailed = fmt.Errorf("failed to render template")
	ErrInvalidFlakeSyntax   = fmt.Errorf("generated flake has invalid syntax")
)

Errors for template operations - kept for backward compatibility.

Functions

func FormatLdflagsForNix

func FormatLdflagsForNix(ldflags string) string

FormatLdflagsForNix converts a space-separated ldflags string into Nix list format. It handles quoted strings and -X flags with values correctly. e.g., "-s -w -X main.version=1.0" -> ""-s" "-w" "-X main.version=1.0"" **Validates: Requirements 18.2**

func GetTemplateForStrategy

func GetTemplateForStrategy(strategy models.BuildStrategy, config models.BuildConfig) string

GetTemplateForStrategy returns the appropriate template name for a build strategy.

Types

type DefaultTemplateEngine

type DefaultTemplateEngine struct {
	// contains filtered or unexported fields
}

DefaultTemplateEngine is the default implementation of TemplateEngine.

func NewTemplateEngine

func NewTemplateEngine() (*DefaultTemplateEngine, error)

NewTemplateEngine creates a new DefaultTemplateEngine with embedded templates.

func (*DefaultTemplateEngine) ListTemplates

func (e *DefaultTemplateEngine) ListTemplates() []string

ListTemplates returns available template names.

func (*DefaultTemplateEngine) Render

func (e *DefaultTemplateEngine) Render(ctx context.Context, templateName string, data TemplateData) (string, error)

Render generates a flake.nix from a template.

func (*DefaultTemplateEngine) RenderAndValidate

func (e *DefaultTemplateEngine) RenderAndValidate(ctx context.Context, templateName string, data TemplateData) (string, error)

RenderAndValidate renders a template and validates the output. This is a convenience method that combines Render and Validate.

func (*DefaultTemplateEngine) Validate

func (e *DefaultTemplateEngine) Validate(ctx context.Context, flakeContent string) error

Validate checks if generated flake.nix is syntactically valid using nix flake check.

func (*DefaultTemplateEngine) ValidateSyntax

func (e *DefaultTemplateEngine) ValidateSyntax(flakeContent string) error

ValidateSyntax performs a basic syntax check on the flake content without running nix. This is faster than full validation and catches common template errors.

type TemplateData

type TemplateData struct {
	AppName         string
	Version         string
	Framework       models.Framework
	EntryPoint      string
	BuildCommand    string
	StartCommand    string
	Config          models.BuildConfig
	DetectionResult *models.DetectionResult
	System          string
	DatabaseType    string
	DatabaseVersion string
}

TemplateData contains data passed to templates.

type TemplateEngine

type TemplateEngine interface {
	// Render generates a flake.nix from a template.
	Render(ctx context.Context, templateName string, data TemplateData) (string, error)

	// Validate checks if generated flake.nix is syntactically valid.
	Validate(ctx context.Context, flakeContent string) error

	// ListTemplates returns available template names.
	ListTemplates() []string
}

TemplateEngine renders Nix flake templates.

Directories

Path Synopsis
Package databases provides database flake template registry and configuration.
Package databases provides database flake template registry and configuration.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL