Documentation
¶
Overview ¶
Package nix implements the parts of the Nix binary cache protocol the server needs: the nixbase32 encoding, store path names, the narinfo file format and the ed25519 signatures narinfo carry.
Index ¶
- Constants
- Variables
- func DecodeBase32(s string, size int) ([]byte, error)
- func EncodeBase32(b []byte) string
- func SplitBaseName(base string) (string, string, error)
- func SplitStorePath(path string) (string, string, error)
- func ValidKeyName(s string) bool
- func ValidName(s string) bool
- func ValidStoreHash(s string) bool
- type NarInfo
- type SHA256
- type SecretKey
Constants ¶
const MaxNarInfoBytes = 1 << 20
MaxNarInfoBytes bounds a narinfo file. Real ones are a few KiB; the largest grow with the number of references.
const StoreDir = "/nix/store"
StoreDir is the store directory of the binary caches the server hosts. A store with another prefix has other store paths, so its paths cannot be substituted by a client using /nix/store.
Variables ¶
var ( ErrInvalidNarInfo = errors.New("invalid narinfo") ErrInvalidHash = errors.New("invalid sha256 hash") ErrInvalidNarFile = errors.New("invalid nar file name") )
Errors of ParseNarInfo, ParseSHA256 and the narinfo accessors.
var ErrInvalidBase32 = errors.New("invalid nixbase32")
ErrInvalidBase32 is returned for text that is not nixbase32.
var ErrInvalidKey = errors.New("invalid nix signing key")
ErrInvalidKey is returned for a key that is not in Nix's "<name>:<base64>" format or does not hold a consistent ed25519 key pair.
var ErrInvalidStorePath = errors.New("invalid store path")
ErrInvalidStorePath is returned for text that is not a store path or the base name of one.
Functions ¶
func DecodeBase32 ¶
DecodeBase32 decodes nixbase32 text into size bytes. The text must have the exact length of such an encoding and no bits may be set beyond the last byte, so a value has exactly one spelling.
func EncodeBase32 ¶
EncodeBase32 returns the nixbase32 encoding of b. Unlike RFC 4648 Nix emits the least significant digit last, i.e. it encodes the bytes in reverse.
func SplitBaseName ¶
SplitBaseName splits "<hash>-<name>" into its parts.
func SplitStorePath ¶
SplitStorePath splits "/nix/store/<hash>-<name>" into its parts.
func ValidKeyName ¶
ValidKeyName reports whether s can name a key: it is the part before the colon in trusted-public-keys and signatures.
func ValidStoreHash ¶
ValidStoreHash reports whether s is the hash part of a store path.
Types ¶
type NarInfo ¶
type NarInfo struct {
// StorePath is the full path, /nix/store/<hash>-<name>.
StorePath string
// URL locates the NAR file relative to the cache, nar/<filehash>.nar.xz.
URL string
// Compression is the compression of the file ("none" when it is the bare NAR).
Compression string
// FileHash and FileSize describe the file at URL; they are absent from some
// narinfo of uncompressed NARs.
FileHash string
FileSize int64
// NarHash and NarSize describe the NAR after decompression.
NarHash string
NarSize int64
// References are the base names of the paths this one refers to.
References []string
// Deriver is the base name of the .drv that built the path, "" when unknown.
Deriver string
// Sigs are the signatures, each "<keyname>:<base64>".
Sigs []string
// CA is the content address of a content-addressed path.
CA string
}
NarInfo is the description of one store path in a binary cache.
func ParseNarInfo ¶
ParseNarInfo parses and validates the text of a .narinfo file. Unknown fields are ignored, a repeated field (other than Sig) is an error.
func (*NarInfo) Fingerprint ¶
Fingerprint is the string a signature covers: the store path, the NAR hash and size and the references as full paths in name order.
func (*NarInfo) NarFile ¶
NarFile validates URL as the location the server accepts for a NAR file, nar/<nixbase32 of the file's sha256>.nar[.<ext>], and returns the file name below nar/ and the hash it embeds.
type SHA256 ¶
SHA256 is a SHA-256 digest.
func ParseNarFile ¶
ParseNarFile checks a file name below nar/ (<nixbase32 sha256>.nar[.<ext>]) and returns the hash it names.
func ParseSHA256 ¶
ParseSHA256 reads a SHA-256 hash in any of the spellings Nix tools write: "sha256:<nixbase32>", "sha256:<hex>" and the SRI form "sha256-<base64>".
type SecretKey ¶
type SecretKey struct {
// contains filtered or unexported fields
}
SecretKey is an ed25519 key that signs narinfo. Its text form is the one "nix-store --generate-binary-cache-key" writes: "<name>:<base64 of seed and public key>".
func GenerateKey ¶
GenerateKey creates a key with a fresh random pair.
func ParseSecretKey ¶
ParseSecretKey reads the text form of a secret key.
func (*SecretKey) PublicKey ¶
PublicKey returns the key to put into trusted-public-keys: "<name>:<base64 of the public key>".