Documentation
¶
Overview ¶
Package bootstrap provides configuration schema for repository setup.
The bootstrap configuration allows repository owners to specify which packages should be installed, installation profiles, platform-specific packages, and conflict resolution policies.
Index ¶
- func GetPackageNames(cfg Config) []string
- func GetProfile(cfg Config, profileName string) ([]string, error)
- func RepoConfigYAML() []byte
- func ResolveProfilePackages(profiles map[string]Profile, name string) ([]string, error)
- type Config
- type Defaults
- type FS
- type GenerateOptions
- type Generator
- type Layout
- type MachineRule
- type PackageSpec
- type Profile
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetPackageNames ¶
GetPackageNames extracts package names from configuration.
func GetProfile ¶
GetProfile retrieves packages for a named profile.
Profiles that declare extends inherit their parent chain packages, which are returned ahead of the profile's own packages.
Returns an error if the profile does not exist or its inheritance chain is broken.
func RepoConfigYAML ¶ added in v0.7.0
func RepoConfigYAML() []byte
RepoConfigYAML returns the repository configuration for a full-tree layout.
It is written to .config/dot/config.yaml in the repository so that every later dot command in that repository leaves package names alone.
func ResolveProfilePackages ¶ added in v0.7.0
ResolveProfilePackages returns the packages of a profile with inheritance applied.
A profile may declare a single parent through the extends field. The resolved package list is the union of the whole parent chain and the profile's own packages, ordered from the root ancestor down to the profile itself. Duplicate names are removed, keeping the earliest (most ancestral) occurrence.
Returns an error if:
- The profile does not exist
- Any profile in the chain extends an unknown profile
- The chain contains a cycle
Types ¶
type Config ¶
type Config struct {
// Version specifies the bootstrap config schema version.
Version string `yaml:"version"`
// Packages lists all available packages in the repository.
Packages []PackageSpec `yaml:"packages"`
// Profiles defines named sets of packages for different use cases.
Profiles map[string]Profile `yaml:"profiles,omitempty"`
// Machines maps host patterns to profiles, in evaluation order.
// The first entry whose pattern matches the hostname wins.
Machines []MachineRule `yaml:"machines,omitempty"`
// Defaults specifies default settings for installation.
Defaults Defaults `yaml:"defaults,omitempty"`
}
Config represents the bootstrap configuration for a dotfiles repository.
func Load ¶
Load reads and parses a bootstrap configuration file.
Returns an error if:
- File cannot be read
- YAML syntax is invalid
- Configuration validation fails
The configuration is automatically validated after loading.
func (Config) Validate ¶
Validate checks the configuration for errors.
Returns an error if:
- Version is missing or empty
- No packages are defined
- Package names are empty or duplicated
- Invalid platform names are used
- Invalid conflict policies are specified
- Profiles reference non-existent packages
- Profiles extend an unknown profile or form a cycle
- Default profile does not exist
- Machine entries have an empty or malformed host pattern
- Machine entries reference a non-existent profile
type Defaults ¶
type Defaults struct {
// ConflictPolicy is the default conflict resolution strategy.
// Valid values: fail, backup, overwrite, skip
ConflictPolicy string `yaml:"on_conflict"`
// Profile is the default profile to use if none specified.
Profile string `yaml:"profile"`
}
Defaults specifies default configuration values.
type GenerateOptions ¶
type GenerateOptions struct {
// FromManifest only includes packages present in manifest
FromManifest bool
// ConflictPolicy sets default conflict resolution policy
ConflictPolicy string
// IncludeComments adds helpful comments to generated config
IncludeComments bool
}
GenerateOptions configures bootstrap generation behavior.
type Generator ¶
type Generator struct{}
Generator creates bootstrap configurations from package information.
func NewGenerator ¶
func NewGenerator() *Generator
NewGenerator creates a new bootstrap configuration generator.
func (*Generator) Generate ¶
func (g *Generator) Generate(packages []string, installed []string, opts GenerateOptions) (Config, error)
Generate creates a bootstrap configuration from package information.
Parameters:
- packages: All discovered package names
- installed: Package names that are currently installed
- opts: Generation options
Returns a validated bootstrap configuration or an error.
func (*Generator) MarshalYAML ¶
MarshalYAML converts configuration to YAML bytes.
The output is formatted for human readability with proper indentation and ordering of fields.
type Layout ¶ added in v0.7.0
type Layout string
Layout describes how a dotfiles repository stores package contents.
const ( // LayoutPrefixed is the historical layout, where dotfiles are stored // with a dot- prefix, such as dot-vim/dot-vimrc. Package name mapping // translates those names on install. LayoutPrefixed Layout = "prefixed" // LayoutFullTree stores package contents as real dotfile paths, such as // nvim/.config/nvim/init.lua. Nothing needs translating, so package name // mapping must be turned off for the repository. LayoutFullTree Layout = "full-tree" )
func DetectLayout ¶ added in v0.7.0
DetectLayout classifies a repository from its packages.
The argument maps each package name to the names of its top-level entries. Detection is deliberately shallow, one directory level per package, and applies these rules in order:
- Any package name or top-level entry carrying the dot- prefix means the prefixed layout, even if other packages look like full trees.
- Otherwise, any top-level entry that is itself a dotfile, such as .config or .zshrc, means the full-tree layout.
- Anything else is reported as prefixed, the historical default.
type MachineRule ¶ added in v0.7.0
type MachineRule struct {
// Host is a glob pattern matched against the machine hostname.
// Pattern syntax is path.Match: * and ? and [class] ranges, with no
// special treatment of dots.
Host string `yaml:"host"`
// Profile names the profile applied on matching hosts.
Profile string `yaml:"profile"`
}
MachineRule maps a host pattern to a profile name.
Rules are an ordered list rather than a map because evaluation order is part of the semantics: patterns are allowed to overlap and the first matching rule wins. YAML mappings do not preserve order in Go, so a list is the only way to express that intent.
func ResolveMachineProfile ¶ added in v0.7.0
func ResolveMachineProfile(machines []MachineRule, hostname string) (MachineRule, bool)
ResolveMachineProfile returns the first machine rule matching the hostname.
Each pattern is matched against both the full hostname and its first label, so a rule for "hephaestus" matches "hephaestus.example.com" as well. Rules are evaluated in declaration order and the first match wins; a trailing "*" rule therefore acts as a catch-all.
Matching is case-insensitive: pattern and hostname are both lowercased first, so a pattern may be written in any case and character classes such as [A-C] match either case of the same letters.
Returns false when the hostname is empty or no rule matches.
type PackageSpec ¶
type PackageSpec struct {
// Name is the package directory name.
Name string `yaml:"name"`
// Required indicates if this package must be installed.
Required bool `yaml:"required"`
// Platform restricts installation to specific operating systems.
// Valid values: linux, darwin, windows, freebsd
Platform []string `yaml:"platform,omitempty"`
// ConflictPolicy specifies how to handle conflicts for this package.
// Valid values: fail, backup, overwrite, skip
ConflictPolicy string `yaml:"on_conflict,omitempty"`
}
PackageSpec defines a package and its installation requirements.
func FilterPackagesByPlatform ¶
func FilterPackagesByPlatform(packages []PackageSpec, platform string) []PackageSpec
FilterPackagesByPlatform returns packages compatible with the specified platform.
Packages with no platform restrictions are included for all platforms. Packages with platform restrictions are included only if the platform matches.
type Profile ¶
type Profile struct {
// Description provides human-readable explanation of the profile.
Description string `yaml:"description"`
// Extends names a single parent profile whose packages are inherited.
// Inherited packages come first, in parent chain order, followed by the
// packages declared on this profile.
Extends string `yaml:"extends,omitempty"`
// Packages lists the package names included in this profile.
Packages []string `yaml:"packages"`
}
Profile represents a named set of packages.