nixpath

package
v0.0.0-...-9a0e2d5 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package nixpath 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 Absolute

func Absolute(name string) string

Absolute prefixes a nixpath name with StoreDir and a '/', and cleans the path. It does not prevent from leaving StoreDir, so check if it still starts with StoreDir if you accept untrusted input. This should be used when assembling store paths in hashing contexts. Even if this code is running on windows, we want to use forward slashes to construct them.

func Validate

func Validate(s string) error

Validate validates a path string, verifying it's syntactically valid.

Types

type NixPath

type NixPath struct {
	Name   string
	Digest []byte
}

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

func FromString

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

FromString parses a path string into a nix path, verifying it's syntactically valid It returns an error if it fails to parse.

func (*NixPath) String

func (n *NixPath) String() string

func (*NixPath) Validate

func (n *NixPath) Validate() error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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