nix

package
v0.0.0-...-b872246 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 14, 2023 License: Apache-2.0 Imports: 30 Imported by: 0

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

View Source
const DefaultPriority = 5
View Source
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

View Source
var (
	ErrPackageNotFound     = errors.New("package not found")
	ErrPackageNotInstalled = errors.New("package not installed")
)

Functions

func AllowInsecurePackages

func AllowInsecurePackages()

func BinaryInstalled

func BinaryInstalled() bool

func ComputeSystem

func ComputeSystem() error

func EnsureNixInstalled

func EnsureNixInstalled(writer io.Writer, withDaemonFunc func() *bool) (err error)

func EnsureNixpkgsPrefetched

func EnsureNixpkgsPrefetched(w io.Writer, commit string) error

EnsureNixpkgsPrefetched runs the prefetch step to download the flake of the registry

func EnsureValidPlatform

func EnsureValidPlatform(platforms ...string) error

EnsureValidPlatform returns an error if the platform is not supported by nix. https://nixos.org/manual/nix/stable/installation/supported-platforms.html

func Eval

func Eval(path string) ([]byte, error)

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 EvalPackageName(path string) (string, error)

func ExperimentalFlags

func ExperimentalFlags() []string

func FlakeNixpkgs

func FlakeNixpkgs(commit string) string

FlakeNixpkgs returns a flakes-compatible reference to the nixpkgs registry. TODO savil. Ensure this works with the nixed cache service.

func FlakeUpdate

func FlakeUpdate(ProfileDir string) error

func HashFromNixPkgsURL

func HashFromNixPkgsURL(url string) string

HashFromNixPkgsURL will (for example) return 5233fd2ba76a3accb5aaa999c00509a11fd0793c from github:nixos/nixpkgs/5233fd2ba76a3accb5aaa999c00509a11fd0793c#hello

func Install

func Install(writer io.Writer, daemon *bool) error

Install runs the install script for Nix. daemon has 3 states nil is unset. false is --no-daemon. true is --daemon.

func IsGithubNixpkgsURL

func IsGithubNixpkgsURL(url string) bool

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

func PackageIsInsecure(path string) bool

PackageIsInsecure is a fun little nix eval that maybe works.

func PackageKnownVulnerabilities

func PackageKnownVulnerabilities(path string) []string

func PkgExistsForAnySystem

func PkgExistsForAnySystem(pkg string) bool

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

func ProfileBinPath(projectDir string) string

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(writer io.Writer, profilePath, installable string) error

func ProfileList

func ProfileList(writer io.Writer, profilePath string, useJSON bool) (string, error)

func ProfileRemove

func ProfileRemove(profilePath string, indexes []string) error

func ProfileUpgrade

func ProfileUpgrade(ProfileDir string, idx int) error

func RunScript

func RunScript(projectDir, cmdWithArgs string, env map[string]string) error
func Search(url string) (map[string]*Info, error)

func SourceNixEnv

func SourceNixEnv() error

func StorePathFromHashPart

func StorePathFromHashPart(ctx context.Context, hash, storeAddr string) (string, error)

func System

func System() string

func Version

func Version() (string, error)

Version returns the version of nix from `nix --version`. Usually in a semver like format, but not strictly.

Types

type Info

type Info struct {
	// attribute key is different in flakes vs legacy so we should only use it
	// if we know exactly which version we are using
	AttributeKey string
	PName        string
	Summary      string
	Version      string
}

func (*Info) String

func (i *Info) String() string

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 PackageInstallWriter struct {
	io.Writer
}

func (*PackageInstallWriter) Write

func (fw *PackageInstallWriter) Write(p []byte) (n int, err error)

type PrintDevEnvArgs

type PrintDevEnvArgs struct {
	FlakeDir             string
	PrintDevEnvCachePath string
	UsePrintDevEnvCache  bool
}

type PrintDevEnvOut

type PrintDevEnvOut struct {
	Variables map[string]Variable // the key is the name.
}

type Variable

type Variable struct {
	Type  string // valid types are var, exported, and array.
	Value any    // can be a string or an array of strings (iff type is array).
}

Directories

Path Synopsis
Package nixstore queries and resolves Nix store packages.
Package nixstore queries and resolves Nix store packages.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL