flakelock

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: 12 Imported by: 0

Documentation

Overview

Package flakelock provides flake.lock file management for reproducible builds.

Package flakelock provides flake.lock file management for reproducible builds.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrEmptyFlakePath is returned when the flake path is empty.
	ErrEmptyFlakePath = errors.New("flake path is empty")

	// ErrFlakeNotFound is returned when flake.nix is not found.
	ErrFlakeNotFound = errors.New("flake.nix not found")

	// ErrLockGenerationFailed is returned when lock generation fails.
	ErrLockGenerationFailed = errors.New("failed to generate flake.lock")

	// ErrLockGenerationTimeout is returned when lock generation times out.
	ErrLockGenerationTimeout = errors.New("flake.lock generation timed out")

	// ErrLockUpdateFailed is returned when lock update fails.
	ErrLockUpdateFailed = errors.New("failed to update flake.lock")

	// ErrInvalidLockFormat is returned when the lock content is not valid JSON.
	ErrInvalidLockFormat = errors.New("invalid flake.lock format")

	// ErrEmptyBuildID is returned when the build ID is empty.
	ErrEmptyBuildID = errors.New("build ID is empty")

	// ErrEmptyLockContent is returned when the lock content is empty.
	ErrEmptyLockContent = errors.New("lock content is empty")

	// ErrLockNotFound is returned when a stored lock is not found.
	ErrLockNotFound = errors.New("flake.lock not found for build ID")
)

Errors returned by the flakelock package.

Functions

func CompareFlakeLocks

func CompareFlakeLocks(lock1, lock2 string) bool

CompareFlakeLocks compares two flake.lock contents and returns true if they are equivalent.

func GetInputRevision

func GetInputRevision(lockContent string, inputName string) (string, error)

GetInputRevision extracts the revision for a specific input from the lock file.

Types

type FlakeLockFile

type FlakeLockFile struct {
	Version int                    `json:"version"`
	Nodes   map[string]interface{} `json:"nodes"`
	Root    string                 `json:"root,omitempty"`
}

FlakeLockFile represents the structure of a flake.lock file.

func ParseFlakeLock

func ParseFlakeLock(content string) (*FlakeLockFile, error)

ParseFlakeLock parses a flake.lock content into a FlakeLockFile.

type FlakeLockManager

type FlakeLockManager interface {
	// Generate creates a new flake.lock for a flake.nix.
	Generate(ctx context.Context, flakePath string) (string, error)

	// Update updates an existing flake.lock.
	Update(ctx context.Context, flakePath string, existingLock string) (string, error)

	// Store persists a flake.lock for a build.
	Store(ctx context.Context, buildID string, lockContent string) error

	// Retrieve gets a stored flake.lock.
	Retrieve(ctx context.Context, buildID string) (string, error)

	// ShouldRegenerate determines if lock should be regenerated.
	ShouldRegenerate(ctx context.Context, buildID string, sourceHash string) bool
}

FlakeLockManager manages flake.lock files for reproducibility.

type Manager

type Manager struct {
	// Timeout is the maximum time to wait for lock generation.
	Timeout time.Duration
	// contains filtered or unexported fields
}

Manager implements the FlakeLockManager interface.

func NewManager

func NewManager() *Manager

NewManager creates a new Manager with default settings.

func NewManagerWithOptions

func NewManagerWithOptions(opts ...ManagerOption) *Manager

NewManagerWithOptions creates a new Manager with custom options.

func (*Manager) Delete

func (m *Manager) Delete(ctx context.Context, buildID string) error

Delete removes a stored flake.lock.

func (*Manager) Generate

func (m *Manager) Generate(ctx context.Context, flakePath string) (string, error)

Generate creates a new flake.lock for a flake.nix at the given path. It runs `nix flake lock` to generate the lock file.

func (*Manager) GetStoredLock

func (m *Manager) GetStoredLock(ctx context.Context, buildID string) (*StoredLock, error)

GetStoredLock retrieves the full stored lock metadata.

func (*Manager) ListBuildIDs

func (m *Manager) ListBuildIDs(ctx context.Context) []string

ListBuildIDs returns all build IDs with stored locks.

func (*Manager) Retrieve

func (m *Manager) Retrieve(ctx context.Context, buildID string) (string, error)

Retrieve gets a stored flake.lock by build ID.

func (*Manager) ShouldRegenerate

func (m *Manager) ShouldRegenerate(ctx context.Context, buildID string, sourceHash string) bool

ShouldRegenerate determines if the lock should be regenerated. Returns true if: - No lock exists for the build ID - The source hash has changed (indicating source code changes)

func (*Manager) Store

func (m *Manager) Store(ctx context.Context, buildID string, lockContent string) error

Store persists a flake.lock for a build.

func (*Manager) Update

func (m *Manager) Update(ctx context.Context, flakePath string, existingLock string) (string, error)

Update updates an existing flake.lock by running `nix flake update`. If existingLock is provided, it writes it first before updating.

type ManagerOption

type ManagerOption func(*Manager)

ManagerOption is a functional option for configuring Manager.

func WithTimeout

func WithTimeout(timeout time.Duration) ManagerOption

WithTimeout sets the timeout for lock generation.

type StoredLock

type StoredLock struct {
	Content    string    `json:"content"`
	SourceHash string    `json:"source_hash"`
	CreatedAt  time.Time `json:"created_at"`
	UpdatedAt  time.Time `json:"updated_at"`
}

StoredLock represents a stored flake.lock with metadata.

Jump to

Keyboard shortcuts

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