nix

package
v0.0.0-...-b7a57f2 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddDir

func AddDir(dir string, dependencies []string) []string

AddDir add the dir path to .nix files specified in dependencies

func BuildDependencies

func BuildDependencies(deps []Dependency, cache *Cache) (err error)

BuildDependencies build nix dependencies and returns a <package>-<nix store path> map

dependencies can be either a package name ex. php or a path to .nix file nixpkgs can be empty which means it will use local nixpkgs channel or a link to desired revision ex. https://github.com/NixOS/nixpkgs/archive/eeefd01d4f630fcbab6588fe3e7fffe0690fbb20.tar.gz

func BuildEnvironment

func BuildEnvironment(deps []Dependency, nixpkgs string, cache *Cache, shellCache *ShellCache) (_ []string, err error)

BuildEnvironment is running nix-shell for a list of dependencies and fetch its whole environment

nix-shell --pure --keep NIX_SSL_CERT_FILE --keep SSL_CERT_FILE -p --command 'env' -E nixExpressionFromDeps

nix shell can be started with empty list of packages so this method works with empty deps as well

func DownloadURl

func DownloadURl() string

DownloadURl give nix download URL based on OS

func GenerateKey

func GenerateKey(dependency Dependency) (_ string, err error)

GenerateKey generates key for the cache for a Dependency

if it's a .nix file it will hash the nixpkgs + file contents if it's a package name will hash the packageName:nixpkgs content

func HashDependencies

func HashDependencies(deps []Dependency) (_ string, err error)

func IsInstalled

func IsInstalled() bool

IsInstalled checks if nix is installed on the system

Types

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

func NewCacheStore

func NewCacheStore(opts ...CacheOption) (_ *Cache, err error)

NewCacheStore initialize a Nix cache store inside dir

func (*Cache) Clean

func (c *Cache) Clean() (err error)

func (*Cache) Close

func (c *Cache) Close() error

Close closes the file used in cache

func (*Cache) Get

func (c *Cache) Get(key string) (string, bool)

Get value from cache by its key Additionally also checks if path exists on the system

func (*Cache) Save

func (c *Cache) Save(key string, storePath string) (err error)

Save dependency inside the cache with its corresponding store path

type CacheOption

type CacheOption func(f *Cache)

func WithPath

func WithPath(path string) CacheOption

WithPath adds a custom file path which is used to store cache content on the filesystem.

type Dependency

type Dependency struct {
	// Name of the dependency
	Name string
	// Nixpkgs can be empty or a link to desired revision
	// ex. https://github.com/NixOS/nixpkgs/archive/eeefd01d4f630fcbab6588fe3e7fffe0690fbb20.tar.gz
	Nixpkgs string
}

func AppendUnique

func AppendUnique(a []Dependency, x Dependency) []Dependency

func UniqueDeps

func UniqueDeps(s []Dependency) []Dependency

UniqueDeps removes duplicates from the list by checking against name-nixpkgs key

type ShellCache

type ShellCache struct {
	// contains filtered or unexported fields
}

ShellCache caches the output of nix-shell command

func NewShellCache

func NewShellCache(dir string) *ShellCache

NewShellCache creates a new instance of ShellCache

func (*ShellCache) Clean

func (c *ShellCache) Clean() (err error)

Clean will clean entire shell env cache

func (*ShellCache) GenerateKey

func (c *ShellCache) GenerateKey(deps []Dependency, nixShellCmd string) (_ string, err error)

GenerateKey generates key for the cache based on a list of Dependency and nix-shell command

if Dependency it's a .nix file it will hash the nixpkgs + file contents if Dependency it's a package name will hash the packageName:nixpkgs content

func (*ShellCache) Get

func (c *ShellCache) Get(key string) ([]byte, bool)

Get the data by cache key If Reading the file returns an error, empty data is returned

func (*ShellCache) Save

func (c *ShellCache) Save(key string, output []byte) (err error)

Save caches the output inside a file named by the key cache

Jump to

Keyboard shortcuts

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