Documentation
¶
Index ¶
- Constants
- Variables
- func DefaultSystem() string
- func MakeSystem(os OS, arch Arch) string
- type Arch
- type Client
- func (c *Client) Close() error
- func (c *Client) Eval(ctx context.Context, expr string, out any) (err error)
- func (c *Client) EvalFlakeOutput(ctx context.Context, f *flake.Flake, path []string, out any) error
- func (c *Client) EvalWithArgs(ctx context.Context, expr string, args, out any) error
- func (c *Client) GetFlakeOutputValue(ctx context.Context, f *flake.Flake, path []string) (*eval.Value, error)
- func (c *Client) OpenFlake(ref string, opts ...flake.Option) (*flake.Flake, error)
- func (c *Client) ProcessDaemonConnection(ctx context.Context, fromFD, toFD int, trusted, recursive bool) error
- func (c *Client) Realize(ctx context.Context, drvPath string) ([]RealizedOutput, error)
- func (c *Client) RealizeOutput(ctx context.Context, drvPath string, outputName string) (RealizedOutput, error)
- func (c *Client) Unmarshal(ctx context.Context, value *eval.Value, out any) error
- func (c *Client) WithEvaluator(ctx context.Context, handler func(*eval.Evaluator) error) error
- func (c *Client) WithStore(ctx context.Context, handler func(*store.Store) error) error
- func (c *Client) WithStoreAndEvaluator(ctx context.Context, handler func(*store.Store, *eval.Evaluator) error) error
- type ClientConfig
- type Error
- type ErrorCode
- type EvalConfig
- type ExperimentalFeature
- type LogFormat
- type OS
- type RealizedOutput
- type StoreConfig
- type Verbosity
Constants ¶
const ( // VerbosityDefault leaves the current Nix verbosity unchanged. VerbosityDefault = nixcontext.VerbosityDefault // VerbosityError shows only errors. VerbosityError = nixcontext.VerbosityError // VerbosityWarn shows warnings and errors. VerbosityWarn = nixcontext.VerbosityWarn // VerbosityNotice shows notices, warnings, and errors. VerbosityNotice = nixcontext.VerbosityNotice // VerbosityInfo shows informational messages. VerbosityInfo = nixcontext.VerbosityInfo // VerbosityTalkative shows talkative Nix logs. VerbosityTalkative = nixcontext.VerbosityTalkative // VerbosityChatty shows chatty Nix logs. VerbosityChatty = nixcontext.VerbosityChatty // VerbosityDebug shows debug Nix logs. VerbosityDebug = nixcontext.VerbosityDebug // VerbosityVomit shows the most verbose Nix logs. VerbosityVomit = nixcontext.VerbosityVomit )
const ( // LogFormatRaw writes raw log messages. LogFormatRaw = nixcontext.LogFormatRaw // LogFormatRawWithLogs writes raw log messages including log records. LogFormatRawWithLogs = nixcontext.LogFormatRawWithLogs // LogFormatInternalJSON writes Nix's internal JSON log format. LogFormatInternalJSON = nixcontext.LogFormatInternalJSON // LogFormatBar writes progress-bar formatted logs. LogFormatBar = nixcontext.LogFormatBar // LogFormatBarWithLogs writes progress-bar formatted logs including log records. LogFormatBarWithLogs = nixcontext.LogFormatBarWithLogs )
Variables ¶
var ErrClosed = status.ErrClosed
ErrClosed is returned when an operation is attempted after a wrapper has been closed.
var ErrConcurrentUse = errors.New("gonix: concurrent use of Client is not supported")
ErrConcurrentUse is returned when a Client operation overlaps another operation or Close call on the same Client.
Functions ¶
func DefaultSystem ¶
func DefaultSystem() string
DefaultSystem returns the Nix system identifier for the current Go runtime.
func MakeSystem ¶
MakeSystem constructs a Nix system identifier from OS and architecture.
Types ¶
type Arch ¶
type Arch string
Arch identifies the architecture component of a Nix system.
const ( // Arch386 identifies Go's 386 architecture as Nix i686. Arch386 Arch = ArchI686 // ArchAarch64 identifies 64-bit ARM. ArchAarch64 Arch = "aarch64" // ArchAarch64BE identifies big-endian 64-bit ARM. ArchAarch64BE Arch = "aarch64_be" // ArchArc identifies Synopsys ARC. ArchArc Arch = "arc" // ArchArm identifies generic ARM. ArchArm Arch = "arm" // ArchArmv5tel identifies ARMv5 little-endian. ArchArmv5tel Arch = "armv5tel" // ArchArmv6l identifies ARMv6 little-endian. ArchArmv6l Arch = "armv6l" // ArchArmv7a identifies ARMv7-A. ArchArmv7a Arch = "armv7a" // ArchArmv7l identifies ARMv7 little-endian. ArchArmv7l Arch = "armv7l" // ArchAvr identifies AVR. ArchAvr Arch = "avr" // ArchI686 identifies 32-bit x86. ArchI686 Arch = "i686" // ArchJavascript identifies JavaScript. ArchJavascript Arch = "javascript" // ArchLoong64 identifies Go's loong64 architecture as Nix loongarch64. ArchLoong64 Arch = ArchLoongArch64 // ArchLoongArch64 identifies LoongArch64. ArchLoongArch64 Arch = "loongarch64" // ArchM68k identifies Motorola 68000. ArchM68k Arch = "m68k" // ArchMicroBlaze identifies MicroBlaze. ArchMicroBlaze Arch = "microblaze" // ArchMicroBlazeEL identifies little-endian MicroBlaze. ArchMicroBlazeEL Arch = "microblazeel" // ArchMIPS identifies big-endian MIPS. ArchMIPS Arch = "mips" // ArchMIPS64 identifies big-endian MIPS64. ArchMIPS64 Arch = "mips64" // ArchMIPS64EL identifies little-endian MIPS64. ArchMIPS64EL Arch = "mips64el" // ArchMIPSEL identifies little-endian MIPS. ArchMIPSEL Arch = "mipsel" // ArchMIPSLE identifies Go's mipsle architecture as Nix mipsel. ArchMIPSLE Arch = ArchMIPSEL // ArchMMIX identifies MMIX. ArchMMIX Arch = "mmix" // ArchMSP430 identifies MSP430. ArchMSP430 Arch = "msp430" // ArchOR1K identifies OpenRISC 1000. ArchOR1K Arch = "or1k" // ArchPPC64 identifies Go's ppc64 architecture as Nix powerpc64. ArchPPC64 Arch = ArchPowerPC64 // ArchPPC64LE identifies Go's ppc64le architecture as Nix powerpc64le. ArchPPC64LE Arch = ArchPowerPC64LE // ArchPowerPC identifies PowerPC. ArchPowerPC Arch = "powerpc" // ArchPowerPC64 identifies 64-bit PowerPC. ArchPowerPC64 Arch = "powerpc64" // ArchPowerPC64LE identifies little-endian 64-bit PowerPC. ArchPowerPC64LE Arch = "powerpc64le" // ArchPowerPCLE identifies little-endian PowerPC. ArchPowerPCLE Arch = "powerpcle" // ArchRISCV32 identifies 32-bit RISC-V. ArchRISCV32 Arch = "riscv32" // ArchRISCV64 identifies 64-bit RISC-V. ArchRISCV64 Arch = "riscv64" // ArchRX identifies Renesas RX. ArchRX Arch = "rx" // ArchS390 identifies IBM S/390. ArchS390 Arch = "s390" // ArchS390X identifies IBM z/Architecture. ArchS390X Arch = "s390x" // ArchSH4 identifies SuperH SH-4. ArchSH4 Arch = "sh4" // ArchVC4 identifies VideoCore IV. ArchVC4 Arch = "vc4" // ArchWasm32 identifies 32-bit WebAssembly. ArchWasm32 Arch = "wasm32" // ArchWasm64 identifies 64-bit WebAssembly. ArchWasm64 Arch = "wasm64" // ArchX86_64 identifies 64-bit x86. ArchX86_64 Arch = "x86_64" )
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client owns the resources for high-level Nix workflows.
Client owns a hidden Nix context, a default store and evaluator, fetcher and flake settings. Flakes created through OpenFlake may be closed early by the caller and are otherwise closed by Client.Close. Client is not goroutine-safe and rejects overlapping operations with ErrConcurrentUse. Close releases owned resources in reverse dependency order.
func NewClient ¶
func NewClient(cfg ClientConfig) (*Client, error)
NewClient creates a flake-ready Client.
ClientConfig{} is a valid quick-start configuration. The returned Client owns all resources it creates and must be closed.
func (*Client) Close ¶
Close releases flakes created by the Client, followed by its evaluator, store, settings, and context.
Close is idempotent. It attempts every cleanup and joins multiple errors.
func (*Client) Eval ¶
Eval evaluates expr and decodes its result into out.
The out argument must be a non-nil pointer to a type supported by eval.Evaluator.Unmarshal. Use the eval package directly when the raw caller-owned Value or a custom diagnostic path is needed.
func (*Client) EvalFlakeOutput ¶
EvalFlakeOutput decodes a locked flake output selected by path into out.
Each path element names one exact Nix attribute; dots have no special meaning. An empty path decodes the complete flake output attribute set. The out argument must be a non-nil pointer to a type supported by eval.Evaluator.Unmarshal.
func (*Client) EvalWithArgs ¶ added in v1.4.0
EvalWithArgs evaluates expr as a function, applies args, and decodes its result into out.
Args may be nil, a boolean, string, integer, float, slice, or map with string keys. Slices and maps may contain nested combinations of those types. The out argument must be a non-nil pointer to a type supported by eval.Evaluator.Unmarshal.
func (*Client) GetFlakeOutputValue ¶
func (c *Client) GetFlakeOutputValue(ctx context.Context, f *flake.Flake, path []string) (*eval.Value, error)
GetFlakeOutputValue returns the flake output selected by path.
Each path element names one exact Nix attribute; dots have no special meaning. An empty path returns the complete flake output attribute set.
The returned Value is caller-owned and must be closed.
func (*Client) OpenFlake ¶
OpenFlake parses and locks ref.
The returned Flake may be closed early by the caller. If it remains open, Client.Close closes it before releasing the resources it borrows.
func (*Client) ProcessDaemonConnection ¶ added in v1.2.0
func (c *Client) ProcessDaemonConnection(ctx context.Context, fromFD, toFD int, trusted, recursive bool) error
ProcessDaemonConnection processes separate input and output file descriptors.
ProcessDaemonConnection duplicates both descriptors, sets the duplicates to blocking mode, and closes only the duplicates after Nix returns.
func (*Client) Realize ¶
Realize realizes every output of the derivation at drvPath.
Realize returns pure Go DTOs and closes the Nix store path handles produced by Nix before returning. The Client's store must support realization.
func (*Client) RealizeOutput ¶ added in v1.3.0
func (c *Client) RealizeOutput(ctx context.Context, drvPath string, outputName string) (RealizedOutput, error)
RealizeOutput realizes one named output of the derivation at drvPath.
RealizeOutput returns a pure Go DTO and closes the Nix store path handle produced by Nix before returning. The Client's store must support realization.
func (*Client) Unmarshal ¶
Unmarshal decodes value into out using the Client's evaluator.
Value must belong to this Client's evaluator. The out argument must be a non-nil pointer to a type supported by eval.Evaluator.Unmarshal.
func (*Client) WithEvaluator ¶
WithEvaluator runs handler with the Client's owned Evaluator.
The operation participates in Client cancellation and exclusive-use handling. The Evaluator is borrowed and must not be closed or retained by handler.
func (*Client) WithStore ¶
WithStore runs handler with the Client's owned Store.
The operation participates in Client cancellation and exclusive-use handling. The Store is borrowed and must not be closed or retained by handler.
func (*Client) WithStoreAndEvaluator ¶
func (c *Client) WithStoreAndEvaluator(ctx context.Context, handler func(*store.Store, *eval.Evaluator) error) error
WithStoreAndEvaluator runs handler with the Client's owned Store and Evaluator.
The operation participates in Client cancellation and exclusive-use handling. Both resources are borrowed and must not be closed or retained by handler.
type ClientConfig ¶
type ClientConfig struct {
// LoadConfig loads the user's Nix configuration during context bootstrap.
LoadConfig bool
// AllowImportFromDerivation enables import-from-derivation when true.
AllowImportFromDerivation bool
// AcceptFlakeConfig accepts settings supplied by flakes when true.
AcceptFlakeConfig bool
// PureEval enables pure evaluation when true.
PureEval bool
// Cores sets the number of cores exposed to builders when non-zero.
Cores int
// MaxJobs sets the maximum number of local build jobs when non-zero.
MaxJobs int
// System sets the Nix build system when non-empty.
System string
// EvalSystem sets the Nix evaluation system when non-empty.
EvalSystem string
// Verbosity sets Nix verbosity when not VerbosityDefault.
Verbosity Verbosity
// LogFormat sets the Nix log format when non-empty.
LogFormat LogFormat
// LogSinkPath sets the Nix log sink destination.
LogSinkPath string
// ExperimentalFeatures replaces the default feature list when non-empty.
ExperimentalFeatures []string
// Substituters sets substituter store URLs when non-empty.
Substituters []string
// TrustedPublicKeys sets trusted binary cache keys when non-empty.
TrustedPublicKeys []string
// Store configures the Client's owned default store.
Store StoreConfig
// Eval configures the Client's owned evaluator.
Eval EvalConfig
// RawSettings applies exact Nix setting values after typed fields and wins
// on key conflicts.
RawSettings map[string]string
}
ClientConfig configures Client creation.
The zero value preserves Nix defaults except that it enables nix-command and flakes, which are required by the Client flake workflow. Zero-value scalar fields are treated as unset. Use RawSettings to explicitly set false, zero, max-jobs=auto, or another exact Nix setting value.
func (ClientConfig) Serialize ¶
func (c ClientConfig) Serialize() map[string]string
Serialize returns the Nix settings represented by c.
Returned settings are detached from c. List fields are deduplicated, sorted, and joined with spaces. RawSettings is applied last.
type Error ¶
Error describes a Nix failure captured by gonix.
It is a stable, Go-native snapshot of a Nix context error: the status code, human-readable message, and any structured upstream Nix details that were available when the error was converted.
type ErrorCode ¶
ErrorCode identifies a Nix C API status code returned through gonix errors.
const ( // ErrorCodeOK reports that a Nix operation completed successfully. ErrorCodeOK ErrorCode = status.ErrorCodeOK // ErrorCodeUnknown reports a generic failure not described by a narrower code. ErrorCodeUnknown ErrorCode = status.ErrorCodeUnknown // ErrorCodeOverflow reports that a value did not fit in the requested representation. ErrorCodeOverflow ErrorCode = status.ErrorCodeOverflow // ErrorCodeKey reports a missing or invalid key, setting, attribute, or lookup name. ErrorCodeKey ErrorCode = status.ErrorCodeKey // ErrorCodeNix reports a structured upstream Nix exception. ErrorCodeNix ErrorCode = status.ErrorCodeNix // ErrorCodeRecoverable reports a failure that Nix classified as recoverable. ErrorCodeRecoverable ErrorCode = status.ErrorCodeRecoverable )
type EvalConfig ¶
type EvalConfig struct {
// Opts are passed to eval.New before Client installs its required flake
// settings integration.
Opts []eval.Option
}
EvalConfig configures the evaluator owned by Client.
type ExperimentalFeature ¶
type ExperimentalFeature = string
ExperimentalFeature is a Go-native Nix experimental feature name.
The type is open: use any newer Nix feature name before gonix adds a named constant.
const ( // ExperimentalFeatureNixCommand enables the modern nix command surface. ExperimentalFeatureNixCommand ExperimentalFeature = "nix-command" // ExperimentalFeatureFlakes enables flake evaluation support. ExperimentalFeatureFlakes ExperimentalFeature = "flakes" // ExperimentalFeatureFetchTree enables the fetch-tree experimental feature. ExperimentalFeatureFetchTree ExperimentalFeature = "fetch-tree" // ExperimentalFeatureCADerivations enables content-addressed derivations. ExperimentalFeatureCADerivations ExperimentalFeature = "ca-derivations" )
type OS ¶
type OS string
OS identifies the operating-system component of a Nix system.
const ( // OSAIX identifies IBM AIX. OSAIX OS = "aix" // OSAndroid identifies Android. OSAndroid OS = "android" // OSCygwin identifies Cygwin. OSCygwin OS = "cygwin" // OSDarwin identifies Darwin-based systems. OSDarwin OS = "darwin" // OSDragonFly identifies DragonFly BSD. OSDragonFly OS = "dragonfly" // OSFreeBSD identifies FreeBSD. OSFreeBSD OS = "freebsd" // OSGenode identifies Genode. OSGenode OS = "genode" // OSGHCJS identifies the GHCJS JavaScript target. OSGHCJS OS = "ghcjs" // OSHurd identifies GNU Hurd. OSHurd OS = "hurd" // OSIllumos identifies illumos. OSIllumos OS = "illumos" // OSIOS identifies iOS. OSIOS OS = "ios" // OSLinux identifies Linux. OSLinux OS = "linux" // OSMMIXWare identifies MMIXware. OSMMIXWare OS = "mmixware" // OSNetBSD identifies NetBSD. OSNetBSD OS = "netbsd" // OSNone identifies a bare-metal or freestanding target. OSNone OS = "none" // OSOpenBSD identifies OpenBSD. OSOpenBSD OS = "openbsd" // OSPlan9 identifies Plan 9. OSPlan9 OS = "plan9" // OSRedox identifies Redox. OSRedox OS = "redox" // OSSolaris identifies Solaris. OSSolaris OS = "solaris" // OSUEFI identifies UEFI. OSUEFI OS = "uefi" // OSWasi identifies WASI. OSWasi OS = "wasi" // OSWasip1 identifies Go's WASI preview 1 target. OSWasip1 OS = "wasip1" // OSWindows identifies Windows. OSWindows OS = "windows" )
type RealizedOutput ¶
type RealizedOutput struct {
OutputName string `json:"outputName"`
StorePath string `json:"storePath"`
RealPath string `json:"realPath"`
Name string `json:"name"`
Hash [20]byte `json:"hash"`
}
RealizedOutput describes one realized derivation output.
It contains only Go-owned data. Client.Realize and Client.RealizeOutput close the underlying Nix store path handles before returning this DTO.
type StoreConfig ¶
type StoreConfig struct {
// URI is the store URI. The empty value uses store.Auto.
URI string
// Opts are passed to store.New.
Opts []store.Option
}
StoreConfig configures the store owned by Client.
type Verbosity ¶
type Verbosity = nixcontext.Verbosity
Verbosity is a Go-native Nix verbosity level.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
example
command
|
|
|
Package eval wraps Nix evaluation states and values.
|
Package eval wraps Nix evaluation states and values. |
|
Package fetchers wraps Nix fetcher settings.
|
Package fetchers wraps Nix fetcher settings. |
|
Package flake provides owned locked flakes and access to their output values.
|
Package flake provides owned locked flakes and access to their output values. |
|
internal
|
|
|
Package nixcontext owns and initializes Nix C API contexts.
|
Package nixcontext owns and initializes Nix C API contexts. |
|
pkg
|
|
|
raw
Generated Go bindings for the Nix C API.
|
Generated Go bindings for the Nix C API. |
|
utils
Package utils provides shared adapters for values returned by pkg/raw.
|
Package utils provides shared adapters for values returned by pkg/raw. |
|
Package store wraps Nix store handles and store-backed operations.
|
Package store wraps Nix store handles and store-backed operations. |
|
Package storepath wraps Nix store path handles.
|
Package storepath wraps Nix store path handles. |