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}`
NormalizedHashPattern defines the valid characters for a Nix32 encoded hash. Nix32 uses a 32-character alphabet excluding 'e', 'o', 'u', and 't'. Valid characters: 0-9, a-d, f-n, p-s, v-z Hashes must be exactly 52 characters long.
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.
Functions ¶
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
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.