packages

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package packages provides package backend operations.

Index

Constants

This section is empty.

Variables

View Source
var AutoBackend = func() (string, error) {
	f, err := detect.Detect()
	if err != nil {
		return "", err
	}
	return f.Backend, nil
}

AutoBackend resolves the backend string from the runtime environment. It is a variable so tests can substitute it.

Functions

This section is empty.

Types

type Apt

type Apt struct {
	Runner Runner
}

Apt is the Debian/Ubuntu backend skeleton.

func NewApt

func NewApt() *Apt

NewApt returns an Apt backend using the real command runner.

func (*Apt) Absent

func (a *Apt) Absent(ctx context.Context, pkgs []string) error

Absent removes packages.

func (*Apt) IsInstalled

func (a *Apt) IsInstalled(ctx context.Context, pkg string) (bool, error)

IsInstalled checks if a package is installed via dpkg.

func (*Apt) Present

func (a *Apt) Present(ctx context.Context, pkgs []string) error

Present installs packages idempotently. Unlike dnf (which refreshes repository metadata as part of install), apt needs an explicit index refresh first: on a fresh machine/container the index is empty or stale and `apt-get install` fails with "Unable to locate package".

type Backend

type Backend interface {
	// Present installs the given packages if not already present.
	Present(ctx context.Context, pkgs []string) error
	// Absent removes the given packages.
	Absent(ctx context.Context, pkgs []string) error
	// IsInstalled reports whether a package is already installed.
	IsInstalled(ctx context.Context, pkg string) (bool, error)
}

Backend performs package operations.

func For

func For(backend string) Backend

For selects a backend for the given facts. It returns a Paru backend for Arch-family distros, Apt for Debian/Ubuntu, Dnf for Fedora, and resolves from os-release for "auto".

type Dnf

type Dnf struct {
	Runner Runner
}

Dnf is the Fedora/RHEL backend skeleton.

func NewDnf

func NewDnf() *Dnf

NewDnf returns a Dnf backend using the real command runner.

func (*Dnf) Absent

func (d *Dnf) Absent(ctx context.Context, pkgs []string) error

Absent removes packages.

func (*Dnf) IsInstalled

func (d *Dnf) IsInstalled(ctx context.Context, pkg string) (bool, error)

IsInstalled checks if a package is installed via rpm.

func (*Dnf) Present

func (d *Dnf) Present(ctx context.Context, pkgs []string) error

Present installs packages idempotently.

type ExecRunner

type ExecRunner struct{}

ExecRunner is the real command runner.

func (ExecRunner) Run

func (ExecRunner) Run(ctx context.Context, name string, args ...string) (string, error)

type Paru

type Paru struct {
	Runner Runner
}

Paru is the Arch/CachyOS backend.

func NewParu

func NewParu() *Paru

NewParu returns a Paru backend using the real command runner.

func (*Paru) Absent

func (p *Paru) Absent(ctx context.Context, pkgs []string) error

Absent removes packages.

func (*Paru) IsInstalled

func (p *Paru) IsInstalled(ctx context.Context, pkg string) (bool, error)

IsInstalled checks if a package is installed via pacman.

func (*Paru) Present

func (p *Paru) Present(ctx context.Context, pkgs []string) error

Present installs packages idempotently.

type Runner

type Runner interface {
	Run(ctx context.Context, name string, args ...string) (string, error)
}

Runner runs a command and returns stdout; cancelling ctx kills the child process.

type Step

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

Step is the apply pipeline step for packages.

func NewStep

func NewStep(backend Backend, plan *resolve.Plan) *Step

NewStep creates a package step bound to a plan and backend.

func (*Step) Name

func (s *Step) Name() string

Name returns the step name.

func (*Step) Run

func (s *Step) Run(ctx context.Context) error

Run applies the package backend, removing absent packages first, then installing present ones.

Jump to

Keyboard shortcuts

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