storepath

package
v0.0.0-...-0327d78 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2024 License: Apache-2.0 Imports: 4 Imported by: 6

Documentation

Overview

Package storepath parses and renders Nix store paths.

Index

Constants

View Source
const (
	StoreDir     = "/nix/store"
	PathHashSize = 20
)

Variables

View Source
var (
	NameRe = regexp.MustCompile(`[a-zA-Z0-9+\-_?=][.a-zA-Z0-9+\-_?=]*`)
	PathRe = regexp.MustCompile(fmt.Sprintf(
		`^%v/([%v]{%d})-(%v)$`,
		regexp.QuoteMeta(StoreDir),
		nixbase32.Alphabet,
		nixbase32.EncodedLen(PathHashSize),
		NameRe,
	))
)

Functions

func Validate

func Validate(s string) error

Validate validates an absolute Nix Store Path string.

Types

type StorePath

type StorePath struct {
	Name   string
	Digest []byte
}

StorePath represents a bare Nix store path, without any paths underneath `/nix/store/…-…`.

func FromAbsolutePath

func FromAbsolutePath(s string) (*StorePath, error)

FromAbsolutePath parses an absolute Nix Store path including store prefix) into a StorePath, verifying it's syntactically valid. It returns an error if it fails to parse.

func FromString

func FromString(s string) (*StorePath, error)

FromString parses a Nix store path without store prefix into a StorePath, verifying it's syntactically valid. It returns an error if it fails to parse.

func (*StorePath) Absolute

func (n *StorePath) Absolute() string

Absolute returns a StorePath with StoreDir and slash prepended. We use forward slashes on all architectures (including Windows), to be consistent in hashing contexts.

func (*StorePath) String

func (n *StorePath) String() string

String returns a Store without StoreDir. It starts with a digest (20 bytes), nixbase32-encoded, followed by a `-`, and ends with the name.

func (*StorePath) Validate

func (n *StorePath) Validate() error

Validate validates a StorePath, verifying it's syntactically valid.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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