Documentation
¶
Overview ¶
Package lockfile implements the unirtm.lock file format — a multi-platform snapshot of resolved tool versions, download URLs, and checksums.
The format is TOML-based and intentionally compatible with the mise.lock schema so that projects can reuse the same lockfile understanding across tools.
Example:
# @generated - this file is auto-generated by `unirtm lock` [[tools.cli]] version = "2.72.0" backend = "github:cli/cli" [tools.cli."platforms.linux-amd64"] checksum = "sha256:abc123..." size = 12345678 url = "https://github.com/cli/cli/releases/download/v2.72.0/gh_2.72.0_linux_amd64.tar.gz" url_api = "https://api.github.com/repos/cli/cli/releases/assets/123456"
Index ¶
- Constants
- Variables
- func CurrentPlatformKey() string
- func IsValidPlatformKey(key string) bool
- func NormalizePlatformKey(raw string) (string, error)
- func ParsePlatformKey(key string) (goos, goarch string, musl bool, err error)
- func ParsePlatformKeys(input string) ([]string, error)
- func PlatformKey(goos, goarch string, musl bool) string
- func ToolKey(backendName, toolName string) string
- type LockFile
- func (lf *LockFile) CheckStrict(required []LockRequirement) error
- func (lf *LockFile) GetEntry(key, version string) *ToolLockEntry
- func (lf *LockFile) GetPlatform(key, version, platformKey string) *PlatformEntry
- func (lf *LockFile) HasURL(key, version, platformKey string) bool
- func (lf *LockFile) IsEmpty() bool
- func (lf *LockFile) Path() string
- func (lf *LockFile) RemoveEntry(key string)
- func (lf *LockFile) Save() error
- func (lf *LockFile) UpsertEntry(key string, entry *ToolLockEntry)
- func (lf *LockFile) UpsertPlatform(key, version, platformKey string, pe *PlatformEntry)
- func (lf *LockFile) Validate() error
- type LockRequirement
- type PlatformEntry
- type ToolLockEntry
- type ValidationError
Constants ¶
const Header = "# @generated - this file is auto-generated by `unirtm lock`\n" +
"# Do not edit manually. See https://github.com/snowdreamtech/unirtm for details.\n"
Header is written at the top of every generated lockfile.
Variables ¶
var StandardPlatforms = []string{
"linux-amd64",
"linux-amd64-musl",
"linux-arm64",
"linux-arm64-musl",
"macos-amd64",
"macos-arm64",
"windows-amd64",
"windows-arm64",
}
StandardPlatforms is the canonical list of platforms that `unirtm lock --all-platforms` will resolve. These mirror the platform keys used in mise.lock.
Functions ¶
func CurrentPlatformKey ¶
func CurrentPlatformKey() string
CurrentPlatformKey returns the platform key for the running OS/arch, e.g. "linux-amd64", "macos-arm64", "windows-amd64".
func IsValidPlatformKey ¶
IsValidPlatformKey reports whether key is a recognised standard platform key.
func NormalizePlatformKey ¶
NormalizePlatformKey lower-cases and validates a user-supplied platform key. It accepts both "linux-x64" (mise-style) and "linux-amd64" (unirtm-style) forms.
func ParsePlatformKey ¶
ParsePlatformKey parses a canonical platform key back into (goos, goarch, musl). Returns an error for keys that do not follow the expected format.
func ParsePlatformKeys ¶
ParsePlatformKeys parses a comma-separated list of platform keys (user input), normalising each one and deduplicating.
func PlatformKey ¶
PlatformKey builds a canonical lockfile platform key from GOOS/GOARCH components.
PlatformKey("linux", "amd64", false) → "linux-amd64"
PlatformKey("darwin", "arm64", false) → "macos-arm64"
PlatformKey("windows", "amd64", false) → "windows-amd64"
PlatformKey("linux", "amd64", true) → "linux-amd64-musl"
Types ¶
type LockFile ¶
type LockFile struct {
// Tools maps a canonical key ("backend:tool") → list of entries.
// In the common case there is exactly one entry per tool key.
Tools map[string][]*ToolLockEntry `toml:"tools"`
// contains filtered or unexported fields
}
LockFile is the in-memory representation of a unirtm.lock file. It maps a canonical tool key to one or more ToolLockEntry records. Multiple entries per tool are an edge case (e.g. different options sets), mirroring the [[tools.name]] array-of-tables TOML syntax from mise.
func Load ¶
Load reads and parses path as a unirtm.lock TOML file. Returns a new empty LockFile (not an error) when path does not exist, which allows callers to handle the "first run" case uniformly.
func (*LockFile) CheckStrict ¶
func (lf *LockFile) CheckStrict(required []LockRequirement) error
CheckStrict verifies that the lockfile contains a valid entry for each tool/platform pair in the required set. For URL-based backends, it ensures a URL is present. Used to enforce UNIRTM_LOCKED=1 / settings.locked=true.
required is a slice of (toolKey, version, platformKey) tuples.
func (*LockFile) GetEntry ¶
func (lf *LockFile) GetEntry(key, version string) *ToolLockEntry
GetEntry returns the first ToolLockEntry for key that matches the given version. GetEntry returns the ToolLockEntry for a given key and version. If version is empty, any version matches. Returns nil when not found.
func (*LockFile) GetPlatform ¶
func (lf *LockFile) GetPlatform(key, version, platformKey string) *PlatformEntry
GetPlatform returns the PlatformEntry for (key, version, platformKey). Returns nil when not found.
func (*LockFile) HasURL ¶
HasURL reports whether the lockfile contains a download URL for the given (key, version, platformKey) combination. Used by strict-mode enforcement.
func (*LockFile) RemoveEntry ¶
RemoveEntry removes all entries for key (tool eviction, e.g. after uninstall).
func (*LockFile) Save ¶
Save serialises the LockFile to its bound path atomically (write-temp + rename).
func (*LockFile) UpsertEntry ¶
func (lf *LockFile) UpsertEntry(key string, entry *ToolLockEntry)
UpsertEntry creates or updates the ToolLockEntry for key+version. If an entry for key+version already exists it is updated in place; otherwise a new entry is appended to lf.Tools[key].
func (*LockFile) UpsertPlatform ¶
func (lf *LockFile) UpsertPlatform(key, version, platformKey string, pe *PlatformEntry)
UpsertPlatform creates or updates a single PlatformEntry inside an existing (or newly created) ToolLockEntry.
type LockRequirement ¶
type LockRequirement struct {
ToolKey string // e.g. "github:cli/cli"
Version string // e.g. "2.72.0"
PlatformKey string // e.g. "linux-amd64"
}
LockRequirement describes a (tool, version, platform) combination that must be present in the lockfile under strict mode.
type PlatformEntry ¶
type PlatformEntry struct {
// Checksum is the hex digest with algorithm prefix: "sha256:<hex>" or "blake3:<hex>".
// Empty when the backend does not provide checksums.
Checksum string `toml:"checksum,omitempty"`
// Size is the artifact size in bytes (0 = unknown).
Size int64 `toml:"size,omitempty"`
// URL is the direct download URL.
URL string `toml:"url,omitempty"`
// URLAPI is the backend API URL for the asset (GitHub Releases asset API, etc.).
// Stored for cache-bypass installs that need the canonical API reference.
URLAPI string `toml:"url_api,omitempty"`
// GPGKey is the hex fingerprint of the trusted GPG key for this artifact.
GPGKey string `toml:"gpg_key,omitempty"`
}
PlatformEntry holds the resolved artifact metadata for a single platform.
type ToolLockEntry ¶
type ToolLockEntry struct {
// Version is the resolved, exact version string (e.g. "2.72.0").
Version string `toml:"version"`
// Backend is the backend name used to install this tool (e.g. "github", "ubi").
Backend string `toml:"backend"`
// Options holds backend-specific options that affect artifact selection,
// e.g. {"exe": "rg", "matching": "musl"} for ubi.
// omitempty so that empty maps are not serialised.
Options map[string]string `toml:"options,omitempty"`
// Platforms maps a platform key (e.g. "linux-amd64") to its artifact entry.
// We use toml:"-" here because the mise format stores these as top-level
// keys in the tool table with a "platforms." prefix, e.g. ["platforms.linux-amd64"].
Platforms map[string]*PlatformEntry `toml:"-"`
}
ToolLockEntry corresponds to one [[tools."<key>"]] TOML table.
type ValidationError ¶
type ValidationError struct {
Errors []string
}
ValidationError accumulates multiple lockfile validation issues.
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string