Documentation ¶
Overview ¶
Package nix provides Go API for nix. Internally this is a wrapper around the nix command line utilities. I'd love to use a go SDK instead, and drop the dependency on the CLI. The dependency means that users need to install nix, before using devbox. Unfortunately, that go sdk does not exist. We would have to implement it.
Index ¶
- Constants
- Variables
- func AllowInsecurePackages()
- func BinaryInstalled() bool
- func Build(ctx context.Context, args *BuildArgs, installables ...string) error
- func ComputeSystem() error
- func CopyInstallableToCache(ctx context.Context, out io.Writer, to, installable string, env []string) error
- func DaemonVersion(ctx context.Context) (string, error)
- func EnsureNixInstalled(writer io.Writer, withDaemonFunc func() *bool) (err error)
- func EnsureNixpkgsPrefetched(w io.Writer, commit string) error
- func EnsureValidPlatform(platforms ...string) error
- func Ensured() bool
- func Eval(path string) ([]byte, error)
- func EvalPackageName(path string) (string, error)
- func ExperimentalFlags() []string
- func FlakeNixpkgs(commit string) string
- func FlakeUpdate(ProfileDir string) error
- func HashFromNixPkgsURL(url string) string
- func IncludeDevboxConfig(ctx context.Context, username string) error
- func Install(writer io.Writer, daemon *bool) error
- func IsExitErrorInsecurePackage(err error, pkgNameOrEmpty, installableOrEmpty string) (bool, error)
- func IsGithubNixpkgsURL(url string) bool
- func IsInsecureAllowed() bool
- func PackageIsInsecure(path string) bool
- func PackageKnownVulnerabilities(path string) []string
- func PkgExistsForAnySystem(pkg string) bool
- func ProfileBinPath(projectDir string) string
- func ProfileInstall(ctx context.Context, args *ProfileInstallArgs) error
- func ProfileList(writer io.Writer, profilePath string, useJSON bool) (string, error)
- func ProfileRemove(profilePath string, packageNames ...string) error
- func ProfileUpgrade(ProfileDir, indexOrName string) error
- func RunScript(projectDir, cmdWithArgs string, env map[string]string) error
- func Search(url string) (map[string]*Info, error)
- func SearchNixpkgsAttribute(query string) (map[string]*Info, error)
- func SourceNixEnv() error
- func StorePathFromHashPart(ctx context.Context, hash, storeAddr string) (string, error)
- func StorePathsAreInStore(ctx context.Context, storePaths []string) (bool, error)
- func StorePathsFromInstallable(ctx context.Context, installable string, allowInsecure bool) ([]string, error)
- func System() string
- func SystemIsLinux() bool
- type BuildArgs
- type Config
- type ConfigField
- type DaemonError
- type Info
- type Nix
- type Nixer
- type PackageInstallWriter
- type PrintDevEnvArgs
- type PrintDevEnvOut
- type ProfileInstallArgs
- type StorePathParts
- type Variable
- type VersionInfo
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" MinVersion = Version2_12 )
All major Nix versions supported by Devbox.
const DefaultPriority = 5
const ProfilePath = ".devbox/nix/profile/default"
ProfilePath contains the contents of the profile generated via `nix-env --profile ProfilePath <command>` or `nix profile install --profile ProfilePath <package...>` Instead of using directory, prefer using the devbox.ProfileDir() function that ensures the directory exists.
Variables ¶
var ( ErrPackageNotFound = errors.New("package not found") ErrPackageNotInstalled = errors.New("package not installed") )
var ErrUnknownServiceManager = errors.New("unknown service manager")
Functions ¶
func AllowInsecurePackages ¶
func AllowInsecurePackages()
func BinaryInstalled ¶
func BinaryInstalled() bool
func ComputeSystem ¶
func ComputeSystem() error
func CopyInstallableToCache ¶
func DaemonVersion ¶
DaemonVersion returns the version of the currently running Nix daemon.
func EnsureNixInstalled ¶
func EnsureNixpkgsPrefetched ¶
EnsureNixpkgsPrefetched runs the prefetch step to download the flake of the registry
func EnsureValidPlatform ¶
EnsureValidPlatform returns an error if the platform is not supported by nix. https://nixos.org/manual/nix/stable/installation/supported-platforms.html
func Eval ¶
Eval is raw nix eval. Needs to be parsed. Useful for stuff like nix eval --raw nixpkgs/9ef09e06806e79e32e30d17aee6879d69c011037#fuse3 to determine if a package if a package can be installed in system.
func EvalPackageName ¶
func ExperimentalFlags ¶
func ExperimentalFlags() []string
func FlakeNixpkgs ¶
FlakeNixpkgs returns a flakes-compatible reference to the nixpkgs registry. TODO savil. Ensure this works with the nixed cache service.
func FlakeUpdate ¶
func HashFromNixPkgsURL ¶
HashFromNixPkgsURL will (for example) return 5233fd2ba76a3accb5aaa999c00509a11fd0793c from github:nixos/nixpkgs/5233fd2ba76a3accb5aaa999c00509a11fd0793c#hello
func Install ¶
Install runs the install script for Nix. daemon has 3 states nil is unset. false is --no-daemon. true is --daemon.
func IsGithubNixpkgsURL ¶
IsGithubNixpkgsURL returns true if the package is a flake of the form: github:NixOS/nixpkgs/...
While there are many ways to specify this input, devbox always uses github:NixOS/nixpkgs/<hash> as the URL. If the user wishes to reference nixpkgs themselves, this function may not return true.
func IsInsecureAllowed ¶
func IsInsecureAllowed() bool
func PackageIsInsecure ¶
PackageIsInsecure is a fun little nix eval that maybe works.
func PkgExistsForAnySystem ¶
PkgExistsForAnySystem is a bit slow (~600ms). Only use it if there's already been an error and we want to provide a better error message.
func ProfileBinPath ¶
Warning: be careful using the bins in default/bin, they won't always match bins produced by the flakes.nix. Use devbox.NixBins() instead.
func ProfileInstall ¶
func ProfileInstall(ctx context.Context, args *ProfileInstallArgs) error
func ProfileList ¶
func ProfileRemove ¶
ProfileRemove removes packages from a profile. WARNING, don't use indexes, they are not supported by nix 2.20+
func ProfileUpgrade ¶
func SearchNixpkgsAttribute ¶
SearchNixpkgsAttribute is a wrapper around searchSystem that caches results. NOTE: we should be very conservative in where we use this function. `nix search` accepts generalized `installable regex` as arguments but is slow. For certain queries of the form `nixpkgs/<commit-hash>#attribute`, we can know for sure that once `nix search` returns a valid result, it will always be the very same result. Hence we can cache it locally and answer future queries fast, by not calling `nix search`.
func SourceNixEnv ¶
func SourceNixEnv() error
func StorePathFromHashPart ¶
func StorePathsAreInStore ¶
StorePathsAreInStore returns true if the store path is in the store It relies on `nix store ls` to check if the store path is in the store
func SystemIsLinux ¶
func SystemIsLinux() bool
Types ¶
type Config ¶
type Config struct { ExperimentalFeatures ConfigField[[]string] `json:"experimental-features"` Substitute ConfigField[bool] `json:"substitute"` Substituters ConfigField[[]string] `json:"substituters"` System ConfigField[string] `json:"system"` TrustedSubstituters ConfigField[[]string] `json:"trusted-substituters"` TrustedUsers ConfigField[[]string] `json:"trusted-users"` }
Config is a parsed Nix configuration.
func CurrentConfig ¶
CurrentConfig reads the current Nix configuration.
type ConfigField ¶
type ConfigField[T any] struct { Value T `json:"value"` }
ConfigField is a Nix configuration setting.
type DaemonError ¶
type DaemonError struct {
// contains filtered or unexported fields
}
DaemonError reports an unsuccessful attempt to connect to the Nix daemon.
func (*DaemonError) Error ¶
func (e *DaemonError) Error() string
func (*DaemonError) Redact ¶
func (e *DaemonError) Redact() string
func (*DaemonError) Unwrap ¶
func (e *DaemonError) Unwrap() error
type Info ¶
type Nix ¶
type Nix struct{}
These make it easier to stub out nix for testing
func (*Nix) PrintDevEnv ¶
func (*Nix) PrintDevEnv(ctx context.Context, args *PrintDevEnvArgs) (*PrintDevEnvOut, error)
PrintDevEnv calls `nix print-dev-env -f <path>` and returns its output. The output contains all the environment variables and bash functions required to create a nix shell.
type Nixer ¶
type Nixer interface {
PrintDevEnv(ctx context.Context, args *PrintDevEnvArgs) (*PrintDevEnvOut, error)
}
type PackageInstallWriter ¶
type PrintDevEnvArgs ¶
type PrintDevEnvOut ¶
type ProfileInstallArgs ¶
type StorePathParts ¶
storePath are the constituent parts of /nix/store/<hash>-<name>-<version>
This is a helper struct for analyzing the string representation
func NewStorePathParts ¶
func NewStorePathParts(path string) StorePathParts
NewStorePathParts splits a Nix store path into its hash, name and version components in the same way that Nix does.
See https://nixos.org/manual/nix/stable/language/builtins.html#builtins-parseDrvName
TODO: store paths can also have `-{output}` suffixes, which need to be handled below.
type VersionInfo ¶
type VersionInfo struct { // Name is the executed program name (the first element of argv). Name string // Version is the semantic Nix version string. Version string // System is the current Nix system. It follows the pattern <arch>-<os> // and does not use the same values as GOOS or GOARCH. 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 }
VersionInfo contains information about a Nix installation.
func Version ¶
func Version() (VersionInfo, error)
Version returns the currently installed version of Nix.
func (VersionInfo) AtLeast ¶
func (v VersionInfo) AtLeast(version string) bool
AtLeast returns true if v.Version is >= version per semantic versioning. It always returns false if v.Version is empty or invalid, such as when the current Nix version cannot be parsed. It panics if version is an invalid semver.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package nixstore queries and resolves Nix store packages.
|
Package nixstore queries and resolves Nix store packages. |