Documentation
¶
Overview ¶
Package eval wraps Nix evaluation states and values.
The package exposes Go-native evaluators, values, builders, and realized strings over the generated pkg/raw expression API. Evaluators own the underlying Nix evaluation state and values are tied to the evaluator that created them.
Index ¶
- type Evaluator
- func (e *Evaluator) Attr(v *Value, name string) (*Value, error)
- func (e *Evaluator) AttrByIndex(v *Value, index uint32) (*Value, error)
- func (e *Evaluator) AttrLazy(v *Value, name string) (*Value, error)
- func (e *Evaluator) AttrName(v *Value, index uint32) (string, error)
- func (e *Evaluator) Borrow() (*raw.EvalState, error)
- func (e *Evaluator) Call(fn, arg *Value) (*Value, error)
- func (e *Evaluator) CallMulti(fn *Value, args ...*Value) (*Value, error)
- func (e *Evaluator) Close() error
- func (e *Evaluator) EvalString(expr, path string) (*Value, error)
- func (e *Evaluator) EvalWithArgs(expr, path string, arg any) (*Value, error)
- func (e *Evaluator) Force(v *Value) error
- func (e *Evaluator) ForceDeep(v *Value) error
- func (e *Evaluator) HasAttr(v *Value, name string) (bool, error)
- func (e *Evaluator) Index(v *Value, index uint32) (*Value, error)
- func (e *Evaluator) NewValue(gv GoValue) (*Value, error)
- func (e *Evaluator) RealiseString(v *Value) (*RealisedString, error)
- func (e *Evaluator) Unmarshal(v *Value, out any) error
- func (e *Evaluator) WrapValue(ptr *raw.NixValue) (*Value, error)
- type GoValue
- func Apply(fn, arg *Value) GoValue
- func Attrs(values map[string]GoValue) GoValue
- func Bool(value bool) GoValue
- func Copy(src *Value) GoValue
- func Float(value float64) GoValue
- func Int(value int64) GoValue
- func List(values ...GoValue) GoValue
- func Null() GoValue
- func PathString(value string) GoValue
- func String(value string) GoValue
- type InvalidUnmarshalError
- type MissingAttrError
- type Option
- type RealisedString
- type UnmarshalTypeError
- type UnsupportedTypeError
- type Value
- func (v *Value) AttrLen() (uint32, error)
- func (v *Value) Bool() (bool, error)
- func (v *Value) Borrow() (*raw.NixValue, error)
- func (v *Value) Close() error
- func (v *Value) Float() (float64, error)
- func (v *Value) Int() (int64, error)
- func (v *Value) ListLen() (uint32, error)
- func (v *Value) PathString() (string, error)
- func (v *Value) String() (string, error)
- func (v *Value) Type() (ValueType, error)
- func (v *Value) TypeName() (string, error)
- type ValueType
- type ValueTypeError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Evaluator ¶
type Evaluator struct {
// contains filtered or unexported fields
}
Evaluator owns a Nix evaluation state.
An Evaluator borrows the Store and Nix context used to create it. The store and context must outlive the evaluator. Evaluator is not goroutine-safe. Values returned by an Evaluator are caller-owned, tied to that evaluator, and must not be used with another evaluator. Callers should close every Value before closing the Evaluator.
func New ¶
New creates an evaluator using an initialized Nix context and open store.
The returned Evaluator owns the raw EvalState and borrows ctx and s. The caller must close the evaluator when finished.
func (*Evaluator) AttrByIndex ¶
AttrByIndex returns the caller-owned forced attribute value at index.
func (*Evaluator) Borrow ¶
Borrow returns the borrowed raw Nix evaluation state.
Callers must not free the returned pointer and must not retain it beyond the immediate raw Nix call that needs it. This is an escape hatch for integration with lower-level bindings.
func (*Evaluator) Close ¶
Close releases the owned EvalState.
Close is safe to call more than once. Once Close returns, methods that need the raw evaluation state and operations on Values created by e report status.ErrClosed. Caller-owned Values may still be closed while their Context remains open.
func (*Evaluator) EvalString ¶
EvalString evaluates a Nix expression string at path.
The path is used by Nix for diagnostics and relative path resolution. The returned Value is owned by the caller and must be closed.
func (*Evaluator) EvalWithArgs ¶ added in v1.4.0
EvalWithArgs evaluates expr as a function and applies arg.
Arg 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 path is used by Nix for diagnostics and relative path resolution. The returned Value is owned by the caller and must be closed.
func (*Evaluator) RealiseString ¶
func (e *Evaluator) RealiseString(v *Value) (*RealisedString, error)
RealiseString realizes v as a string and returns referenced store paths.
func (*Evaluator) Unmarshal ¶
Unmarshal decodes a Nix value into the Go value pointed to by out.
Struct fields are matched with the nix tag, or with the exact Go field name when no nix tag is present. Fields tagged nix:"-" are skipped. A missing field tagged validate:"required" returns a MissingAttrError; other missing fields are left unchanged. Extra Nix attributes are ignored.
func (*Evaluator) WrapValue ¶
WrapValue adopts an owned raw Nix value as a Value tied to e.
This is an integration point for sibling gonix packages that receive owned or refcounted values from lower-level Nix APIs. Callers transfer ownership of ptr to the returned Value and must not decref ptr directly after a successful call. The returned Value must be closed by the caller.
type GoValue ¶
GoValue initializes a Nix value from Go-native data.
Use the helper functions in this package, such as Int, String, List, and Attrs, to construct GoValue values for Evaluator.NewValue.
func PathString ¶
PathString returns a GoValue that initializes a Nix path string.
type InvalidUnmarshalError ¶
InvalidUnmarshalError describes an invalid target passed to Evaluator.Unmarshal.
func (*InvalidUnmarshalError) Error ¶
func (e *InvalidUnmarshalError) Error() string
type MissingAttrError ¶
MissingAttrError describes a required Nix attribute that was absent.
func (*MissingAttrError) Error ¶
func (e *MissingAttrError) Error() string
type Option ¶
type Option func(*config)
Option configures Evaluator creation.
func WithFlakeSettings ¶
func WithFlakeSettings(settings *flakesettings.Settings) Option
WithFlakeSettings adds flake evaluator integration to the state builder.
func WithLookupPath ¶
WithLookupPath sets the Nix evaluator lookup path.
Entries use Nix lookup-path syntax, for example "nixpkgs=/path/to/nixpkgs". Repeated options append entries in order.
type RealisedString ¶
type RealisedString struct {
// Value is the realized string content.
Value string
// Paths are owned store paths referenced by Value.
Paths []*storepath.Path
}
RealisedString is a Nix string with its referenced store paths.
RealiseString returns Go-owned string data and owned store path clones. Call Close when finished to release the paths.
func (*RealisedString) Close ¶
func (r *RealisedString) Close() error
Close releases every referenced store path.
Close attempts to close every path and returns a joined error if one or more closes fail. It is safe to call more than once.
type UnmarshalTypeError ¶
UnmarshalTypeError describes a Nix value that cannot be decoded into a Go type.
func (*UnmarshalTypeError) Error ¶
func (e *UnmarshalTypeError) Error() string
type UnsupportedTypeError ¶
UnsupportedTypeError describes a Go type that an Evaluator cannot convert to or from a Nix value.
func (*UnsupportedTypeError) Error ¶
func (e *UnsupportedTypeError) Error() string
type Value ¶
type Value struct {
// contains filtered or unexported fields
}
Value owns a reference to a Nix value.
Values are tied to the Evaluator that created them and must be closed by the caller before the Context. Value operations require the Evaluator to remain open. Close releases the owned value reference and is idempotent.
func (*Value) Borrow ¶
Borrow returns the borrowed raw Nix value handle.
Callers must not free the returned pointer and must not retain it beyond the immediate raw Nix call that needs it. This is an escape hatch for integration with lower-level bindings.
func (*Value) Close ¶
Close releases the owned Nix value reference.
Close is safe to call more than once. It may be called after the Evaluator is closed, but the Context must remain open. Once Close returns, methods that need the raw value handle report status.ErrClosed.
func (*Value) PathString ¶
PathString returns v as a Nix path string.
type ValueType ¶
type ValueType int
ValueType identifies a Nix value's runtime type.
const ( // ValueTypeThunk is a deferred Nix expression. ValueTypeThunk ValueType = iota // ValueTypeInt is a Nix integer. ValueTypeInt // ValueTypeFloat is a Nix floating-point number. ValueTypeFloat // ValueTypeBool is a Nix boolean. ValueTypeBool // ValueTypeString is a Nix string. ValueTypeString // ValueTypePath is a Nix path. ValueTypePath // ValueTypeNull is Nix null. ValueTypeNull // ValueTypeAttrs is a Nix attribute set. ValueTypeAttrs // ValueTypeList is a Nix list. ValueTypeList // ValueTypeFunction is a Nix function. ValueTypeFunction // ValueTypeExternal is an external value. ValueTypeExternal // ValueTypeFailed is a failed value. ValueTypeFailed )
type ValueTypeError ¶
type ValueTypeError struct {
// Actual is the value's runtime Nix type.
Actual ValueType
// Expected is the Nix type required by the getter.
Expected ValueType
}
ValueTypeError describes a Value getter called for the wrong Nix type.
func (*ValueTypeError) Error ¶
func (e *ValueTypeError) Error() string