Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Loading...
Searching...
No Matches
archive.hh File Reference

Go to the source code of this file.

Functions

void nix::dumpPath (const std::filesystem::path &path, Sink &sink, PathFilter &filter)
time_t nix::dumpPathAndGetMtime (const std::filesystem::path &path, Sink &sink, PathFilter &filter)
void nix::dumpString (std::string_view s, Sink &sink)
void nix::parseDump (FileSystemObjectSink &sink, Source &source)
void nix::restorePath (const std::filesystem::path &path, Source &source, bool startFsync, RestoreSinkHooks *hooks)
void nix::copyNAR (Source &source, Sink &sink)

Variables

constexpr size_t nix::narMaxDepth = 64
constexpr std::string_view nix::narVersionMagic1 = "nix-archive-1"
constexpr std::string_view nix::caseHackSuffix = "~nix~case~hack~"

Function Documentation

◆ copyNAR()

void nix::copyNAR ( Source & source,
Sink & sink )

Read a NAR from 'source' and write it to 'sink'.

◆ dumpPath()

void nix::dumpPath ( const std::filesystem::path & path,
Sink & sink,
PathFilter & filter = defaultPathFilter )

dumpPath creates a Nix archive of the specified path.

Parameters
paththe file system data to dump. Dumping is recursive so if this is a directory we dump it and all its children.
[out]sinkThe serialised archive is fed into this sink.
filterCan be used to skip certain files.

The format is as follows:

IF path points to a REGULAR FILE:
dump(path) = attrs(
[ ("type", "regular")
, ("contents", contents(path))
])
IF path points to a DIRECTORY:
dump(path) = attrs(
[ ("type", "directory")
, ("entries", concat(map(f, sort(entries(path)))))
])
where f(fn) = attrs(
[ ("name", fn)
, ("file", dump(path + "/" + fn))
])
where:
attrs(as) = concat(map(attr, as)) + encN(0)
attrs((a, b)) = encS(a) + encS(b)
encS(s) = encN(len(s)) + s + (padding until next 64-bit boundary)
encN(n) = 64-bit little-endian encoding of n.
contents(path) = the contents of a regular file.
sort(strings) = lexicographic sort by 8-bit value (strcmp).
entries(path) = the entries of a directory, without `.` and
`..`.
`+` denotes string concatenation.

◆ dumpPathAndGetMtime()

time_t nix::dumpPathAndGetMtime ( const std::filesystem::path & path,
Sink & sink,
PathFilter & filter = defaultPathFilter )

Same as dumpPath(), but returns the last modified date of the path.

◆ dumpString()

void nix::dumpString ( std::string_view s,
Sink & sink )

Dump an archive with a single file with these contents.

Parameters
sContents of the file.

◆ restorePath()

void nix::restorePath ( const std::filesystem::path & path,
Source & source,
bool startFsync,
RestoreSinkHooks * hooks )
Parameters
pathRoot where to unpack the NAR.
sourceNAR source
hooksHooks for canonicalising metadata.

Variable Documentation

◆ narMaxDepth

size_t nix::narMaxDepth = 64
constexpr

Maximum directory nesting depth for dumpPath()/parseDump(). Bounds stack usage so deep trees cannot overflow the (possibly coroutine) stack these run on.

Other code writing out file system objects can use this too, so that whatever it writes can also be dumped as a NAR.