Documentation
¶
Index ¶
Constants ¶
const HashPattern = `(?:(` + narinfo.HashPattern + `[-_]))?` + NormalizedHashPattern
HashPattern is the strict validation pattern for complete nar hashes. It matches an optional prefix (narinfo hash + separator) followed by exactly a 52-character normalized hash. Used with anchors (^...$) to validate the full input. For extraction and lenient parsing, use HashPatternLenient instead.
const HashPatternLenient = `(?:(` + narinfo.HashPattern + `[-_]))?(.+)`
HashPatternLenient is used for parsing/extraction. It matches optional prefix followed by anything, allowing us to extract and validate parts separately.
const NormalizedHashPattern = `(?:[0-9a-df-np-sv-z]{52}|[0-9a-f]{64})`
NormalizedHashPattern defines the valid patterns for Nix store hashes. It supports two primary formats:
- Nix32 (Base32): A custom 32-character alphabet (0-9, a-z excluding 'e', 'o', 'u', 't'). Used for truncated SHA-256 (52 chars).
- Hexadecimal (Base16): Standard 0-9, a-f. Used for full SHA-256 digests (64 chars).
Variables ¶
var ( // ErrInvalidHash is returned if the hash is not valid. ErrInvalidHash = errors.New("invalid nar hash") )
var ErrInvalidURL = errors.New("invalid nar URL")
ErrInvalidURL is returned if the regexp did not match the given URL.
var ErrUnknownFileExtension = errors.New("file extension is not known")
ErrUnknownFileExtension is returned if the file extension is not known.
var ErrUnsupportedCompressionType = errors.New("unsupported compression type")
ErrUnsupportedCompressionType is returned when an unsupported compression type is encountered.
Functions ¶
func DecompressReader ¶ added in v0.9.0
func DecompressReader(ctx context.Context, r io.Reader, comp CompressionType) (io.ReadCloser, error)
DecompressReader returns a Reader that decompresses the data from r using the given compression type. The caller is responsible for closing the returned ReadCloser.
func FilePath ¶ added in v0.8.5
FilePath returns the path of the nar file given a hash and an optional compression.
func ValidateHash ¶ added in v0.8.5
ValidateHash validates a Nix archive (nar) hash string. It returns ErrInvalidHash if the hash does not match the expected pattern. The function accepts both the optional narinfo hash prefix and the 52‑ or 64‑character normalized hash value, following the definitions in NormalizedHashPattern and HashPattern.
Types ¶
type CompressionType ¶
type CompressionType string
CompressionType represents the compression types supported by Nix. See: https://github.com/NixOS/nix/blob/f1187cb696584739884687d788a6fbb4dd36c61c/src/libstore/binary-cache-store.cc#L166
const ( CompressionTypeNone CompressionType = "none" CompressionTypeBzip2 CompressionType = "bzip2" CompressionTypeZstd CompressionType = "zstd" CompressionTypeLzip CompressionType = "lzip" CompressionTypeLz4 CompressionType = "lz4" CompressionTypeBr CompressionType = "br" CompressionTypeXz CompressionType = "xz" )
func CompressionTypeFromExtension ¶
func CompressionTypeFromExtension(ext string) (CompressionType, error)
CompressionTypeFromExtension returns the compression type given an extension.
func CompressionTypeFromString ¶
func CompressionTypeFromString(ct string) CompressionType
CompressionTypeFromString returns the string compression type as CompressionType.
func (CompressionType) String ¶
func (ct CompressionType) String() string
String returns the CompressionType as a string.
func (CompressionType) ToFileExtension ¶
func (ct CompressionType) ToFileExtension() string
ToFileExtension returns the file extensions associated with the compression type.
type URL ¶
type URL struct {
Hash string
Compression CompressionType
Query url.Values
}
URL represents a nar URL.
func ParseURL ¶
ParseURL parses a nar URL (as present in narinfo) and returns its components. It accepts URLs in the format: [path/]<hash>.nar[.<compression>][?query] The hash must match HashPattern. This implementation is flexible about the directory structure - only the filename matters, not the "nar/" prefix.
func (URL) Normalize ¶ added in v0.8.5
Normalize returns a new URL with the narinfo hash prefix trimmed from the Hash. nix-serve serves NAR URLs with the narinfo hash as a prefix (e.g., "narinfo-hash-actual-hash"). This method removes that prefix to standardize the hash for storage.
func (URL) ToFilePath ¶
ToFilePath returns the filepath in the store for a given nar URL.