2012-07-18 20:59:03 +02:00
|
|
|
|
#pragma once
|
2006-11-30 18:43:04 +01:00
|
|
|
|
|
2010-10-04 19:55:38 +02:00
|
|
|
|
#include "hash.hh"
|
|
|
|
|
#include "serialise.hh"
|
2016-03-24 11:41:00 +01:00
|
|
|
|
#include "crypto.hh"
|
2016-04-19 18:50:15 +02:00
|
|
|
|
#include "lru-cache.hh"
|
|
|
|
|
#include "sync.hh"
|
2016-09-02 12:39:29 +02:00
|
|
|
|
#include "globals.hh"
|
2017-04-13 15:55:38 +02:00
|
|
|
|
#include "config.hh"
|
2010-10-04 19:55:38 +02:00
|
|
|
|
|
2016-04-19 18:50:15 +02:00
|
|
|
|
#include <atomic>
|
2015-08-21 13:57:53 +02:00
|
|
|
|
#include <limits>
|
2006-12-05 02:31:45 +01:00
|
|
|
|
#include <map>
|
2014-03-30 00:49:23 +01:00
|
|
|
|
#include <memory>
|
2016-04-19 18:50:15 +02:00
|
|
|
|
#include <string>
|
2006-11-30 18:43:04 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
|
|
|
|
|
|
2017-05-01 13:43:34 +02:00
|
|
|
|
MakeError(SubstError, Error)
|
|
|
|
|
MakeError(BuildError, Error) /* denotes a permanent build failure */
|
|
|
|
|
MakeError(InvalidPath, Error)
|
|
|
|
|
MakeError(Unsupported, Error)
|
|
|
|
|
|
|
|
|
|
|
2016-08-03 13:17:11 +02:00
|
|
|
|
struct BasicDerivation;
|
|
|
|
|
struct Derivation;
|
|
|
|
|
class FSAccessor;
|
|
|
|
|
class NarInfoDiskCache;
|
|
|
|
|
class Store;
|
exportReferencesGraph: Export more complete info in JSON format
This writes info about every path in the closure in the same format as
‘nix path-info --json’. Thus it also includes NAR hashes and sizes.
Example:
[
{
"path": "/nix/store/10h6li26i7g6z3mdpvra09yyf10mmzdr-hello-2.10",
"narHash": "sha256:0ckdc4z20kkmpqdilx0wl6cricxv90lh85xpv2qljppcmz6vzcxl",
"narSize": 197648,
"references": [
"/nix/store/10h6li26i7g6z3mdpvra09yyf10mmzdr-hello-2.10",
"/nix/store/27binbdy296qvjycdgr1535v8872vz3z-glibc-2.24"
],
"closureSize": 20939776
},
{
"path": "/nix/store/27binbdy296qvjycdgr1535v8872vz3z-glibc-2.24",
"narHash": "sha256:1nfn3m3p98y1c0kd0brp80dn9n5mycwgrk183j17rajya0h7gax3",
"narSize": 20742128,
"references": [
"/nix/store/27binbdy296qvjycdgr1535v8872vz3z-glibc-2.24"
],
"closureSize": 20742128
}
]
Fixes #1134.
2017-01-26 20:36:20 +01:00
|
|
|
|
class JSONPlaceholder;
|
2016-08-03 13:17:11 +02:00
|
|
|
|
|
|
|
|
|
|
2016-02-15 14:48:38 +01:00
|
|
|
|
/* Size of the hash part of store paths, in base-32 characters. */
|
|
|
|
|
const size_t storePathHashLen = 32; // i.e. 160 bits
|
|
|
|
|
|
2016-05-04 13:36:54 +02:00
|
|
|
|
/* Magic header of exportPath() output (obsolete). */
|
2016-02-15 14:48:38 +01:00
|
|
|
|
const uint32_t exportMagic = 0x4558494e;
|
|
|
|
|
|
|
|
|
|
|
2006-12-05 02:31:45 +01:00
|
|
|
|
typedef std::map<Path, Path> Roots;
|
|
|
|
|
|
|
|
|
|
|
2008-06-18 11:34:17 +02:00
|
|
|
|
struct GCOptions
|
|
|
|
|
{
|
|
|
|
|
/* Garbage collector operation:
|
|
|
|
|
|
|
|
|
|
- `gcReturnLive': return the set of paths reachable from
|
|
|
|
|
(i.e. in the closure of) the roots.
|
|
|
|
|
|
|
|
|
|
- `gcReturnDead': return the set of paths not reachable from
|
|
|
|
|
the roots.
|
|
|
|
|
|
|
|
|
|
- `gcDeleteDead': actually delete the latter set.
|
|
|
|
|
|
|
|
|
|
- `gcDeleteSpecific': delete the paths listed in
|
|
|
|
|
`pathsToDelete', insofar as they are not reachable.
|
|
|
|
|
*/
|
|
|
|
|
typedef enum {
|
|
|
|
|
gcReturnLive,
|
|
|
|
|
gcReturnDead,
|
|
|
|
|
gcDeleteDead,
|
|
|
|
|
gcDeleteSpecific,
|
|
|
|
|
} GCAction;
|
|
|
|
|
|
2015-08-21 13:57:53 +02:00
|
|
|
|
GCAction action{gcDeleteDead};
|
2008-06-18 11:34:17 +02:00
|
|
|
|
|
|
|
|
|
/* If `ignoreLiveness' is set, then reachability from the roots is
|
|
|
|
|
ignored (dangerous!). However, the paths must still be
|
|
|
|
|
unreferenced *within* the store (i.e., there can be no other
|
|
|
|
|
store paths that depend on them). */
|
2015-08-21 13:57:53 +02:00
|
|
|
|
bool ignoreLiveness{false};
|
2008-06-18 11:34:17 +02:00
|
|
|
|
|
|
|
|
|
/* For `gcDeleteSpecific', the paths to delete. */
|
|
|
|
|
PathSet pathsToDelete;
|
|
|
|
|
|
2012-08-02 01:14:30 +02:00
|
|
|
|
/* Stop after at least `maxFreed' bytes have been freed. */
|
2015-08-21 13:57:53 +02:00
|
|
|
|
unsigned long long maxFreed{std::numeric_limits<unsigned long long>::max()};
|
2008-06-18 11:34:17 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2015-03-25 17:06:12 +01:00
|
|
|
|
struct GCResults
|
2008-06-18 11:34:17 +02:00
|
|
|
|
{
|
|
|
|
|
/* Depending on the action, the GC roots, or the paths that would
|
|
|
|
|
be or have been deleted. */
|
|
|
|
|
PathSet paths;
|
|
|
|
|
|
|
|
|
|
/* For `gcReturnDead', `gcDeleteDead' and `gcDeleteSpecific', the
|
|
|
|
|
number of bytes that would be or was freed. */
|
2017-04-10 11:12:45 +02:00
|
|
|
|
unsigned long long bytesFreed = 0;
|
2008-06-18 11:34:17 +02:00
|
|
|
|
};
|
2006-12-05 03:18:46 +01:00
|
|
|
|
|
|
|
|
|
|
2008-08-02 14:54:35 +02:00
|
|
|
|
struct SubstitutablePathInfo
|
|
|
|
|
{
|
|
|
|
|
Path deriver;
|
|
|
|
|
PathSet references;
|
|
|
|
|
unsigned long long downloadSize; /* 0 = unknown or inapplicable */
|
2010-11-17 15:31:42 +01:00
|
|
|
|
unsigned long long narSize; /* 0 = unknown */
|
2008-08-02 14:54:35 +02:00
|
|
|
|
};
|
|
|
|
|
|
download-from-binary-cache: parallelise fetching of NAR info files
Getting substitute information using the binary cache substituter has
non-trivial latency overhead. A package or NixOS system configuration
can have hundreds of dependencies, and in the worst case (when the
local info cache is empty) we have to do a separate HTTP request for
each of these. If the ping time to the server is t, getting N info
files will take tN seconds; e.g., with a ping time of 0.1s to
nixos.org, sequentially downloading 1000 info files (a typical NixOS
config) will take at least 100 seconds.
To fix this problem, the binary cache substituter can now perform
requests in parallel. This required changing the substituter
interface to support a function querySubstitutablePathInfos() that
queries multiple paths at the same time, and rewriting queryMissing()
to take advantage of parallelism. (Due to local caching,
parallelising queryMissing() is sufficient for most use cases, since
it's almost always called before building a derivation and thus fills
the local info cache.)
For example, parallelism speeds up querying all 1056 paths in a
particular NixOS system configuration from 116s to 2.6s. It works so
well because the eccentricity of the top-level derivation in the
dependency graph is only 9. So we only need 10 round-trips (when
using an unlimited number of parallel connections) to get everything.
Currently we do a maximum of 150 parallel connections to the server.
Thus it's important that the binary cache server (e.g. nixos.org) has
a high connection limit. Alternatively we could use HTTP pipelining,
but WWW::Curl doesn't support it and libcurl has a hard-coded limit of
5 requests per pipeline.
2012-07-07 01:08:20 +02:00
|
|
|
|
typedef std::map<Path, SubstitutablePathInfo> SubstitutablePathInfos;
|
|
|
|
|
|
2008-08-02 14:54:35 +02:00
|
|
|
|
|
2015-03-25 17:06:12 +01:00
|
|
|
|
struct ValidPathInfo
|
2010-11-16 18:11:46 +01:00
|
|
|
|
{
|
|
|
|
|
Path path;
|
|
|
|
|
Path deriver;
|
2016-02-16 11:49:12 +01:00
|
|
|
|
Hash narHash;
|
2010-11-16 18:11:46 +01:00
|
|
|
|
PathSet references;
|
2015-11-09 23:16:24 +01:00
|
|
|
|
time_t registrationTime = 0;
|
2016-03-30 15:50:45 +02:00
|
|
|
|
uint64_t narSize = 0; // 0 = unknown
|
|
|
|
|
uint64_t id; // internal use only
|
2015-11-09 23:16:24 +01:00
|
|
|
|
|
2017-05-11 13:31:23 +02:00
|
|
|
|
/* Whether the path is ultimately trusted, that is, it's a
|
|
|
|
|
derivation output that was built locally. */
|
2016-03-21 18:05:47 +01:00
|
|
|
|
bool ultimate = false;
|
|
|
|
|
|
|
|
|
|
StringSet sigs; // note: not necessarily verified
|
|
|
|
|
|
2016-08-03 13:17:11 +02:00
|
|
|
|
/* If non-empty, an assertion that the path is content-addressed,
|
|
|
|
|
i.e., that the store path is computed from a cryptographic hash
|
|
|
|
|
of the contents of the path, plus some other bits of data like
|
|
|
|
|
the "name" part of the path. Such a path doesn't need
|
|
|
|
|
signatures, since we don't have to trust anybody's claim that
|
|
|
|
|
the path is the output of a particular derivation. (In the
|
|
|
|
|
extensional store model, we have to trust that the *contents*
|
|
|
|
|
of an output path of a derivation were actually produced by
|
|
|
|
|
that derivation. In the intensional model, we have to trust
|
|
|
|
|
that a particular output path was produced by a derivation; the
|
2017-02-22 16:31:04 +01:00
|
|
|
|
path then implies the contents.)
|
2016-08-03 13:17:11 +02:00
|
|
|
|
|
|
|
|
|
Ideally, the content-addressability assertion would just be a
|
|
|
|
|
Boolean, and the store path would be computed from
|
2016-11-26 00:37:43 +01:00
|
|
|
|
‘storePathToName(path)’, ‘narHash’ and ‘references’. However,
|
2016-08-03 13:17:11 +02:00
|
|
|
|
1) we've accumulated several types of content-addressed paths
|
|
|
|
|
over the years; and 2) fixed-output derivations support
|
|
|
|
|
multiple hash algorithms and serialisation methods (flat file
|
2016-11-26 00:37:43 +01:00
|
|
|
|
vs NAR). Thus, ‘ca’ has one of the following forms:
|
2016-08-03 13:17:11 +02:00
|
|
|
|
|
2016-11-26 00:37:43 +01:00
|
|
|
|
* ‘text:sha256:<sha256 hash of file contents>’: For paths
|
2016-08-03 13:17:11 +02:00
|
|
|
|
computed by makeTextPath() / addTextToStore().
|
|
|
|
|
|
2016-11-26 00:37:43 +01:00
|
|
|
|
* ‘fixed:<r?>:<ht>:<h>’: For paths computed by
|
2016-08-03 13:17:11 +02:00
|
|
|
|
makeFixedOutputPath() / addToStore().
|
|
|
|
|
*/
|
|
|
|
|
std::string ca;
|
|
|
|
|
|
2015-11-09 23:16:24 +01:00
|
|
|
|
bool operator == (const ValidPathInfo & i) const
|
|
|
|
|
{
|
|
|
|
|
return
|
|
|
|
|
path == i.path
|
2016-02-16 11:49:12 +01:00
|
|
|
|
&& narHash == i.narHash
|
2015-11-09 23:16:24 +01:00
|
|
|
|
&& references == i.references;
|
|
|
|
|
}
|
2016-03-24 11:41:00 +01:00
|
|
|
|
|
2016-08-03 13:17:11 +02:00
|
|
|
|
/* Return a fingerprint of the store path to be used in binary
|
|
|
|
|
cache signatures. It contains the store path, the base-32
|
|
|
|
|
SHA-256 hash of the NAR serialisation of the path, the size of
|
|
|
|
|
the NAR, and the sorted references. The size field is strictly
|
|
|
|
|
speaking superfluous, but might prevent endless/excessive data
|
|
|
|
|
attacks. */
|
2016-03-24 11:41:00 +01:00
|
|
|
|
std::string fingerprint() const;
|
|
|
|
|
|
|
|
|
|
void sign(const SecretKey & secretKey);
|
|
|
|
|
|
2016-08-03 13:17:11 +02:00
|
|
|
|
/* Return true iff the path is verifiably content-addressed. */
|
|
|
|
|
bool isContentAddressed(const Store & store) const;
|
|
|
|
|
|
|
|
|
|
static const size_t maxSigs = std::numeric_limits<size_t>::max();
|
|
|
|
|
|
2016-03-24 11:41:00 +01:00
|
|
|
|
/* Return the number of signatures on this .narinfo that were
|
2016-08-03 13:17:11 +02:00
|
|
|
|
produced by one of the specified keys, or maxSigs if the path
|
|
|
|
|
is content-addressed. */
|
|
|
|
|
size_t checkSignatures(const Store & store, const PublicKeys & publicKeys) const;
|
2016-04-07 15:14:12 +02:00
|
|
|
|
|
|
|
|
|
/* Verify a single signature. */
|
|
|
|
|
bool checkSignature(const PublicKeys & publicKeys, const std::string & sig) const;
|
2016-04-19 18:50:15 +02:00
|
|
|
|
|
2016-04-20 14:12:38 +02:00
|
|
|
|
Strings shortRefs() const;
|
|
|
|
|
|
2016-04-19 18:50:15 +02:00
|
|
|
|
virtual ~ValidPathInfo() { }
|
2010-11-16 18:11:46 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
typedef list<ValidPathInfo> ValidPathInfos;
|
|
|
|
|
|
|
|
|
|
|
2016-01-31 12:06:45 +01:00
|
|
|
|
enum BuildMode { bmNormal, bmRepair, bmCheck, bmHash };
|
2014-02-18 01:01:14 +01:00
|
|
|
|
|
|
|
|
|
|
Allow remote builds without sending the derivation closure
Previously, to build a derivation remotely, we had to copy the entire
closure of the .drv file to the remote machine, even though we only
need the top-level derivation. This is very wasteful: the closure can
contain thousands of store paths, and in some Hydra use cases, include
source paths that are very large (e.g. Git/Mercurial checkouts).
So now there is a new operation, StoreAPI::buildDerivation(), that
performs a build from an in-memory representation of a derivation
(BasicDerivation) rather than from a on-disk .drv file. The only files
that need to be in the Nix store are the sources of the derivation
(drv.inputSrcs), and the needed output paths of the dependencies (as
described by drv.inputDrvs). "nix-store --serve" exposes this
interface.
Note that this is a privileged operation, because you can construct a
derivation that builds any store path whatsoever. Fixing this will
require changing the hashing scheme (i.e., the output paths should be
computed from the other fields in BasicDerivation, allowing them to be
verified without access to other derivations). However, this would be
quite nice because it would allow .drv-free building (e.g. "nix-env
-i" wouldn't have to write any .drv files to disk).
Fixes #173.
2015-07-17 17:57:40 +02:00
|
|
|
|
struct BuildResult
|
|
|
|
|
{
|
2016-10-26 15:02:38 +02:00
|
|
|
|
/* Note: don't remove status codes, and only add new status codes
|
|
|
|
|
at the end of the list, to prevent client/server
|
|
|
|
|
incompatibilities in the nix-store --serve protocol. */
|
Allow remote builds without sending the derivation closure
Previously, to build a derivation remotely, we had to copy the entire
closure of the .drv file to the remote machine, even though we only
need the top-level derivation. This is very wasteful: the closure can
contain thousands of store paths, and in some Hydra use cases, include
source paths that are very large (e.g. Git/Mercurial checkouts).
So now there is a new operation, StoreAPI::buildDerivation(), that
performs a build from an in-memory representation of a derivation
(BasicDerivation) rather than from a on-disk .drv file. The only files
that need to be in the Nix store are the sources of the derivation
(drv.inputSrcs), and the needed output paths of the dependencies (as
described by drv.inputDrvs). "nix-store --serve" exposes this
interface.
Note that this is a privileged operation, because you can construct a
derivation that builds any store path whatsoever. Fixing this will
require changing the hashing scheme (i.e., the output paths should be
computed from the other fields in BasicDerivation, allowing them to be
verified without access to other derivations). However, this would be
quite nice because it would allow .drv-free building (e.g. "nix-env
-i" wouldn't have to write any .drv files to disk).
Fixes #173.
2015-07-17 17:57:40 +02:00
|
|
|
|
enum Status {
|
2015-07-20 03:15:45 +02:00
|
|
|
|
Built = 0,
|
|
|
|
|
Substituted,
|
|
|
|
|
AlreadyValid,
|
|
|
|
|
PermanentFailure,
|
|
|
|
|
InputRejected,
|
|
|
|
|
OutputRejected,
|
|
|
|
|
TransientFailure, // possibly transient
|
2016-10-26 15:02:38 +02:00
|
|
|
|
CachedFailure, // no longer used
|
2015-07-20 03:15:45 +02:00
|
|
|
|
TimedOut,
|
|
|
|
|
MiscFailure,
|
2015-10-06 17:33:30 +02:00
|
|
|
|
DependencyFailed,
|
|
|
|
|
LogLimitExceeded,
|
2015-11-09 23:16:24 +01:00
|
|
|
|
NotDeterministic,
|
Allow remote builds without sending the derivation closure
Previously, to build a derivation remotely, we had to copy the entire
closure of the .drv file to the remote machine, even though we only
need the top-level derivation. This is very wasteful: the closure can
contain thousands of store paths, and in some Hydra use cases, include
source paths that are very large (e.g. Git/Mercurial checkouts).
So now there is a new operation, StoreAPI::buildDerivation(), that
performs a build from an in-memory representation of a derivation
(BasicDerivation) rather than from a on-disk .drv file. The only files
that need to be in the Nix store are the sources of the derivation
(drv.inputSrcs), and the needed output paths of the dependencies (as
described by drv.inputDrvs). "nix-store --serve" exposes this
interface.
Note that this is a privileged operation, because you can construct a
derivation that builds any store path whatsoever. Fixing this will
require changing the hashing scheme (i.e., the output paths should be
computed from the other fields in BasicDerivation, allowing them to be
verified without access to other derivations). However, this would be
quite nice because it would allow .drv-free building (e.g. "nix-env
-i" wouldn't have to write any .drv files to disk).
Fixes #173.
2015-07-17 17:57:40 +02:00
|
|
|
|
} status = MiscFailure;
|
|
|
|
|
std::string errorMsg;
|
2016-12-07 13:16:06 +01:00
|
|
|
|
|
|
|
|
|
/* How many times this build was performed. */
|
|
|
|
|
unsigned int timesBuilt = 0;
|
|
|
|
|
|
|
|
|
|
/* If timesBuilt > 1, whether some builds did not produce the same
|
|
|
|
|
result. (Note that 'isNonDeterministic = false' does not mean
|
|
|
|
|
the build is deterministic, just that we don't have evidence of
|
|
|
|
|
non-determinism.) */
|
|
|
|
|
bool isNonDeterministic = false;
|
|
|
|
|
|
2016-12-07 16:09:38 +01:00
|
|
|
|
/* The start/stop times of the build (or one of the rounds, if it
|
|
|
|
|
was repeated). */
|
|
|
|
|
time_t startTime = 0, stopTime = 0;
|
2016-12-07 13:16:06 +01:00
|
|
|
|
|
2015-07-20 03:15:45 +02:00
|
|
|
|
bool success() {
|
|
|
|
|
return status == Built || status == Substituted || status == AlreadyValid;
|
|
|
|
|
}
|
Allow remote builds without sending the derivation closure
Previously, to build a derivation remotely, we had to copy the entire
closure of the .drv file to the remote machine, even though we only
need the top-level derivation. This is very wasteful: the closure can
contain thousands of store paths, and in some Hydra use cases, include
source paths that are very large (e.g. Git/Mercurial checkouts).
So now there is a new operation, StoreAPI::buildDerivation(), that
performs a build from an in-memory representation of a derivation
(BasicDerivation) rather than from a on-disk .drv file. The only files
that need to be in the Nix store are the sources of the derivation
(drv.inputSrcs), and the needed output paths of the dependencies (as
described by drv.inputDrvs). "nix-store --serve" exposes this
interface.
Note that this is a privileged operation, because you can construct a
derivation that builds any store path whatsoever. Fixing this will
require changing the hashing scheme (i.e., the output paths should be
computed from the other fields in BasicDerivation, allowing them to be
verified without access to other derivations). However, this would be
quite nice because it would allow .drv-free building (e.g. "nix-env
-i" wouldn't have to write any .drv files to disk).
Fixes #173.
2015-07-17 17:57:40 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2017-04-13 15:55:38 +02:00
|
|
|
|
class Store : public std::enable_shared_from_this<Store>, public Config
|
2006-11-30 18:43:04 +01:00
|
|
|
|
{
|
2016-06-01 14:49:12 +02:00
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
typedef std::map<std::string, std::string> Params;
|
|
|
|
|
|
2017-04-13 15:55:38 +02:00
|
|
|
|
const PathSetting storeDir_{this, false, settings.nixStore,
|
|
|
|
|
"store", "path to the Nix store"};
|
|
|
|
|
const Path storeDir = storeDir_;
|
|
|
|
|
|
|
|
|
|
const Setting<int> pathInfoCacheSize{this, 65536, "path-info-cache-size", "size of the in-memory store path information cache"};
|
2016-06-01 14:49:12 +02:00
|
|
|
|
|
2016-04-19 18:50:15 +02:00
|
|
|
|
protected:
|
|
|
|
|
|
|
|
|
|
struct State
|
|
|
|
|
{
|
2017-04-06 14:30:31 +02:00
|
|
|
|
LRUCache<std::string, std::shared_ptr<ValidPathInfo>> pathInfoCache;
|
2016-04-19 18:50:15 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Sync<State> state;
|
|
|
|
|
|
2016-04-20 14:12:38 +02:00
|
|
|
|
std::shared_ptr<NarInfoDiskCache> diskCache;
|
|
|
|
|
|
2016-06-01 14:49:12 +02:00
|
|
|
|
Store(const Params & params);
|
|
|
|
|
|
2006-11-30 18:43:04 +01:00
|
|
|
|
public:
|
|
|
|
|
|
2016-02-04 14:48:42 +01:00
|
|
|
|
virtual ~Store() { }
|
2006-11-30 18:43:04 +01:00
|
|
|
|
|
2016-04-29 16:26:16 +02:00
|
|
|
|
virtual std::string getUri() = 0;
|
2016-04-20 14:12:38 +02:00
|
|
|
|
|
2016-11-26 00:37:43 +01:00
|
|
|
|
/* Return true if ‘path’ is in the Nix store (but not the Nix
|
2016-06-01 14:49:12 +02:00
|
|
|
|
store itself). */
|
|
|
|
|
bool isInStore(const Path & path) const;
|
|
|
|
|
|
2016-11-26 00:37:43 +01:00
|
|
|
|
/* Return true if ‘path’ is a store path, i.e. a direct child of
|
2016-06-01 14:49:12 +02:00
|
|
|
|
the Nix store. */
|
|
|
|
|
bool isStorePath(const Path & path) const;
|
|
|
|
|
|
2016-11-26 00:37:43 +01:00
|
|
|
|
/* Throw an exception if ‘path’ is not a store path. */
|
2016-06-01 14:49:12 +02:00
|
|
|
|
void assertStorePath(const Path & path) const;
|
|
|
|
|
|
|
|
|
|
/* Chop off the parts after the top-level store name, e.g.,
|
|
|
|
|
/nix/store/abcd-foo/bar => /nix/store/abcd-foo. */
|
|
|
|
|
Path toStorePath(const Path & path) const;
|
|
|
|
|
|
|
|
|
|
/* Follow symlinks until we end up with a path in the Nix store. */
|
|
|
|
|
Path followLinksToStore(const Path & path) const;
|
|
|
|
|
|
|
|
|
|
/* Same as followLinksToStore(), but apply toStorePath() to the
|
|
|
|
|
result. */
|
|
|
|
|
Path followLinksToStorePath(const Path & path) const;
|
|
|
|
|
|
|
|
|
|
/* Constructs a unique store path name. */
|
|
|
|
|
Path makeStorePath(const string & type,
|
|
|
|
|
const Hash & hash, const string & name) const;
|
|
|
|
|
|
|
|
|
|
Path makeOutputPath(const string & id,
|
|
|
|
|
const Hash & hash, const string & name) const;
|
|
|
|
|
|
|
|
|
|
Path makeFixedOutputPath(bool recursive,
|
2016-07-26 21:25:52 +02:00
|
|
|
|
const Hash & hash, const string & name) const;
|
2016-06-01 14:49:12 +02:00
|
|
|
|
|
2016-08-03 13:17:11 +02:00
|
|
|
|
Path makeTextPath(const string & name, const Hash & hash,
|
|
|
|
|
const PathSet & references) const;
|
|
|
|
|
|
|
|
|
|
/* This is the preparatory part of addToStore(); it computes the
|
|
|
|
|
store path to which srcPath is to be copied. Returns the store
|
|
|
|
|
path and the cryptographic hash of the contents of srcPath. */
|
2016-06-01 14:49:12 +02:00
|
|
|
|
std::pair<Path, Hash> computeStorePathForPath(const Path & srcPath,
|
|
|
|
|
bool recursive = true, HashType hashAlgo = htSHA256,
|
|
|
|
|
PathFilter & filter = defaultPathFilter) const;
|
|
|
|
|
|
|
|
|
|
/* Preparatory part of addTextToStore().
|
|
|
|
|
|
|
|
|
|
!!! Computation of the path should take the references given to
|
|
|
|
|
addTextToStore() into account, otherwise we have a (relatively
|
|
|
|
|
minor) security hole: a caller can register a source file with
|
|
|
|
|
bogus references. If there are too many references, the path may
|
|
|
|
|
not be garbage collected when it has to be (not really a problem,
|
|
|
|
|
the caller could create a root anyway), or it may be garbage
|
|
|
|
|
collected when it shouldn't be (more serious).
|
|
|
|
|
|
|
|
|
|
Hashing the references would solve this (bogus references would
|
|
|
|
|
simply yield a different store path, so other users wouldn't be
|
|
|
|
|
affected), but it has some backwards compatibility issues (the
|
|
|
|
|
hashing scheme changes), so I'm not doing that for now. */
|
|
|
|
|
Path computeStorePathForText(const string & name, const string & s,
|
|
|
|
|
const PathSet & references) const;
|
|
|
|
|
|
2015-03-25 17:06:12 +01:00
|
|
|
|
/* Check whether a path is valid. */
|
2016-04-19 18:50:15 +02:00
|
|
|
|
bool isValidPath(const Path & path);
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
2017-02-07 19:22:48 +01:00
|
|
|
|
virtual bool isValidPathUncached(const Path & path);
|
2016-04-19 18:50:15 +02:00
|
|
|
|
|
|
|
|
|
public:
|
2006-11-30 18:43:04 +01:00
|
|
|
|
|
2017-03-16 13:50:01 +01:00
|
|
|
|
/* Query which of the given paths is valid. Optionally, try to
|
|
|
|
|
substitute missing paths. */
|
|
|
|
|
virtual PathSet queryValidPaths(const PathSet & paths,
|
|
|
|
|
bool maybeSubstitute = false);
|
2012-07-11 17:08:47 +02:00
|
|
|
|
|
2016-04-21 17:53:47 +02:00
|
|
|
|
/* Query the set of all valid paths. Note that for some store
|
|
|
|
|
backends, the name part of store paths may be omitted
|
|
|
|
|
(i.e. you'll get /nix/store/<hash> rather than
|
|
|
|
|
/nix/store/<hash>-<name>). Use queryPathInfo() to obtain the
|
|
|
|
|
full store path. */
|
2012-07-11 16:49:04 +02:00
|
|
|
|
virtual PathSet queryAllValidPaths() = 0;
|
2008-01-29 19:17:36 +01:00
|
|
|
|
|
2016-04-21 17:53:47 +02:00
|
|
|
|
/* Query information about a valid path. It is permitted to omit
|
|
|
|
|
the name part of the store path. */
|
2016-04-19 18:50:15 +02:00
|
|
|
|
ref<const ValidPathInfo> queryPathInfo(const Path & path);
|
|
|
|
|
|
2016-09-16 18:54:14 +02:00
|
|
|
|
/* Asynchronous version of queryPathInfo(). */
|
|
|
|
|
void queryPathInfo(const Path & path,
|
|
|
|
|
std::function<void(ref<ValidPathInfo>)> success,
|
|
|
|
|
std::function<void(std::exception_ptr exc)> failure);
|
|
|
|
|
|
2016-04-19 18:50:15 +02:00
|
|
|
|
protected:
|
2010-11-16 18:11:46 +01:00
|
|
|
|
|
2016-09-16 18:54:14 +02:00
|
|
|
|
virtual void queryPathInfoUncached(const Path & path,
|
|
|
|
|
std::function<void(std::shared_ptr<ValidPathInfo>)> success,
|
|
|
|
|
std::function<void(std::exception_ptr exc)> failure) = 0;
|
2006-11-30 18:43:04 +01:00
|
|
|
|
|
2016-04-19 18:50:15 +02:00
|
|
|
|
public:
|
2006-11-30 18:43:04 +01:00
|
|
|
|
|
|
|
|
|
/* Queries the set of incoming FS references for a store path.
|
|
|
|
|
The result is not cleared. */
|
2006-12-01 19:00:01 +01:00
|
|
|
|
virtual void queryReferrers(const Path & path,
|
2006-11-30 18:43:04 +01:00
|
|
|
|
PathSet & referrers) = 0;
|
|
|
|
|
|
2012-12-20 18:41:44 +01:00
|
|
|
|
/* Return all currently valid derivations that have `path' as an
|
|
|
|
|
output. (Note that the result of `queryDeriver()' is the
|
|
|
|
|
derivation that was actually used to produce `path', which may
|
|
|
|
|
not exist anymore.) */
|
2017-02-07 19:22:48 +01:00
|
|
|
|
virtual PathSet queryValidDerivers(const Path & path) { return {}; };
|
2012-12-20 18:41:44 +01:00
|
|
|
|
|
2010-02-22 13:44:36 +01:00
|
|
|
|
/* Query the outputs of the derivation denoted by `path'. */
|
|
|
|
|
virtual PathSet queryDerivationOutputs(const Path & path) = 0;
|
2011-11-06 07:28:20 +01:00
|
|
|
|
|
|
|
|
|
/* Query the output names of the derivation denoted by `path'. */
|
|
|
|
|
virtual StringSet queryDerivationOutputNames(const Path & path) = 0;
|
2012-07-18 00:55:39 +02:00
|
|
|
|
|
|
|
|
|
/* Query the full store path given the hash part of a valid store
|
|
|
|
|
path, or "" if the path doesn't exist. */
|
|
|
|
|
virtual Path queryPathFromHashPart(const string & hashPart) = 0;
|
2015-03-25 17:06:12 +01:00
|
|
|
|
|
2012-07-11 23:52:18 +02:00
|
|
|
|
/* Query which of the given paths have substitutes. */
|
2017-02-07 19:22:48 +01:00
|
|
|
|
virtual PathSet querySubstitutablePaths(const PathSet & paths) { return {}; };
|
2007-08-12 02:29:28 +02:00
|
|
|
|
|
2012-07-11 16:43:24 +02:00
|
|
|
|
/* Query substitute info (i.e. references, derivers and download
|
|
|
|
|
sizes) of a set of paths. If a path does not have substitute
|
2016-11-26 00:37:43 +01:00
|
|
|
|
info, it's omitted from the resulting ‘infos’ map. */
|
download-from-binary-cache: parallelise fetching of NAR info files
Getting substitute information using the binary cache substituter has
non-trivial latency overhead. A package or NixOS system configuration
can have hundreds of dependencies, and in the worst case (when the
local info cache is empty) we have to do a separate HTTP request for
each of these. If the ping time to the server is t, getting N info
files will take tN seconds; e.g., with a ping time of 0.1s to
nixos.org, sequentially downloading 1000 info files (a typical NixOS
config) will take at least 100 seconds.
To fix this problem, the binary cache substituter can now perform
requests in parallel. This required changing the substituter
interface to support a function querySubstitutablePathInfos() that
queries multiple paths at the same time, and rewriting queryMissing()
to take advantage of parallelism. (Due to local caching,
parallelising queryMissing() is sufficient for most use cases, since
it's almost always called before building a derivation and thus fills
the local info cache.)
For example, parallelism speeds up querying all 1056 paths in a
particular NixOS system configuration from 116s to 2.6s. It works so
well because the eccentricity of the top-level derivation in the
dependency graph is only 9. So we only need 10 round-trips (when
using an unlimited number of parallel connections) to get everything.
Currently we do a maximum of 150 parallel connections to the server.
Thus it's important that the binary cache server (e.g. nixos.org) has
a high connection limit. Alternatively we could use HTTP pipelining,
but WWW::Curl doesn't support it and libcurl has a hard-coded limit of
5 requests per pipeline.
2012-07-07 01:08:20 +02:00
|
|
|
|
virtual void querySubstitutablePathInfos(const PathSet & paths,
|
2017-02-07 19:22:48 +01:00
|
|
|
|
SubstitutablePathInfos & infos) { return; };
|
2015-03-25 17:06:12 +01:00
|
|
|
|
|
2016-05-30 13:33:05 +02:00
|
|
|
|
virtual bool wantMassQuery() { return false; }
|
|
|
|
|
|
2016-05-04 13:36:54 +02:00
|
|
|
|
/* Import a path into the store. */
|
2016-10-21 16:50:28 +02:00
|
|
|
|
virtual void addToStore(const ValidPathInfo & info, const ref<std::string> & nar,
|
2016-10-21 18:09:30 +02:00
|
|
|
|
bool repair = false, bool dontCheckSigs = false,
|
|
|
|
|
std::shared_ptr<FSAccessor> accessor = 0) = 0;
|
2016-05-04 13:36:54 +02:00
|
|
|
|
|
2006-11-30 18:43:04 +01:00
|
|
|
|
/* Copy the contents of a path to the store and register the
|
2006-12-01 21:51:18 +01:00
|
|
|
|
validity the resulting path. The resulting path is returned.
|
2011-12-01 14:48:48 +01:00
|
|
|
|
The function object `filter' can be used to exclude files (see
|
2006-12-13 00:05:01 +01:00
|
|
|
|
libutil/archive.hh). */
|
2015-03-25 17:06:12 +01:00
|
|
|
|
virtual Path addToStore(const string & name, const Path & srcPath,
|
2008-12-03 17:10:17 +01:00
|
|
|
|
bool recursive = true, HashType hashAlgo = htSHA256,
|
2012-10-03 21:09:18 +02:00
|
|
|
|
PathFilter & filter = defaultPathFilter, bool repair = false) = 0;
|
2006-11-30 18:43:04 +01:00
|
|
|
|
|
|
|
|
|
/* Like addToStore, but the contents written to the output path is
|
|
|
|
|
a regular file containing the given string. */
|
2008-12-03 16:06:30 +01:00
|
|
|
|
virtual Path addTextToStore(const string & name, const string & s,
|
2012-10-03 21:09:18 +02:00
|
|
|
|
const PathSet & references, bool repair = false) = 0;
|
2006-11-30 19:02:04 +01:00
|
|
|
|
|
2016-03-21 17:55:57 +01:00
|
|
|
|
/* Write a NAR dump of a store path. */
|
2016-03-22 14:21:45 +01:00
|
|
|
|
virtual void narFromPath(const Path & path, Sink & sink) = 0;
|
2016-03-21 17:55:57 +01:00
|
|
|
|
|
2012-06-27 22:58:15 +02:00
|
|
|
|
/* For each path, if it's a derivation, build it. Building a
|
|
|
|
|
derivation means ensuring that the output paths are valid. If
|
2006-11-30 19:02:04 +01:00
|
|
|
|
they are already valid, this is a no-op. Otherwise, validity
|
2007-08-12 02:29:28 +02:00
|
|
|
|
can be reached in two ways. First, if the output paths is
|
|
|
|
|
substitutable, then build the path that way. Second, the
|
|
|
|
|
output paths can be created by running the builder, after
|
2012-06-27 22:58:15 +02:00
|
|
|
|
recursively building any sub-derivations. For inputs that are
|
|
|
|
|
not derivations, substitute them. */
|
2017-05-01 13:43:34 +02:00
|
|
|
|
virtual void buildPaths(const PathSet & paths, BuildMode buildMode = bmNormal);
|
2006-11-30 19:02:04 +01:00
|
|
|
|
|
Allow remote builds without sending the derivation closure
Previously, to build a derivation remotely, we had to copy the entire
closure of the .drv file to the remote machine, even though we only
need the top-level derivation. This is very wasteful: the closure can
contain thousands of store paths, and in some Hydra use cases, include
source paths that are very large (e.g. Git/Mercurial checkouts).
So now there is a new operation, StoreAPI::buildDerivation(), that
performs a build from an in-memory representation of a derivation
(BasicDerivation) rather than from a on-disk .drv file. The only files
that need to be in the Nix store are the sources of the derivation
(drv.inputSrcs), and the needed output paths of the dependencies (as
described by drv.inputDrvs). "nix-store --serve" exposes this
interface.
Note that this is a privileged operation, because you can construct a
derivation that builds any store path whatsoever. Fixing this will
require changing the hashing scheme (i.e., the output paths should be
computed from the other fields in BasicDerivation, allowing them to be
verified without access to other derivations). However, this would be
quite nice because it would allow .drv-free building (e.g. "nix-env
-i" wouldn't have to write any .drv files to disk).
Fixes #173.
2015-07-17 17:57:40 +02:00
|
|
|
|
/* Build a single non-materialized derivation (i.e. not from an
|
2016-11-26 00:37:43 +01:00
|
|
|
|
on-disk .drv file). Note that ‘drvPath’ is only used for
|
Allow remote builds without sending the derivation closure
Previously, to build a derivation remotely, we had to copy the entire
closure of the .drv file to the remote machine, even though we only
need the top-level derivation. This is very wasteful: the closure can
contain thousands of store paths, and in some Hydra use cases, include
source paths that are very large (e.g. Git/Mercurial checkouts).
So now there is a new operation, StoreAPI::buildDerivation(), that
performs a build from an in-memory representation of a derivation
(BasicDerivation) rather than from a on-disk .drv file. The only files
that need to be in the Nix store are the sources of the derivation
(drv.inputSrcs), and the needed output paths of the dependencies (as
described by drv.inputDrvs). "nix-store --serve" exposes this
interface.
Note that this is a privileged operation, because you can construct a
derivation that builds any store path whatsoever. Fixing this will
require changing the hashing scheme (i.e., the output paths should be
computed from the other fields in BasicDerivation, allowing them to be
verified without access to other derivations). However, this would be
quite nice because it would allow .drv-free building (e.g. "nix-env
-i" wouldn't have to write any .drv files to disk).
Fixes #173.
2015-07-17 17:57:40 +02:00
|
|
|
|
informational purposes. */
|
|
|
|
|
virtual BuildResult buildDerivation(const Path & drvPath, const BasicDerivation & drv,
|
|
|
|
|
BuildMode buildMode = bmNormal) = 0;
|
|
|
|
|
|
2006-11-30 19:02:04 +01:00
|
|
|
|
/* Ensure that a path is valid. If it is not currently valid, it
|
|
|
|
|
may be made valid by running a substitute (if defined for the
|
|
|
|
|
path). */
|
2006-12-01 19:00:01 +01:00
|
|
|
|
virtual void ensurePath(const Path & path) = 0;
|
2006-12-02 17:41:36 +01:00
|
|
|
|
|
|
|
|
|
/* Add a store path as a temporary root of the garbage collector.
|
|
|
|
|
The root disappears as soon as we exit. */
|
|
|
|
|
virtual void addTempRoot(const Path & path) = 0;
|
|
|
|
|
|
2006-12-05 00:29:16 +01:00
|
|
|
|
/* Add an indirect root, which is merely a symlink to `path' from
|
|
|
|
|
/nix/var/nix/gcroots/auto/<hash of `path'>. `path' is supposed
|
|
|
|
|
to be a symlink to a store path. The garbage collector will
|
|
|
|
|
automatically remove the indirect root when it finds that
|
|
|
|
|
`path' has disappeared. */
|
|
|
|
|
virtual void addIndirectRoot(const Path & path) = 0;
|
|
|
|
|
|
2006-12-02 17:41:36 +01:00
|
|
|
|
/* Acquire the global GC lock, then immediately release it. This
|
|
|
|
|
function must be called after registering a new permanent root,
|
|
|
|
|
but before exiting. Otherwise, it is possible that a running
|
|
|
|
|
garbage collector doesn't see the new root and deletes the
|
|
|
|
|
stuff we've just built. By acquiring the lock briefly, we
|
|
|
|
|
ensure that either:
|
|
|
|
|
|
|
|
|
|
- The collector is already running, and so we block until the
|
|
|
|
|
collector is finished. The collector will know about our
|
|
|
|
|
*temporary* locks, which should include whatever it is we
|
|
|
|
|
want to register as a permanent lock.
|
|
|
|
|
|
|
|
|
|
- The collector isn't running, or it's just started but hasn't
|
|
|
|
|
acquired the GC lock yet. In that case we get and release
|
|
|
|
|
the lock right away, then exit. The collector scans the
|
|
|
|
|
permanent root and sees our's.
|
|
|
|
|
|
|
|
|
|
In either case the permanent root is seen by the collector. */
|
2017-02-07 19:22:48 +01:00
|
|
|
|
virtual void syncWithGC() { };
|
2006-12-02 17:41:36 +01:00
|
|
|
|
|
2006-12-05 02:31:45 +01:00
|
|
|
|
/* Find the roots of the garbage collector. Each root is a pair
|
|
|
|
|
(link, storepath) where `link' is the path of the symlink
|
|
|
|
|
outside of the Nix store that point to `storePath'. */
|
|
|
|
|
virtual Roots findRoots() = 0;
|
|
|
|
|
|
2008-06-18 11:34:17 +02:00
|
|
|
|
/* Perform a garbage collection. */
|
|
|
|
|
virtual void collectGarbage(const GCOptions & options, GCResults & results) = 0;
|
2010-05-04 12:45:10 +02:00
|
|
|
|
|
2010-11-16 18:11:46 +01:00
|
|
|
|
/* Return a string representing information about the path that
|
|
|
|
|
can be loaded into the database using `nix-store --load-db' or
|
|
|
|
|
`nix-store --register-validity'. */
|
|
|
|
|
string makeValidityRegistration(const PathSet & paths,
|
|
|
|
|
bool showDerivers, bool showHash);
|
2014-09-01 22:21:42 +02:00
|
|
|
|
|
exportReferencesGraph: Export more complete info in JSON format
This writes info about every path in the closure in the same format as
‘nix path-info --json’. Thus it also includes NAR hashes and sizes.
Example:
[
{
"path": "/nix/store/10h6li26i7g6z3mdpvra09yyf10mmzdr-hello-2.10",
"narHash": "sha256:0ckdc4z20kkmpqdilx0wl6cricxv90lh85xpv2qljppcmz6vzcxl",
"narSize": 197648,
"references": [
"/nix/store/10h6li26i7g6z3mdpvra09yyf10mmzdr-hello-2.10",
"/nix/store/27binbdy296qvjycdgr1535v8872vz3z-glibc-2.24"
],
"closureSize": 20939776
},
{
"path": "/nix/store/27binbdy296qvjycdgr1535v8872vz3z-glibc-2.24",
"narHash": "sha256:1nfn3m3p98y1c0kd0brp80dn9n5mycwgrk183j17rajya0h7gax3",
"narSize": 20742128,
"references": [
"/nix/store/27binbdy296qvjycdgr1535v8872vz3z-glibc-2.24"
],
"closureSize": 20742128
}
]
Fixes #1134.
2017-01-26 20:36:20 +01:00
|
|
|
|
/* Write a JSON representation of store path metadata, such as the
|
|
|
|
|
hash and the references. If ‘includeImpureInfo’ is true,
|
|
|
|
|
variable elements such as the registration time are
|
|
|
|
|
included. If ‘showClosureSize’ is true, the closure size of
|
|
|
|
|
each path is included. */
|
|
|
|
|
void pathInfoToJSON(JSONPlaceholder & jsonOut, const PathSet & storePaths,
|
|
|
|
|
bool includeImpureInfo, bool showClosureSize);
|
|
|
|
|
|
|
|
|
|
/* Return the size of the closure of the specified path, that is,
|
|
|
|
|
the sum of the size of the NAR serialisation of each path in
|
|
|
|
|
the closure. */
|
|
|
|
|
unsigned long long getClosureSize(const Path & storePath);
|
|
|
|
|
|
2014-09-01 22:21:42 +02:00
|
|
|
|
/* Optimise the disk space usage of the Nix store by hard-linking files
|
|
|
|
|
with the same contents. */
|
2017-02-07 19:22:48 +01:00
|
|
|
|
virtual void optimiseStore() { };
|
2015-06-01 23:20:11 +02:00
|
|
|
|
|
|
|
|
|
/* Check the integrity of the Nix store. Returns true if errors
|
|
|
|
|
remain. */
|
2017-02-07 19:22:48 +01:00
|
|
|
|
virtual bool verifyStore(bool checkContents, bool repair) { return false; };
|
Eliminate the "store" global variable
Also, move a few free-standing functions into StoreAPI and Derivation.
Also, introduce a non-nullable smart pointer, ref<T>, which is just a
wrapper around std::shared_ptr ensuring that the pointer is never
null. (For reference-counted values, this is better than passing a
"T&", because the latter doesn't maintain the refcount. Usually, the
caller will have a shared_ptr keeping the value alive, but that's not
always the case, e.g., when passing a reference to a std::thread via
std::bind.)
2016-02-04 14:28:26 +01:00
|
|
|
|
|
2016-02-25 17:43:19 +01:00
|
|
|
|
/* Return an object to access files in the Nix store. */
|
|
|
|
|
virtual ref<FSAccessor> getFSAccessor() = 0;
|
|
|
|
|
|
2016-04-05 15:30:22 +02:00
|
|
|
|
/* Add signatures to the specified store path. The signatures are
|
|
|
|
|
not verified. */
|
|
|
|
|
virtual void addSignatures(const Path & storePath, const StringSet & sigs) = 0;
|
|
|
|
|
|
Eliminate the "store" global variable
Also, move a few free-standing functions into StoreAPI and Derivation.
Also, introduce a non-nullable smart pointer, ref<T>, which is just a
wrapper around std::shared_ptr ensuring that the pointer is never
null. (For reference-counted values, this is better than passing a
"T&", because the latter doesn't maintain the refcount. Usually, the
caller will have a shared_ptr keeping the value alive, but that's not
always the case, e.g., when passing a reference to a std::thread via
std::bind.)
2016-02-04 14:28:26 +01:00
|
|
|
|
/* Utility functions. */
|
|
|
|
|
|
|
|
|
|
/* Read a derivation, after ensuring its existence through
|
|
|
|
|
ensurePath(). */
|
|
|
|
|
Derivation derivationFromPath(const Path & drvPath);
|
|
|
|
|
|
2016-11-10 17:45:04 +01:00
|
|
|
|
/* Place in `out' the set of all store paths in the file system
|
Eliminate the "store" global variable
Also, move a few free-standing functions into StoreAPI and Derivation.
Also, introduce a non-nullable smart pointer, ref<T>, which is just a
wrapper around std::shared_ptr ensuring that the pointer is never
null. (For reference-counted values, this is better than passing a
"T&", because the latter doesn't maintain the refcount. Usually, the
caller will have a shared_ptr keeping the value alive, but that's not
always the case, e.g., when passing a reference to a std::thread via
std::bind.)
2016-02-04 14:28:26 +01:00
|
|
|
|
closure of `storePath'; that is, all paths than can be directly
|
2016-11-10 17:45:04 +01:00
|
|
|
|
or indirectly reached from it. `out' is not cleared. If
|
Eliminate the "store" global variable
Also, move a few free-standing functions into StoreAPI and Derivation.
Also, introduce a non-nullable smart pointer, ref<T>, which is just a
wrapper around std::shared_ptr ensuring that the pointer is never
null. (For reference-counted values, this is better than passing a
"T&", because the latter doesn't maintain the refcount. Usually, the
caller will have a shared_ptr keeping the value alive, but that's not
always the case, e.g., when passing a reference to a std::thread via
std::bind.)
2016-02-04 14:28:26 +01:00
|
|
|
|
`flipDirection' is true, the set of paths that can reach
|
|
|
|
|
`storePath' is returned; that is, the closures under the
|
|
|
|
|
`referrers' relation instead of the `references' relation is
|
|
|
|
|
returned. */
|
2017-03-16 11:44:01 +01:00
|
|
|
|
virtual void computeFSClosure(const PathSet & paths,
|
2016-11-10 17:45:04 +01:00
|
|
|
|
PathSet & out, bool flipDirection = false,
|
|
|
|
|
bool includeOutputs = false, bool includeDerivers = false);
|
|
|
|
|
|
Eliminate the "store" global variable
Also, move a few free-standing functions into StoreAPI and Derivation.
Also, introduce a non-nullable smart pointer, ref<T>, which is just a
wrapper around std::shared_ptr ensuring that the pointer is never
null. (For reference-counted values, this is better than passing a
"T&", because the latter doesn't maintain the refcount. Usually, the
caller will have a shared_ptr keeping the value alive, but that's not
always the case, e.g., when passing a reference to a std::thread via
std::bind.)
2016-02-04 14:28:26 +01:00
|
|
|
|
void computeFSClosure(const Path & path,
|
2016-11-10 17:45:04 +01:00
|
|
|
|
PathSet & out, bool flipDirection = false,
|
Eliminate the "store" global variable
Also, move a few free-standing functions into StoreAPI and Derivation.
Also, introduce a non-nullable smart pointer, ref<T>, which is just a
wrapper around std::shared_ptr ensuring that the pointer is never
null. (For reference-counted values, this is better than passing a
"T&", because the latter doesn't maintain the refcount. Usually, the
caller will have a shared_ptr keeping the value alive, but that's not
always the case, e.g., when passing a reference to a std::thread via
std::bind.)
2016-02-04 14:28:26 +01:00
|
|
|
|
bool includeOutputs = false, bool includeDerivers = false);
|
|
|
|
|
|
|
|
|
|
/* Given a set of paths that are to be built, return the set of
|
|
|
|
|
derivations that will be built, and the set of output paths
|
|
|
|
|
that will be substituted. */
|
2017-04-06 18:40:19 +02:00
|
|
|
|
virtual void queryMissing(const PathSet & targets,
|
Eliminate the "store" global variable
Also, move a few free-standing functions into StoreAPI and Derivation.
Also, introduce a non-nullable smart pointer, ref<T>, which is just a
wrapper around std::shared_ptr ensuring that the pointer is never
null. (For reference-counted values, this is better than passing a
"T&", because the latter doesn't maintain the refcount. Usually, the
caller will have a shared_ptr keeping the value alive, but that's not
always the case, e.g., when passing a reference to a std::thread via
std::bind.)
2016-02-04 14:28:26 +01:00
|
|
|
|
PathSet & willBuild, PathSet & willSubstitute, PathSet & unknown,
|
|
|
|
|
unsigned long long & downloadSize, unsigned long long & narSize);
|
|
|
|
|
|
|
|
|
|
/* Sort a set of paths topologically under the references
|
|
|
|
|
relation. If p refers to q, then p preceeds q in this list. */
|
|
|
|
|
Paths topoSortPaths(const PathSet & paths);
|
|
|
|
|
|
2016-11-26 00:37:43 +01:00
|
|
|
|
/* Export multiple paths in the format expected by ‘nix-store
|
|
|
|
|
--import’. */
|
2016-05-04 13:36:54 +02:00
|
|
|
|
void exportPaths(const Paths & paths, Sink & sink);
|
|
|
|
|
|
|
|
|
|
void exportPath(const Path & path, Sink & sink);
|
|
|
|
|
|
|
|
|
|
/* Import a sequence of NAR dumps created by exportPaths() into
|
|
|
|
|
the Nix store. Optionally, the contents of the NARs are
|
|
|
|
|
preloaded into the specified FS accessor to speed up subsequent
|
|
|
|
|
access. */
|
2016-05-31 11:18:45 +02:00
|
|
|
|
Paths importPaths(Source & source, std::shared_ptr<FSAccessor> accessor,
|
|
|
|
|
bool dontCheckSigs = false);
|
2016-05-04 13:36:54 +02:00
|
|
|
|
|
2016-04-19 18:50:15 +02:00
|
|
|
|
struct Stats
|
|
|
|
|
{
|
|
|
|
|
std::atomic<uint64_t> narInfoRead{0};
|
|
|
|
|
std::atomic<uint64_t> narInfoReadAverted{0};
|
|
|
|
|
std::atomic<uint64_t> narInfoMissing{0};
|
|
|
|
|
std::atomic<uint64_t> narInfoWrite{0};
|
|
|
|
|
std::atomic<uint64_t> pathInfoCacheSize{0};
|
|
|
|
|
std::atomic<uint64_t> narRead{0};
|
|
|
|
|
std::atomic<uint64_t> narReadBytes{0};
|
|
|
|
|
std::atomic<uint64_t> narReadCompressedBytes{0};
|
|
|
|
|
std::atomic<uint64_t> narWrite{0};
|
|
|
|
|
std::atomic<uint64_t> narWriteAverted{0};
|
|
|
|
|
std::atomic<uint64_t> narWriteBytes{0};
|
|
|
|
|
std::atomic<uint64_t> narWriteCompressedBytes{0};
|
|
|
|
|
std::atomic<uint64_t> narWriteCompressionTimeMs{0};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const Stats & getStats();
|
|
|
|
|
|
2017-03-13 12:07:50 +01:00
|
|
|
|
/* Return the build log of the specified store path, if available,
|
|
|
|
|
or null otherwise. */
|
|
|
|
|
virtual std::shared_ptr<std::string> getBuildLog(const Path & path)
|
|
|
|
|
{ return nullptr; }
|
|
|
|
|
|
2017-04-06 15:22:37 +02:00
|
|
|
|
/* Hack to allow long-running processes like hydra-queue-runner to
|
|
|
|
|
occasionally flush their path info cache. */
|
|
|
|
|
void clearPathInfoCache()
|
|
|
|
|
{
|
|
|
|
|
state.lock()->pathInfoCache.clear();
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-02 14:18:46 +02:00
|
|
|
|
/* Establish a connection to the store, for store types that have
|
|
|
|
|
a notion of connection. Otherwise this is a no-op. */
|
|
|
|
|
virtual void connect() { };
|
|
|
|
|
|
2016-04-19 18:50:15 +02:00
|
|
|
|
protected:
|
|
|
|
|
|
|
|
|
|
Stats stats;
|
|
|
|
|
|
2017-05-01 13:43:34 +02:00
|
|
|
|
/* Unsupported methods. */
|
|
|
|
|
[[noreturn]] void unsupported()
|
|
|
|
|
{
|
|
|
|
|
throw Unsupported("requested operation is not supported by store ‘%s’", getUri());
|
|
|
|
|
}
|
|
|
|
|
|
2006-11-30 18:43:04 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2016-09-02 20:15:04 +02:00
|
|
|
|
class LocalFSStore : public virtual Store
|
2016-02-25 17:43:19 +01:00
|
|
|
|
{
|
2016-03-21 17:55:57 +01:00
|
|
|
|
public:
|
2017-04-13 15:55:38 +02:00
|
|
|
|
|
|
|
|
|
// FIXME: the (Store*) cast works around a bug in gcc that causes
|
|
|
|
|
// it to emit the call to the Option constructor. Clang works fine
|
|
|
|
|
// either way.
|
|
|
|
|
const PathSetting rootDir{(Store*) this, true, "",
|
|
|
|
|
"root", "directory prefixed to all other paths"};
|
|
|
|
|
const PathSetting stateDir{(Store*) this, false,
|
|
|
|
|
rootDir != "" ? rootDir + "/nix/var/nix" : settings.nixStateDir,
|
|
|
|
|
"state", "directory where Nix will store state"};
|
|
|
|
|
const PathSetting logDir{(Store*) this, false,
|
|
|
|
|
rootDir != "" ? rootDir + "/nix/var/log/nix" : settings.nixLogDir,
|
|
|
|
|
"log", "directory where Nix will store state"};
|
|
|
|
|
|
2017-03-13 12:07:50 +01:00
|
|
|
|
const static string drvsLogDir;
|
2016-06-02 13:33:49 +02:00
|
|
|
|
|
|
|
|
|
LocalFSStore(const Params & params);
|
|
|
|
|
|
2016-03-22 14:21:45 +01:00
|
|
|
|
void narFromPath(const Path & path, Sink & sink) override;
|
2016-02-25 17:43:19 +01:00
|
|
|
|
ref<FSAccessor> getFSAccessor() override;
|
2016-06-02 13:33:49 +02:00
|
|
|
|
|
|
|
|
|
/* Register a permanent GC root. */
|
|
|
|
|
Path addPermRoot(const Path & storePath,
|
|
|
|
|
const Path & gcRoot, bool indirect, bool allowOutsideRootsDir = false);
|
2016-06-02 18:43:36 +02:00
|
|
|
|
|
|
|
|
|
virtual Path getRealStoreDir() { return storeDir; }
|
2016-06-03 15:45:11 +02:00
|
|
|
|
|
|
|
|
|
Path toRealPath(const Path & storePath)
|
|
|
|
|
{
|
|
|
|
|
return getRealStoreDir() + "/" + baseNameOf(storePath);
|
|
|
|
|
}
|
2017-03-13 12:07:50 +01:00
|
|
|
|
|
|
|
|
|
std::shared_ptr<std::string> getBuildLog(const Path & path) override;
|
2016-02-25 17:43:19 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2011-07-20 20:10:47 +02:00
|
|
|
|
/* Extract the name part of the given store path. */
|
|
|
|
|
string storePathToName(const Path & path);
|
2015-03-25 17:06:12 +01:00
|
|
|
|
|
2016-02-15 12:49:01 +01:00
|
|
|
|
/* Extract the hash part of the given store path. */
|
|
|
|
|
string storePathToHash(const Path & path);
|
|
|
|
|
|
2016-11-26 00:37:43 +01:00
|
|
|
|
/* Check whether ‘name’ is a valid store path name part, i.e. contains
|
2016-06-01 14:49:12 +02:00
|
|
|
|
only the characters [a-zA-Z0-9\+\-\.\_\?\=] and doesn't start with
|
|
|
|
|
a dot. */
|
2006-11-30 18:43:04 +01:00
|
|
|
|
void checkStoreName(const string & name);
|
|
|
|
|
|
2007-11-29 17:18:24 +01:00
|
|
|
|
|
2016-05-03 14:45:50 +02:00
|
|
|
|
/* Copy a path from one store to another. */
|
|
|
|
|
void copyStorePath(ref<Store> srcStore, ref<Store> dstStore,
|
2016-11-09 19:08:20 +01:00
|
|
|
|
const Path & storePath, bool repair = false, bool dontCheckSigs = false);
|
2016-05-03 14:45:50 +02:00
|
|
|
|
|
|
|
|
|
|
2016-10-07 19:15:25 +02:00
|
|
|
|
/* Copy the closure of the specified paths from one store to another. */
|
|
|
|
|
void copyClosure(ref<Store> srcStore, ref<Store> dstStore,
|
2016-11-09 19:08:20 +01:00
|
|
|
|
const PathSet & storePaths, bool repair = false, bool dontCheckSigs = false);
|
2016-10-07 19:15:25 +02:00
|
|
|
|
|
|
|
|
|
|
2006-12-05 03:18:46 +01:00
|
|
|
|
/* Remove the temporary roots file for this process. Any temporary
|
|
|
|
|
root becomes garbage after this point unless it has been registered
|
|
|
|
|
as a (permanent) root. */
|
|
|
|
|
void removeTempRoots();
|
|
|
|
|
|
|
|
|
|
|
2016-02-24 14:48:16 +01:00
|
|
|
|
/* Return a Store object to access the Nix store denoted by
|
2016-11-26 00:37:43 +01:00
|
|
|
|
‘uri’ (slight misnomer...). Supported values are:
|
2016-02-24 14:48:16 +01:00
|
|
|
|
|
2017-05-01 17:35:30 +02:00
|
|
|
|
* ‘local’: The Nix store in /nix/store and database in
|
2016-02-24 14:48:16 +01:00
|
|
|
|
/nix/var/nix/db, accessed directly.
|
|
|
|
|
|
2016-11-26 00:37:43 +01:00
|
|
|
|
* ‘daemon’: The Nix store accessed via a Unix domain socket
|
2016-02-24 14:48:16 +01:00
|
|
|
|
connection to nix-daemon.
|
|
|
|
|
|
2017-05-01 17:35:30 +02:00
|
|
|
|
* ‘auto’ or ‘’: Equivalent to ‘local’ or ‘daemon’ depending on
|
|
|
|
|
whether the user has write access to the local Nix
|
|
|
|
|
store/database.
|
|
|
|
|
|
2016-11-26 00:37:43 +01:00
|
|
|
|
* ‘file://<path>’: A binary cache stored in <path>.
|
2016-02-24 14:48:16 +01:00
|
|
|
|
|
2017-05-01 17:35:30 +02:00
|
|
|
|
* ‘https://<path>’: A binary cache accessed via HTTP.
|
|
|
|
|
|
|
|
|
|
* ‘s3://<path>’: A writable binary cache stored on Amazon's Simple
|
|
|
|
|
Storage Service.
|
|
|
|
|
|
|
|
|
|
* ‘ssh://[user@]<host>’: A remote Nix store accessed by running
|
|
|
|
|
‘nix-store --serve’ via SSH.
|
2016-02-24 14:48:16 +01:00
|
|
|
|
|
2017-05-01 17:35:30 +02:00
|
|
|
|
You can pass parameters to the store implementation by appending
|
|
|
|
|
‘?key=value&key=value&...’ to the URI.
|
|
|
|
|
*/
|
|
|
|
|
ref<Store> openStore(const std::string & uri = getEnv("NIX_REMOTE"),
|
|
|
|
|
const Store::Params & extraParams = Store::Params());
|
2017-03-03 19:23:20 +01:00
|
|
|
|
|
2016-02-24 14:48:16 +01:00
|
|
|
|
|
2017-05-01 20:03:25 +02:00
|
|
|
|
void copyPaths(ref<Store> from, ref<Store> to, const PathSet & storePaths,
|
|
|
|
|
bool substitute = false, bool dontCheckSigs = false);
|
2016-07-19 00:50:27 +02:00
|
|
|
|
|
2016-09-02 12:39:29 +02:00
|
|
|
|
enum StoreType {
|
|
|
|
|
tDaemon,
|
|
|
|
|
tLocal,
|
|
|
|
|
tOther
|
|
|
|
|
};
|
|
|
|
|
|
2008-06-09 15:52:45 +02:00
|
|
|
|
|
2016-09-02 12:39:29 +02:00
|
|
|
|
StoreType getStoreType(const std::string & uri = getEnv("NIX_REMOTE"), const std::string & stateDir = settings.nixStateDir);
|
2008-06-09 15:52:45 +02:00
|
|
|
|
|
2016-04-29 13:57:08 +02:00
|
|
|
|
/* Return the default substituter stores, defined by the
|
2016-11-26 00:37:43 +01:00
|
|
|
|
‘substituters’ option and various legacy options like
|
|
|
|
|
‘binary-caches’. */
|
2016-04-29 13:57:08 +02:00
|
|
|
|
std::list<ref<Store>> getDefaultSubstituters();
|
|
|
|
|
|
|
|
|
|
|
2016-02-29 16:11:11 +01:00
|
|
|
|
/* Store implementation registration. */
|
2016-04-29 16:26:16 +02:00
|
|
|
|
typedef std::function<std::shared_ptr<Store>(
|
2016-06-01 14:49:12 +02:00
|
|
|
|
const std::string & uri, const Store::Params & params)> OpenStore;
|
2016-02-29 16:11:11 +01:00
|
|
|
|
|
|
|
|
|
struct RegisterStoreImplementation
|
|
|
|
|
{
|
|
|
|
|
typedef std::vector<OpenStore> Implementations;
|
|
|
|
|
static Implementations * implementations;
|
|
|
|
|
|
|
|
|
|
RegisterStoreImplementation(OpenStore fun)
|
|
|
|
|
{
|
|
|
|
|
if (!implementations) implementations = new Implementations;
|
|
|
|
|
implementations->push_back(fun);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-06-09 15:52:45 +02:00
|
|
|
|
/* Display a set of paths in human-readable form (i.e., between quotes
|
|
|
|
|
and separated by commas). */
|
|
|
|
|
string showPaths(const PathSet & paths);
|
2006-11-30 18:43:04 +01:00
|
|
|
|
|
|
|
|
|
|
2008-01-29 19:17:36 +01:00
|
|
|
|
ValidPathInfo decodeValidPathInfo(std::istream & str,
|
|
|
|
|
bool hashGiven = false);
|
2007-08-12 02:29:28 +02:00
|
|
|
|
|
|
|
|
|
|
2017-02-22 16:31:04 +01:00
|
|
|
|
/* Compute the content-addressability assertion (ValidPathInfo::ca)
|
|
|
|
|
for paths created by makeFixedOutputPath() / addToStore(). */
|
|
|
|
|
std::string makeFixedOutputCA(bool recursive, const Hash & hash);
|
|
|
|
|
|
2006-11-30 18:43:04 +01:00
|
|
|
|
}
|