nix

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 28 Imported by: 0

Documentation

Overview

Package nix validates Nix binary-cache metadata and archive integrity.

Index

Constants

View Source
const (
	MaxMetadataBytes       = 1 << 20
	MaxArchiveBytes  int64 = 512 << 20
	MaxNarBytes      int64 = 2 << 30
	CacheInfo              = "StoreDir: /nix/store\nWantMassQuery: 1\nPriority: 30\n"
)

Variables

View Source
var (
	ErrInvalid = errors.New("nix: invalid binary cache content")
)

Functions

func ArchivePath

func ArchivePath(path string) (string, bool)

ArchivePath admits only relative content-addressed archive names, never URLs.

func IsInfoPath

func IsInfoPath(path string) bool

func Nix32

func Nix32(raw []byte) string

Nix32 encodes bytes in the bit order used by Nix, distinct from RFC 4648.

func ReferencedArchive

func ReferencedArchive(
	ctx context.Context,
	env format.Env,
	c repo.Config,
	info Info,
	cached bool,
) (types.Item, error)

ReferencedArchive verifies the complete compressed and uncompressed identity.

func Serves

func Serves(t repo.PackageType) bool

Types

type Archive

type Archive struct {
	FileHash string
	FileSize int64
	NarHash  string
	NarSize  int64
}

Archive describes both the transport bytes and the uncompressed NAR.

func ReadArchive

func ReadArchive(input io.Reader, size int64, compression string) (Archive, error)

func (Archive) Matches

func (a Archive) Matches(info Info) bool

type Handler

type Handler struct{ generic.Handler }

func (Handler) Admit

func (Handler) Admit(
	ctx context.Context,
	env format.Env,
	c repo.Config,
	w format.Write,
) (format.Write, error)

func (Handler) Classify

func (Handler) Classify(_ repo.Config, path string) format.Class

func (Handler) Deleted

func (Handler) Deleted(ctx context.Context, env format.Env, c repo.Config, _ []types.Item) error

func (Handler) Deployed

func (Handler) Deployed(ctx context.Context, env format.Env, c repo.Config, it types.Item) error

func (Handler) GuardWrite

func (Handler) GuardWrite(
	ctx context.Context,
	env format.Env,
	c repo.Config,
	w format.Write,
) error

GuardWrite serializes competing first publications at the same store hash. A transfer is admitted while planning, so repeat the fingerprint check under the transaction lock before its destination is replaced.

func (Handler) Inspect

func (Handler) Inspect(
	ctx context.Context,
	env format.Env,
	_ repo.Config,
	w format.Write,
) (any, error)

func (Handler) Reindex

func (Handler) Reindex(ctx context.Context, env format.Env, c repo.Config) error

func (Handler) Resolve

func (Handler) Resolve(
	ctx context.Context,
	env format.Env,
	c repo.Config,
	d format.Download,
) (string, error)

type Info

type Info struct {
	StorePath   string   `json:"store_path"`
	URL         string   `json:"url"`
	Compression string   `json:"compression"`
	FileHash    string   `json:"file_hash"`
	FileSize    int64    `json:"file_size"`
	NarHash     string   `json:"nar_hash"`
	NarSize     int64    `json:"nar_size"`
	References  []string `json:"references"`
	Deriver     string   `json:"deriver"`
	Signatures  []string `json:"signatures"`
}

Info holds the fields covered by a Nix signature and the archive's transport identity.

func Parse

func Parse(data []byte, path string) (Info, error)

func ReadInfo

func ReadInfo(ctx context.Context, env format.Env, it types.Item) (Info, error)

func (Info) Encode

func (i Info) Encode(url string) []byte

Encode can rewrite the relative archive URL without changing the signed fingerprint.

func (Info) Fingerprint

func (i Info) Fingerprint() []byte

func (*Info) Sign

func (i *Info) Sign(alias string, key ed25519.PrivateKey) error

func (Info) Verify

func (i Info) Verify(alias string, key ed25519.PublicKey) bool

Jump to

Keyboard shortcuts

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