Documentation
¶
Index ¶
Constants ¶
const ( Version2_12 = "2.12.0" Version2_13 = "2.13.0" Version2_14 = "2.14.0" Version2_15 = "2.15.0" Version2_16 = "2.16.0" Version2_17 = "2.17.0" Version2_18 = "2.18.0" Version2_19 = "2.19.0" Version2_20 = "2.20.0" Version2_21 = "2.21.0" Version2_22 = "2.22.0" Version2_23 = "2.23.0" Version2_24 = "2.24.0" Version2_25 = "2.25.0" MinVersion = Version2_12 )
All major Nix versions supported by Devbox.
Variables ¶
var Default = &Nix{}
Default is the default Nix installation.
Functions ¶
func AtLeast ¶
AtLeast reports if the default Nix installation's version is equal to or newer than the given version. It returns false if it cannot determine the Nix version.
func SourceProfile ¶
SourceProfile adds environment variables from the Nix profile shell scripts to the current process's environment. This ensures that PATH contains the nix bin directory and that NIX_PROFILES and NIX_SSL_CERT_FILE are set.
For properly configured Nix installations, the user's login shell handles sourcing the profile and SourceProfile has no effect.
Types ¶
type Args ¶
type Args []any
Args is a slice of Cmd arguments.
func (Args) String ¶
String returns the arguments as a shell command, quoting arguments with spaces.
func (Args) StringSlice ¶
StringSlice formats each argument using fmt.Sprint.
type Cmd ¶
type Cmd struct { // Path is the absolute path to the nix executable. It is the only // mandatory field and must not be empty. Path string // Args are the command line arguments, including the command name in // Args[0]. Run formats each argument using [fmt.Sprint] before passing // them to Nix. Args Args Env []string Stdin io.Reader Stdout io.Writer Stderr io.Writer // Logger emits debug logs when the command starts and exits. If nil, it // defaults to [slog.Default]. Logger *slog.Logger // contains filtered or unexported fields }
Cmd is an external command that invokes a *Nix executable. It provides improved error messages, graceful cancellation, and debug logging via log/slog. Although it's possible to initialize a Cmd directly, calling the Command function or Nix.Command method is more typical.
Most methods and fields correspond to their exec.Cmd equivalent. See its documentation for more details.
func Command ¶
Command creates an arbitrary command using the Nix executable found in $PATH. It's the same as calling Nix.Command on the default Nix installation.
type Info ¶
type Info struct { // Name identifies the Nix implementation. It is usually "nix" but may // also be a fork like "lix". Name string // Version is the semantic Nix version string. Version string // System is the Nix system tuple. It follows the pattern <arch>-<os> // and does not use the same values as GOOS or GOARCH. Note that the Nix // system is configurable and may not represent the actual operating // system or architecture. System string // ExtraSystems are other systems that the current machine supports. // Usually set by the extra-platforms setting in nix.conf. ExtraSystems []string // Features are the capabilities that the Nix binary was compiled with. Features []string // SystemConfig is the path to the Nix system configuration file, // usually /etc/nix/nix.conf. SystemConfig string // UserConfigs is a list of paths to the user's Nix configuration files. UserConfigs []string // StoreDir is the path to the Nix store directory, usually /nix/store. StoreDir string // StateDir is the path to the Nix state directory, usually // /nix/var/nix. StateDir string // DataDir is the path to the Nix data directory, usually somewhere // within the Nix store. This field is empty for Nix versions <= 2.12. DataDir string }
Info contains information about a Nix installation.
type Installer ¶
type Installer struct { // Path is the path to the Nix installer. If it's empty, Download and // Install will automatically download the installer and set Path to the // downloaded file before returning. Path string }
Installer downloads and installs Nix.
type Nix ¶
type Nix struct { // Path is the absolute path to the nix executable. If it is empty, // nix commands use the executable found in $PATH. Path string // ExtraArgs are command line arguments to pass to every Nix command. ExtraArgs Args // Logger logs information at [slog.LevelDebug] about Nix command // starts and exits. If nil, it defaults to [slog.Default]. Logger *slog.Logger // contains filtered or unexported fields }
Nix provides an interface for interacting with Nix. The zero-value is valid and uses the first Nix executable found in $PATH.
func (*Nix) Command ¶
Command creates an arbitrary Nix command that uses the Path, ExtraArgs, Logger and other defaults from n.
func (*Nix) Info ¶
Info returns Nix version information. It caches the result after the first call, which means it won't reflect any configuration changes to Nix. Create a new Nix instance to retrieve uncached information.