Documentation ¶
Overview ¶
Package nix provides functions and types for interoperating with Nix.
Index ¶
- Constants
- func CompressHash(dst, src []byte)
- func GenerateKey(name string, rand io.Reader) (*PublicKey, *PrivateKey, error)
- func VerifyNARInfo(trusted []*PublicKey, info *NARInfo, sig *Signature) error
- type CacheInfo
- type CompressionType
- type ContentAddress
- func (ca ContentAddress) Equal(ca2 ContentAddress) bool
- func (ca ContentAddress) Hash() Hash
- func (ca ContentAddress) IsFixed() bool
- func (ca ContentAddress) IsRecursiveFile() bool
- func (ca ContentAddress) IsText() bool
- func (ca ContentAddress) IsZero() bool
- func (ca ContentAddress) MarshalText() ([]byte, error)
- func (ca ContentAddress) String() string
- func (ca *ContentAddress) UnmarshalText(data []byte) error
- type Hash
- func (h Hash) Base16() string
- func (h Hash) Base32() string
- func (h Hash) Base64() string
- func (h Hash) Bytes(dst []byte) []byte
- func (h Hash) Equal(h2 Hash) bool
- func (h Hash) IsZero() bool
- func (h Hash) MarshalText() ([]byte, error)
- func (h Hash) RawBase16() string
- func (h Hash) RawBase32() string
- func (h Hash) RawBase64() string
- func (h Hash) SRI() string
- func (h Hash) String() string
- func (h Hash) Type() HashType
- func (h *Hash) UnmarshalText(s []byte) error
- type HashType
- type Hasher
- type NARInfo
- func (info *NARInfo) AddSignatures(sigs ...*Signature)
- func (info *NARInfo) Clone() *NARInfo
- func (info *NARInfo) IsValid() bool
- func (info *NARInfo) MarshalText() ([]byte, error)
- func (info *NARInfo) StoreDirectory() StoreDirectory
- func (info *NARInfo) UnmarshalText(src []byte) (err error)
- func (info *NARInfo) WriteFingerprint(w io.Writer) error
- type PrivateKey
- type PublicKey
- type Signature
- type StoreDirectory
- type StorePath
- func (path StorePath) Base() string
- func (path StorePath) Digest() string
- func (path StorePath) Dir() StoreDirectory
- func (path StorePath) IsDerivation() bool
- func (path StorePath) MarshalText() ([]byte, error)
- func (path StorePath) Name() string
- func (path *StorePath) UnmarshalText(data []byte) error
Examples ¶
Constants ¶
const CacheInfoMIMEType = "text/x-nix-cache-info"
CacheInfoMIMEType is the MIME content type for the nix-cache-info file.
const CacheInfoName = "nix-cache-info"
CacheInfoName is the name of the binary cache resource that contains its CacheInfo.
const NARInfoExtension = ".narinfo"
NARInfoExtension is the file extension for a file containing NAR information.
const NARInfoMIMEType = "text/x-nix-narinfo"
NARInfoMIMEType is the MIME content type for a .narinfo file.
Variables ¶
This section is empty.
Functions ¶
func CompressHash ¶
func CompressHash(dst, src []byte)
CompressHash compresses the src byte slice (usually a hash digest) into the given dst byte slice by cyclically XORing bytes together. If len(dst) >= len(src), dst[:len(src)] will be a copy of src and dst[len(src):] will not be modified.
func GenerateKey ¶
GenerateKey generates a Nix signing key using entropy from rand. If rand is nil, crypto/rand.Reader will be used.
Types ¶
type CacheInfo ¶
type CacheInfo struct { // StoreDirectory is the location of the store. // Defaults to [DefaultStoreDirectory] if empty. StoreDirectory StoreDirectory // Priority is the priority of the store when used as a substituter. // Lower values mean higher priority. Priority int // WantMassQuery indicates whether this store (when used as a substituter) // can be queried efficiently for path validity. WantMassQuery bool }
CacheInfo holds various settings about a Nix binary cache.
func (*CacheInfo) MarshalText ¶
MarshalText formats the binary cache information in the format of a nix-cache-info file.
func (*CacheInfo) UnmarshalText ¶
UnmarshalText parses the binary cache information from a nix-cache-info file.
type CompressionType ¶
type CompressionType string
CompressionType is an enumeration of compression algorithms used in NARInfo.
const ( NoCompression CompressionType = "none" Gzip CompressionType = "gzip" Bzip2 CompressionType = "bzip2" XZ CompressionType = "xz" Zstandard CompressionType = "zstd" Lzip CompressionType = "lzip" LZ4 CompressionType = "lz4" Brotli CompressionType = "br" )
Compression types.
func (CompressionType) IsKnown ¶
func (ct CompressionType) IsKnown() bool
IsKnown reports whether ct is one of the known compression types.
type ContentAddress ¶
type ContentAddress struct {
// contains filtered or unexported fields
}
A ContentAddress is a content-addressability assertion.
func FlatFileContentAddress ¶
func FlatFileContentAddress(h Hash) ContentAddress
FlatFileContentAddress returns a content address for a flat, fixed-output derivation with the given hash.
func ParseContentAddress ¶
func ParseContentAddress(s string) (ContentAddress, error)
ParseContentAddress parses a content address in the form of "text:<ht>:<sha256 hash of file contents>" or "fixed<:r?>:<ht>:<h>".
func RecursiveFileContentAddress ¶
func RecursiveFileContentAddress(h Hash) ContentAddress
RecursiveFileContentAddress returns a content address for a recursive (NAR), fixed-output derivation with the given hash.
func TextContentAddress ¶
func TextContentAddress(h Hash) ContentAddress
TextContentAddress returns a content address for a "text" filesystem object with the given hash.
func (ContentAddress) Equal ¶
func (ca ContentAddress) Equal(ca2 ContentAddress) bool
Equal reports whether ca == ca2.
func (ContentAddress) Hash ¶
func (ca ContentAddress) Hash() Hash
Hash returns the hash part of the content address.
func (ContentAddress) IsFixed ¶
func (ca ContentAddress) IsFixed() bool
IsFixed reports whether the content address is for a fixed-output derivation.
func (ContentAddress) IsRecursiveFile ¶
func (ca ContentAddress) IsRecursiveFile() bool
IsRecursiveFile reports whether the content address is for a fixed-output derivation with recursive (NAR) hashing.
func (ContentAddress) IsText ¶
func (ca ContentAddress) IsText() bool
IsText reports whether the content address is for a "text" filesystem object.
func (ContentAddress) IsZero ¶
func (ca ContentAddress) IsZero() bool
IsZero reports whether the content address is the zero value.
func (ContentAddress) MarshalText ¶
func (ca ContentAddress) MarshalText() ([]byte, error)
MarshalText formats the content address in the same way as ContentAddress.String. It returns an error if ca is the zero value.
func (ContentAddress) String ¶
func (ca ContentAddress) String() string
String formats the content address as either "text:<ht>:<sha256 hash of file contents>" or "fixed<:r?>:<ht>:<h>". It returns the empty string if ca is the zero value.
func (*ContentAddress) UnmarshalText ¶
func (ca *ContentAddress) UnmarshalText(data []byte) error
UnmarshalText parses a string in the same way as ParseContentAddress.
type Hash ¶
type Hash struct {
// contains filtered or unexported fields
}
A Hash is an output of a hash algorithm. The zero value is an empty hash with no type.
func NewHash ¶
NewHash returns a new hash with the given type and raw bytes. NewHash panics if the type is invalid or the length of the raw bytes do not match the type's length.
func ParseHash ¶
ParseHash parses a hash in the format "<type>:<base16|base32|base64>" or "<type>-<base64>" (a Subresource Integrity hash expression). It is a wrapper around Hash.UnmarshalText.
func (Hash) Base16 ¶
Base16 encodes the hash with base16 (i.e. hex) prefixed by the hash type separated by a colon.
func (Hash) Base32 ¶
Base32 encodes the hash with base32 prefixed by the hash type separated by a colon.
func (Hash) Base64 ¶
Base64 encodes the hash with base64 prefixed by the hash type separated by a colon.
func (Hash) MarshalText ¶
MarshalText formats the hash as a Subresource Integrity hash expression (e.g. "sha256-47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU="). It returns an error if h is the zero Hash.
func (Hash) SRI ¶
SRI returns the hash in the format of a Subresource Integrity hash expression (e.g. "sha256-47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=").
func (*Hash) UnmarshalText ¶
UnmarshalText parses a hash in the format "<type>:<base16|base32|base64>" or "<type>-<base64>" (a Subresource Integrity hash expression).
type HashType ¶
type HashType int8
HashType is an enumeration of algorithms supported by Hash.
Hash algorithms. Applications must not depend on the exact numeric values.
func ParseHashType ¶
ParseHashType matches a string to its hash type, returning an error if the string does not name a hash type.
type Hasher ¶
type Hasher struct {
// contains filtered or unexported fields
}
Hasher is a common interface for hash algorithms to produce Hash values from byte streams. Hasher implements hash.Hash.
Example ¶
package main import ( "fmt" "io" "zombiezen.com/go/nix" ) func main() { h := nix.NewHasher(nix.SHA256) io.WriteString(h, "Hello, World!\n") fmt.Println(h.SumHash()) }
Output: sha256-yYwktnfv9Ehgr+pvSTu67FuxxMuyCcb8K7tH9m/yrTE=
func NewHasher ¶
NewHasher returns a new Hasher object for the given algorithm. NewHasher panics if the hash type is invalid.
func (*Hasher) Size ¶
Size returns the number of bytes Hasher.Sum will return.
func (*Hasher) Sum ¶
Sum appends the current hash to b and returns the resulting slice. It does not change the underlying hash state.
func (*Hasher) SumHash ¶
SumHash returns the current Hash value. It does not change the underlying hash state.
type NARInfo ¶
type NARInfo struct { // StorePath is the absolute path of this store object // (e.g. "/nix/store/s66mzxpvicwk07gjbjfw9izjfa797vsw-hello-2.12.1"). // Nix requires this field to be set. StorePath StorePath // URL is the path to download to the (possibly compressed) .nar file, // relative to the .narinfo file's directory. // Nix requires this field to be set. URL string // Compression is the algorithm used for the file referenced by URL. // If empty, defaults to "bzip2". Compression CompressionType // FileHash is the hash of the file referenced by URL. // If Compression is [NoCompression] and FileHash is the zero hash, // then NARHash will be used. FileHash Hash // FileSize is the size of the file referenced by URL in bytes. // If Compression is [NoCompression] and FileSize is zero, // then NARSize will be used. FileSize int64 // NARHash is the hash of the decompressed .nar file. // Nix requires this field to be set. NARHash Hash // NARSize is the size of the decompressed .nar file in bytes. // Nix requires this field to be set. NARSize int64 // References is the set of other store objects that this store object references. References []StorePath // Deriver is the name of the store object that is the store derivation // of this store object. Deriver StorePath // System is a deprecated field. // // Deprecated: Ignore this field. System string // Sig is a set of signatures for this object. Sig []*Signature // CA is an optional content-addressability assertion. CA ContentAddress }
NARInfo represents a parsed .narinfo file.
func (*NARInfo) AddSignatures ¶
AddSignatures adds signatures that are not already present in info.
func (*NARInfo) MarshalText ¶
MarshalText encodes the information as a .narinfo file.
func (*NARInfo) StoreDirectory ¶
func (info *NARInfo) StoreDirectory() StoreDirectory
Directory returns the store directory of the store object.
func (*NARInfo) UnmarshalText ¶
UnmarshalText decodes a .narinfo file.
type PrivateKey ¶
type PrivateKey struct {
// contains filtered or unexported fields
}
A PrivateKey is a Nix private signing key. It is used to produce a Signature for a Nix store object (represented by NARInfo).
func ParsePrivateKey ¶
func ParsePrivateKey(s string) (*PrivateKey, error)
ParsePrivateKey parses the string encoding of a private key. It is a wrapper around PrivateKey.UnmarshalText.
func (*PrivateKey) MarshalText ¶
func (pk *PrivateKey) MarshalText() ([]byte, error)
MarshalText formats the private key as "<name>:<base64 data>". It returns an error if pub is nil.
func (*PrivateKey) Name ¶
func (pk *PrivateKey) Name() string
Name returns the private key's identifier.
func (*PrivateKey) PublicKey ¶
func (pk *PrivateKey) PublicKey() *PublicKey
PublicKey returns the public portion of the private key.
func (*PrivateKey) String ¶
func (pk *PrivateKey) String() string
String formats the private key as "<name>:<base64 data>".
func (*PrivateKey) UnmarshalText ¶
func (pk *PrivateKey) UnmarshalText(data []byte) error
UnmarshalText parses the string encoding of a private key.
type PublicKey ¶
type PublicKey struct {
// contains filtered or unexported fields
}
A PublicKey is a Nix public signing key.
func ParsePublicKey ¶
ParsePublicKey parses the string encoding of a public key. It is a wrapper around PublicKey.UnmarshalText.
func (*PublicKey) MarshalText ¶
MarshalText formats the public key as "<name>:<base64 data>". It returns an error if pub is nil.
func (*PublicKey) UnmarshalText ¶
UnmarshalText parses the string encoding of a public key.
type Signature ¶
type Signature struct {
// contains filtered or unexported fields
}
A Signature is a signature of a Nix store object created by a PrivateKey.
func ParseSignature ¶
ParseSignature parses the string encoding of a signature. It is a wrapper around Signature.UnmarshalText.
func SignNARInfo ¶
func SignNARInfo(pk *PrivateKey, info *NARInfo) (*Signature, error)
SignNARInfo signs the given NARInfo with the private key.
func (*Signature) MarshalText ¶
MarshalText formats the signature as "<key name>:<base64 data>". It returns an error if pub is nil.
func (*Signature) Name ¶
Name returns the identifier of the PrivateKey used to produce this signature.
func (*Signature) UnmarshalText ¶
UnmarshalText parses the string encoding of a signature.
type StoreDirectory ¶
type StoreDirectory string
StoreDirectory is the absolute path of a Nix store in the local filesystem.
const DefaultStoreDirectory StoreDirectory = "/nix/store"
DefaultStoreDirectory is the default Nix store directory.
func CleanStoreDirectory ¶
func CleanStoreDirectory(path string) (StoreDirectory, error)
CleanStoreDirectory cleans an absolute slash-separated path as a StoreDirectory. It returns an error if the path is not absolute.
func StoreDirectoryFromEnvironment ¶
func StoreDirectoryFromEnvironment() (StoreDirectory, error)
StoreDirectoryFromEnvironment returns the Nix store directory in use based on the NIX_STORE_DIR environment variable, falling back to DefaultStoreDirectory if not set.
func (StoreDirectory) Join ¶
func (dir StoreDirectory) Join(elem ...string) string
Join joins any number of path elements to the store directory separated by slashes.
func (StoreDirectory) Object ¶
func (dir StoreDirectory) Object(name string) (StorePath, error)
Object returns the store path for the given store object name.
Example ¶
package main import ( "fmt" "zombiezen.com/go/nix" ) func main() { const objectName = "s66mzxpvicwk07gjbjfw9izjfa797vsw-hello-2.12.1" storePath, err := nix.DefaultStoreDirectory.Object(objectName) if err != nil { panic(err) } fmt.Println(storePath) }
Output: /nix/store/s66mzxpvicwk07gjbjfw9izjfa797vsw-hello-2.12.1
func (StoreDirectory) ParsePath ¶
func (dir StoreDirectory) ParsePath(path string) (storePath StorePath, sub string, err error)
ParsePath verifies that a given absolute slash-separated path begins with the store directory and names either a store object or a file inside a store object. On success, it returns the store object's name and the relative path inside the store object, if any.
Example ¶
package main import ( "fmt" "zombiezen.com/go/nix" ) func main() { const path = "/nix/store/s66mzxpvicwk07gjbjfw9izjfa797vsw-hello-2.12.1/bin/hello" storePath, subPath, err := nix.DefaultStoreDirectory.ParsePath(path) if err != nil { panic(err) } fmt.Println(storePath) fmt.Println(subPath) }
Output: /nix/store/s66mzxpvicwk07gjbjfw9izjfa797vsw-hello-2.12.1 bin/hello
type StorePath ¶
type StorePath string
StorePath is a Nix store path: the absolute path of a Nix store object in the filesystem. For example: "/nix/store/s66mzxpvicwk07gjbjfw9izjfa797vsw-hello-2.12.1".
func ParseStorePath ¶
ParseStorePath parses an absolute slash-separated path as a store path (i.e. an immediate child of a Nix store directory).
func (StorePath) Digest ¶
Digest returns the digest part of the name.
Example ¶
package main import ( "fmt" "zombiezen.com/go/nix" ) func main() { path, err := nix.ParseStorePath("/nix/store/s66mzxpvicwk07gjbjfw9izjfa797vsw-hello-2.12.1") if err != nil { panic(err) } fmt.Println(path.Digest()) }
Output: s66mzxpvicwk07gjbjfw9izjfa797vsw
func (StorePath) IsDerivation ¶
IsDerivation reports whether the name ends in ".drv".
func (StorePath) MarshalText ¶
MarshalText returns a byte slice of the path or an error if it's empty.
func (StorePath) Name ¶
Name returns the part of the name after the digest.
Example ¶
package main import ( "fmt" "zombiezen.com/go/nix" ) func main() { path, err := nix.ParseStorePath("/nix/store/s66mzxpvicwk07gjbjfw9izjfa797vsw-hello-2.12.1") if err != nil { panic(err) } fmt.Println(path.Name()) }
Output: hello-2.12.1
func (*StorePath) UnmarshalText ¶
UnmarshalText validates and cleans the path in the same way as ParseStorePath and stores it into *path.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
Package nar implements access to Nix Archive (NAR) files.
|
Package nar implements access to Nix Archive (NAR) files. |
Package nixbase32 implements the slightly odd "base32" encoding that's used in Nix.
|
Package nixbase32 implements the slightly odd "base32" encoding that's used in Nix. |