2012-07-18 18:59:03 +00:00
|
|
|
|
#pragma once
|
2006-11-30 17:43:04 +00:00
|
|
|
|
|
2020-10-08 15:36:51 +00:00
|
|
|
|
#include "realisation.hh"
|
2019-12-05 18:11:09 +00:00
|
|
|
|
#include "path.hh"
|
2010-10-04 17:55:38 +00:00
|
|
|
|
#include "hash.hh"
|
2020-06-02 19:44:58 +00:00
|
|
|
|
#include "content-address.hh"
|
2010-10-04 17:55:38 +00:00
|
|
|
|
#include "serialise.hh"
|
2016-04-19 16:50:15 +00:00
|
|
|
|
#include "lru-cache.hh"
|
|
|
|
|
#include "sync.hh"
|
2016-09-02 10:39:29 +00:00
|
|
|
|
#include "globals.hh"
|
2017-04-13 13:55:38 +00:00
|
|
|
|
#include "config.hh"
|
2020-03-21 15:07:16 +00:00
|
|
|
|
#include "derivations.hh"
|
2020-06-24 21:22:13 +00:00
|
|
|
|
#include "path-info.hh"
|
2010-10-04 17:55:38 +00:00
|
|
|
|
|
2016-04-19 16:50:15 +00:00
|
|
|
|
#include <atomic>
|
2015-08-21 11:57:53 +00:00
|
|
|
|
#include <limits>
|
2006-12-05 01:31:45 +00:00
|
|
|
|
#include <map>
|
2019-03-14 15:00:00 +00:00
|
|
|
|
#include <unordered_map>
|
2019-03-14 12:27:16 +00:00
|
|
|
|
#include <unordered_set>
|
2014-03-29 23:49:23 +00:00
|
|
|
|
#include <memory>
|
2016-04-19 16:50:15 +00:00
|
|
|
|
#include <string>
|
2020-03-11 19:04:47 +00:00
|
|
|
|
#include <chrono>
|
2020-06-01 22:53:31 +00:00
|
|
|
|
#include <variant>
|
2006-11-30 17:43:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
|
2020-09-14 09:18:45 +00:00
|
|
|
|
/**
|
|
|
|
|
* About the class hierarchy of the store implementations:
|
|
|
|
|
*
|
|
|
|
|
* Each store type `Foo` consists of two classes:
|
|
|
|
|
*
|
|
|
|
|
* 1. A class `FooConfig : virtual StoreConfig` that contains the configuration
|
|
|
|
|
* for the store
|
|
|
|
|
*
|
|
|
|
|
* It should only contain members of type `const Setting<T>` (or subclasses
|
|
|
|
|
* of it) and inherit the constructors of `StoreConfig`
|
|
|
|
|
* (`using StoreConfig::StoreConfig`).
|
|
|
|
|
*
|
|
|
|
|
* 2. A class `Foo : virtual Store, virtual FooConfig` that contains the
|
|
|
|
|
* implementation of the store.
|
|
|
|
|
*
|
|
|
|
|
* This class is expected to have a constructor `Foo(const Params & params)`
|
|
|
|
|
* that calls `StoreConfig(params)` (otherwise you're gonna encounter an
|
|
|
|
|
* `assertion failure` when trying to instantiate it).
|
|
|
|
|
*
|
|
|
|
|
* You can then register the new store using:
|
|
|
|
|
*
|
|
|
|
|
* ```
|
|
|
|
|
* cpp static RegisterStoreImplementation<Foo, FooConfig> regStore;
|
|
|
|
|
* ```
|
|
|
|
|
*/
|
2006-11-30 17:43:04 +00:00
|
|
|
|
|
2019-11-10 16:14:26 +00:00
|
|
|
|
MakeError(SubstError, Error);
|
2019-11-10 21:21:59 +00:00
|
|
|
|
MakeError(BuildError, Error); // denotes a permanent build failure
|
2019-11-10 16:14:26 +00:00
|
|
|
|
MakeError(InvalidPath, Error);
|
|
|
|
|
MakeError(Unsupported, Error);
|
|
|
|
|
MakeError(SubstituteGone, Error);
|
|
|
|
|
MakeError(SubstituterDisabled, Error);
|
2020-07-13 14:19:37 +00:00
|
|
|
|
MakeError(BadStorePath, Error);
|
2017-05-01 11:43:34 +00:00
|
|
|
|
|
2020-09-08 12:50:23 +00:00
|
|
|
|
MakeError(InvalidStoreURI, Error);
|
2017-05-01 11:43:34 +00:00
|
|
|
|
|
2016-08-03 11:17:11 +00:00
|
|
|
|
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 19:36:20 +00:00
|
|
|
|
class JSONPlaceholder;
|
2016-08-03 11:17:11 +00:00
|
|
|
|
|
|
|
|
|
|
2017-06-28 16:11:01 +00:00
|
|
|
|
enum CheckSigsFlag : bool { NoCheckSigs = false, CheckSigs = true };
|
|
|
|
|
enum SubstituteFlag : bool { NoSubstitute = false, Substitute = true };
|
2017-07-14 13:27:21 +00:00
|
|
|
|
enum AllowInvalidFlag : bool { DisallowInvalid = false, AllowInvalid = true };
|
2017-06-28 16:11:01 +00:00
|
|
|
|
|
2016-05-04 11:36:54 +00:00
|
|
|
|
/* Magic header of exportPath() output (obsolete). */
|
2016-02-15 13:48:38 +00:00
|
|
|
|
const uint32_t exportMagic = 0x4558494e;
|
|
|
|
|
|
|
|
|
|
|
2019-12-05 18:11:09 +00:00
|
|
|
|
typedef std::unordered_map<StorePath, std::unordered_set<std::string>> Roots;
|
2006-12-05 01:31:45 +00:00
|
|
|
|
|
|
|
|
|
|
2008-06-18 09:34:17 +00: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 11:57:53 +00:00
|
|
|
|
GCAction action{gcDeleteDead};
|
2008-06-18 09:34:17 +00: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 11:57:53 +00:00
|
|
|
|
bool ignoreLiveness{false};
|
2008-06-18 09:34:17 +00:00
|
|
|
|
|
|
|
|
|
/* For `gcDeleteSpecific', the paths to delete. */
|
2019-12-05 18:11:09 +00:00
|
|
|
|
StorePathSet pathsToDelete;
|
2008-06-18 09:34:17 +00:00
|
|
|
|
|
2012-08-01 23:14:30 +00:00
|
|
|
|
/* Stop after at least `maxFreed' bytes have been freed. */
|
2020-07-30 11:10:49 +00:00
|
|
|
|
uint64_t maxFreed{std::numeric_limits<uint64_t>::max()};
|
2008-06-18 09:34:17 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2015-03-25 16:06:12 +00:00
|
|
|
|
struct GCResults
|
2008-06-18 09:34:17 +00: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. */
|
2020-07-30 11:10:49 +00:00
|
|
|
|
uint64_t bytesFreed = 0;
|
2008-06-18 09:34:17 +00:00
|
|
|
|
};
|
2006-12-05 02:18:46 +00:00
|
|
|
|
|
|
|
|
|
|
2018-02-03 09:04:29 +00:00
|
|
|
|
enum BuildMode { bmNormal, bmRepair, bmCheck };
|
2014-02-18 00:01:14 +00: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 15:57:40 +00:00
|
|
|
|
struct BuildResult
|
|
|
|
|
{
|
2016-10-26 13:02:38 +00: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 15:57:40 +00:00
|
|
|
|
enum Status {
|
2015-07-20 01:15:45 +00:00
|
|
|
|
Built = 0,
|
|
|
|
|
Substituted,
|
|
|
|
|
AlreadyValid,
|
|
|
|
|
PermanentFailure,
|
|
|
|
|
InputRejected,
|
|
|
|
|
OutputRejected,
|
|
|
|
|
TransientFailure, // possibly transient
|
2016-10-26 13:02:38 +00:00
|
|
|
|
CachedFailure, // no longer used
|
2015-07-20 01:15:45 +00:00
|
|
|
|
TimedOut,
|
|
|
|
|
MiscFailure,
|
2015-10-06 15:33:30 +00:00
|
|
|
|
DependencyFailed,
|
|
|
|
|
LogLimitExceeded,
|
2015-11-09 22:16:24 +00: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 15:57:40 +00:00
|
|
|
|
} status = MiscFailure;
|
|
|
|
|
std::string errorMsg;
|
2016-12-07 12:16:06 +00: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 15:09:38 +00: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 12:16:06 +00:00
|
|
|
|
|
2015-07-20 01:15:45 +00: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 15:57:40 +00:00
|
|
|
|
};
|
|
|
|
|
|
2020-09-10 08:55:51 +00:00
|
|
|
|
struct StoreConfig : public Config
|
2006-11-30 17:43:04 +00:00
|
|
|
|
{
|
2020-09-10 08:55:51 +00:00
|
|
|
|
using Config::Config;
|
2020-09-14 09:18:45 +00:00
|
|
|
|
|
2020-12-20 15:33:12 +00:00
|
|
|
|
StoreConfig() = delete;
|
2020-09-11 09:12:25 +00:00
|
|
|
|
|
2020-10-06 12:00:42 +00:00
|
|
|
|
virtual ~StoreConfig() { }
|
|
|
|
|
|
2020-09-14 12:04:02 +00:00
|
|
|
|
virtual const std::string name() = 0;
|
2016-06-01 12:49:12 +00:00
|
|
|
|
|
2017-04-13 13:55:38 +00: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 12:49:12 +00:00
|
|
|
|
|
2018-02-05 17:08:30 +00:00
|
|
|
|
const Setting<bool> isTrusted{this, false, "trusted", "whether paths from this store can be used as substitutes even when they lack trusted signatures"};
|
|
|
|
|
|
2019-12-17 16:17:53 +00:00
|
|
|
|
Setting<int> priority{this, 0, "priority", "priority of this substituter (lower value means higher priority)"};
|
|
|
|
|
|
|
|
|
|
Setting<bool> wantMassQuery{this, false, "want-mass-query", "whether this substituter can be queried efficiently for path validity"};
|
|
|
|
|
|
2020-08-12 16:32:36 +00:00
|
|
|
|
Setting<StringSet> systemFeatures{this, settings.systemFeatures,
|
|
|
|
|
"system-features",
|
|
|
|
|
"Optional features that the system this store builds on implements (like \"kvm\")."};
|
|
|
|
|
|
2020-09-10 08:55:51 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class Store : public std::enable_shared_from_this<Store>, public virtual StoreConfig
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
typedef std::map<std::string, std::string> Params;
|
|
|
|
|
|
2016-04-19 16:50:15 +00:00
|
|
|
|
protected:
|
|
|
|
|
|
2020-03-11 19:04:47 +00:00
|
|
|
|
struct PathInfoCacheValue {
|
|
|
|
|
|
|
|
|
|
// Time of cache entry creation or update
|
|
|
|
|
std::chrono::time_point<std::chrono::steady_clock> time_point = std::chrono::steady_clock::now();
|
|
|
|
|
|
|
|
|
|
// Null if missing
|
|
|
|
|
std::shared_ptr<const ValidPathInfo> value;
|
|
|
|
|
|
|
|
|
|
// Whether the value is valid as a cache entry. The path may not exist.
|
|
|
|
|
bool isKnownNow();
|
|
|
|
|
|
|
|
|
|
// Past tense, because a path can only be assumed to exists when
|
|
|
|
|
// isKnownNow() && didExist()
|
|
|
|
|
inline bool didExist() {
|
|
|
|
|
return value != nullptr;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2016-04-19 16:50:15 +00:00
|
|
|
|
struct State
|
|
|
|
|
{
|
2019-12-05 18:11:09 +00:00
|
|
|
|
// FIXME: fix key
|
2020-03-11 19:04:47 +00:00
|
|
|
|
LRUCache<std::string, PathInfoCacheValue> pathInfoCache;
|
2016-04-19 16:50:15 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Sync<State> state;
|
|
|
|
|
|
2016-04-20 12:12:38 +00:00
|
|
|
|
std::shared_ptr<NarInfoDiskCache> diskCache;
|
|
|
|
|
|
2016-06-01 12:49:12 +00:00
|
|
|
|
Store(const Params & params);
|
|
|
|
|
|
2006-11-30 17:43:04 +00:00
|
|
|
|
public:
|
2020-09-09 09:29:17 +00:00
|
|
|
|
/**
|
|
|
|
|
* Perform any necessary effectful operation to make the store up and
|
|
|
|
|
* running
|
|
|
|
|
*/
|
|
|
|
|
virtual void init() {};
|
2006-11-30 17:43:04 +00:00
|
|
|
|
|
2016-02-04 13:48:42 +00:00
|
|
|
|
virtual ~Store() { }
|
2006-11-30 17:43:04 +00:00
|
|
|
|
|
2016-04-29 14:26:16 +00:00
|
|
|
|
virtual std::string getUri() = 0;
|
2016-04-20 12:12:38 +00:00
|
|
|
|
|
2019-12-05 18:11:09 +00:00
|
|
|
|
StorePath parseStorePath(std::string_view path) const;
|
|
|
|
|
|
2020-02-28 17:07:10 +00:00
|
|
|
|
std::optional<StorePath> maybeParseStorePath(std::string_view path) const;
|
|
|
|
|
|
2019-12-05 18:11:09 +00:00
|
|
|
|
std::string printStorePath(const StorePath & path) const;
|
|
|
|
|
|
|
|
|
|
// FIXME: remove
|
|
|
|
|
StorePathSet parseStorePathSet(const PathSet & paths) const;
|
|
|
|
|
|
|
|
|
|
PathSet printStorePathSet(const StorePathSet & path) const;
|
|
|
|
|
|
|
|
|
|
/* Split a string specifying a derivation and a set of outputs
|
|
|
|
|
(/nix/store/hash-foo!out1,out2,...) into the derivation path
|
|
|
|
|
and the outputs. */
|
2019-12-16 18:11:47 +00:00
|
|
|
|
StorePathWithOutputs parsePathWithOutputs(const string & s);
|
2019-12-05 18:11:09 +00:00
|
|
|
|
|
|
|
|
|
/* Display a set of paths in human-readable form (i.e., between quotes
|
|
|
|
|
and separated by commas). */
|
|
|
|
|
std::string showPaths(const StorePathSet & paths);
|
|
|
|
|
|
2016-11-25 23:37:43 +00:00
|
|
|
|
/* Return true if ‘path’ is in the Nix store (but not the Nix
|
2016-06-01 12:49:12 +00:00
|
|
|
|
store itself). */
|
|
|
|
|
bool isInStore(const Path & path) const;
|
|
|
|
|
|
2016-11-25 23:37:43 +00:00
|
|
|
|
/* Return true if ‘path’ is a store path, i.e. a direct child of
|
2016-06-01 12:49:12 +00:00
|
|
|
|
the Nix store. */
|
2020-03-04 12:55:15 +00:00
|
|
|
|
bool isStorePath(std::string_view path) const;
|
2016-06-01 12:49:12 +00:00
|
|
|
|
|
2020-07-13 14:19:37 +00:00
|
|
|
|
/* Split a path like /nix/store/<hash>-<name>/<bla> into
|
|
|
|
|
/nix/store/<hash>-<name> and /<bla>. */
|
|
|
|
|
std::pair<StorePath, Path> toStorePath(const Path & path) const;
|
2016-06-01 12:49:12 +00:00
|
|
|
|
|
|
|
|
|
/* Follow symlinks until we end up with a path in the Nix store. */
|
2019-12-16 18:11:47 +00:00
|
|
|
|
Path followLinksToStore(std::string_view path) const;
|
2016-06-01 12:49:12 +00:00
|
|
|
|
|
|
|
|
|
/* Same as followLinksToStore(), but apply toStorePath() to the
|
|
|
|
|
result. */
|
2019-12-16 18:11:47 +00:00
|
|
|
|
StorePath followLinksToStorePath(std::string_view path) const;
|
|
|
|
|
|
|
|
|
|
StorePathWithOutputs followLinksToStorePathWithOutputs(std::string_view path) const;
|
2016-06-01 12:49:12 +00:00
|
|
|
|
|
|
|
|
|
/* Constructs a unique store path name. */
|
2020-08-07 19:09:26 +00:00
|
|
|
|
StorePath makeStorePath(std::string_view type,
|
|
|
|
|
std::string_view hash, std::string_view name) const;
|
|
|
|
|
StorePath makeStorePath(std::string_view type,
|
2019-12-05 18:11:09 +00:00
|
|
|
|
const Hash & hash, std::string_view name) const;
|
2016-06-01 12:49:12 +00:00
|
|
|
|
|
2020-08-07 19:09:26 +00:00
|
|
|
|
StorePath makeOutputPath(std::string_view id,
|
2019-12-05 18:11:09 +00:00
|
|
|
|
const Hash & hash, std::string_view name) const;
|
2016-06-01 12:49:12 +00:00
|
|
|
|
|
2020-03-29 05:04:55 +00:00
|
|
|
|
StorePath makeFixedOutputPath(FileIngestionMethod method,
|
2019-12-05 18:11:09 +00:00
|
|
|
|
const Hash & hash, std::string_view name,
|
|
|
|
|
const StorePathSet & references = {},
|
|
|
|
|
bool hasSelfReference = false) const;
|
2016-06-01 12:49:12 +00:00
|
|
|
|
|
2019-12-05 18:11:09 +00:00
|
|
|
|
StorePath makeTextPath(std::string_view name, const Hash & hash,
|
2020-06-12 21:36:35 +00:00
|
|
|
|
const StorePathSet & references = {}) const;
|
|
|
|
|
|
2020-06-22 17:08:11 +00:00
|
|
|
|
StorePath makeFixedOutputPathFromCA(std::string_view name, ContentAddress ca,
|
2020-06-12 21:36:35 +00:00
|
|
|
|
const StorePathSet & references = {},
|
|
|
|
|
bool hasSelfReference = false) const;
|
2016-08-03 11:17:11 +00:00
|
|
|
|
|
|
|
|
|
/* 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. */
|
2019-12-05 18:11:09 +00:00
|
|
|
|
std::pair<StorePath, Hash> computeStorePathForPath(std::string_view name,
|
2020-03-29 05:04:55 +00:00
|
|
|
|
const Path & srcPath, FileIngestionMethod method = FileIngestionMethod::Recursive,
|
2018-01-25 15:05:57 +00:00
|
|
|
|
HashType hashAlgo = htSHA256, PathFilter & filter = defaultPathFilter) const;
|
2016-06-01 12:49:12 +00:00
|
|
|
|
|
|
|
|
|
/* 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. */
|
2019-12-05 18:11:09 +00:00
|
|
|
|
StorePath computeStorePathForText(const string & name, const string & s,
|
|
|
|
|
const StorePathSet & references) const;
|
2016-06-01 12:49:12 +00:00
|
|
|
|
|
2015-03-25 16:06:12 +00:00
|
|
|
|
/* Check whether a path is valid. */
|
2019-12-05 18:11:09 +00:00
|
|
|
|
bool isValidPath(const StorePath & path);
|
2016-04-19 16:50:15 +00:00
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
2019-12-05 18:11:09 +00:00
|
|
|
|
virtual bool isValidPathUncached(const StorePath & path);
|
2016-04-19 16:50:15 +00:00
|
|
|
|
|
|
|
|
|
public:
|
2006-11-30 17:43:04 +00:00
|
|
|
|
|
2020-10-21 19:31:19 +00:00
|
|
|
|
/* If requested, substitute missing paths. This
|
|
|
|
|
implements nix-copy-closure's --use-substitutes
|
|
|
|
|
flag. */
|
|
|
|
|
void substitutePaths(const StorePathSet & paths);
|
|
|
|
|
|
2017-03-16 12:50:01 +00:00
|
|
|
|
/* Query which of the given paths is valid. Optionally, try to
|
|
|
|
|
substitute missing paths. */
|
2019-12-05 18:11:09 +00:00
|
|
|
|
virtual StorePathSet queryValidPaths(const StorePathSet & paths,
|
2017-06-28 16:11:01 +00:00
|
|
|
|
SubstituteFlag maybeSubstitute = NoSubstitute);
|
2012-07-11 15:08:47 +00:00
|
|
|
|
|
2016-04-21 15:53:47 +00:00
|
|
|
|
/* Query the set of all valid paths. Note that for some store
|
2020-07-13 12:35:01 +00:00
|
|
|
|
backends, the name part of store paths may be replaced by 'x'
|
|
|
|
|
(i.e. you'll get /nix/store/<hash>-x rather than
|
2016-04-21 15:53:47 +00:00
|
|
|
|
/nix/store/<hash>-<name>). Use queryPathInfo() to obtain the
|
2020-07-13 12:35:01 +00:00
|
|
|
|
full store path. FIXME: should return a set of
|
|
|
|
|
std::variant<StorePath, HashPart> to get rid of this hack. */
|
2019-12-05 18:11:09 +00:00
|
|
|
|
virtual StorePathSet queryAllValidPaths()
|
2019-01-18 12:34:23 +00:00
|
|
|
|
{ unsupported("queryAllValidPaths"); }
|
2008-01-29 18:17:36 +00:00
|
|
|
|
|
2020-07-13 12:35:01 +00:00
|
|
|
|
constexpr static const char * MissingName = "x";
|
|
|
|
|
|
2016-04-21 15:53:47 +00:00
|
|
|
|
/* Query information about a valid path. It is permitted to omit
|
|
|
|
|
the name part of the store path. */
|
2019-12-05 18:11:09 +00:00
|
|
|
|
ref<const ValidPathInfo> queryPathInfo(const StorePath & path);
|
2016-04-19 16:50:15 +00:00
|
|
|
|
|
2016-09-16 16:54:14 +00:00
|
|
|
|
/* Asynchronous version of queryPathInfo(). */
|
2019-12-05 18:11:09 +00:00
|
|
|
|
void queryPathInfo(const StorePath & path,
|
2018-09-25 16:54:16 +00:00
|
|
|
|
Callback<ref<const ValidPathInfo>> callback) noexcept;
|
2016-09-16 16:54:14 +00:00
|
|
|
|
|
2021-01-22 15:27:55 +00:00
|
|
|
|
/* Check whether the given valid path info is sufficiently attested, by
|
|
|
|
|
either being signed by a trusted public key or content-addressed, in
|
|
|
|
|
order to be included in the given store.
|
2021-01-15 16:37:41 +00:00
|
|
|
|
|
|
|
|
|
These same checks would be performed in addToStore, but this allows an
|
|
|
|
|
earlier failure in the case where dependencies need to be added too, but
|
|
|
|
|
the addToStore wouldn't fail until those dependencies are added. Also,
|
|
|
|
|
we don't really want to add the dependencies listed in a nar info we
|
|
|
|
|
don't trust anyyways.
|
|
|
|
|
*/
|
|
|
|
|
virtual bool pathInfoIsTrusted(const ValidPathInfo &)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-19 16:50:15 +00:00
|
|
|
|
protected:
|
2010-11-16 17:11:46 +00:00
|
|
|
|
|
2019-12-05 18:11:09 +00:00
|
|
|
|
virtual void queryPathInfoUncached(const StorePath & path,
|
2018-09-25 16:54:16 +00:00
|
|
|
|
Callback<std::shared_ptr<const ValidPathInfo>> callback) noexcept = 0;
|
2006-11-30 17:43:04 +00:00
|
|
|
|
|
2016-04-19 16:50:15 +00:00
|
|
|
|
public:
|
2006-11-30 17:43:04 +00:00
|
|
|
|
|
2020-10-08 15:36:51 +00:00
|
|
|
|
virtual std::optional<const Realisation> queryRealisation(const DrvOutput &) = 0;
|
|
|
|
|
|
2006-11-30 17:43:04 +00:00
|
|
|
|
/* Queries the set of incoming FS references for a store path.
|
|
|
|
|
The result is not cleared. */
|
2019-12-05 18:11:09 +00:00
|
|
|
|
virtual void queryReferrers(const StorePath & path, StorePathSet & referrers)
|
2019-01-18 12:34:23 +00:00
|
|
|
|
{ unsupported("queryReferrers"); }
|
2006-11-30 17:43:04 +00:00
|
|
|
|
|
2012-12-20 17:41:44 +00: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.) */
|
2019-12-05 18:11:09 +00:00
|
|
|
|
virtual StorePathSet queryValidDerivers(const StorePath & path) { return {}; };
|
2012-12-20 17:41:44 +00:00
|
|
|
|
|
2010-02-22 12:44:36 +00:00
|
|
|
|
/* Query the outputs of the derivation denoted by `path'. */
|
2020-06-10 09:20:52 +00:00
|
|
|
|
virtual StorePathSet queryDerivationOutputs(const StorePath & path);
|
|
|
|
|
|
2020-07-24 21:02:51 +00:00
|
|
|
|
/* Query the mapping outputName => outputPath for the given derivation. All
|
|
|
|
|
outputs are mentioned so ones mising the mapping are mapped to
|
|
|
|
|
`std::nullopt`. */
|
2020-12-17 10:35:24 +00:00
|
|
|
|
virtual std::map<std::string, std::optional<StorePath>> queryPartialDerivationOutputMap(const StorePath & path);
|
|
|
|
|
|
2020-07-24 21:02:51 +00:00
|
|
|
|
/* Query the mapping outputName=>outputPath for the given derivation.
|
|
|
|
|
Assume every output has a mapping and throw an exception otherwise. */
|
2020-08-20 14:12:51 +00:00
|
|
|
|
OutputPathMap queryDerivationOutputMap(const StorePath & path);
|
2011-11-06 06:28:20 +00:00
|
|
|
|
|
2012-07-17 22:55:39 +00:00
|
|
|
|
/* Query the full store path given the hash part of a valid store
|
2019-12-05 18:11:09 +00:00
|
|
|
|
path, or empty if the path doesn't exist. */
|
|
|
|
|
virtual std::optional<StorePath> queryPathFromHashPart(const std::string & hashPart) = 0;
|
2015-03-25 16:06:12 +00:00
|
|
|
|
|
2012-07-11 21:52:18 +00:00
|
|
|
|
/* Query which of the given paths have substitutes. */
|
2019-12-05 18:11:09 +00:00
|
|
|
|
virtual StorePathSet querySubstitutablePaths(const StorePathSet & paths) { return {}; };
|
2007-08-12 00:29:28 +00:00
|
|
|
|
|
2012-07-11 14:43:24 +00:00
|
|
|
|
/* Query substitute info (i.e. references, derivers and download
|
2020-06-19 18:48:57 +00:00
|
|
|
|
sizes) of a map of paths to their optional ca values. If a path
|
|
|
|
|
does not have substitute info, it's omitted from the resulting
|
|
|
|
|
‘infos’ map. */
|
2020-06-17 19:03:05 +00:00
|
|
|
|
virtual void querySubstitutablePathInfos(const StorePathCAMap & paths,
|
2017-02-07 18:22:48 +00:00
|
|
|
|
SubstitutablePathInfos & infos) { return; };
|
2015-03-25 16:06:12 +00:00
|
|
|
|
|
2016-05-04 11:36:54 +00:00
|
|
|
|
/* Import a path into the store. */
|
2018-03-16 19:22:34 +00:00
|
|
|
|
virtual void addToStore(const ValidPathInfo & info, Source & narSource,
|
2020-07-13 15:37:44 +00:00
|
|
|
|
RepairFlag repair = NoRepair, CheckSigsFlag checkSigs = CheckSigs) = 0;
|
2016-05-04 11:36:54 +00:00
|
|
|
|
|
2006-11-30 17:43:04 +00:00
|
|
|
|
/* Copy the contents of a path to the store and register the
|
2006-12-01 20:51:18 +00:00
|
|
|
|
validity the resulting path. The resulting path is returned.
|
2011-12-01 13:48:48 +00:00
|
|
|
|
The function object `filter' can be used to exclude files (see
|
2006-12-12 23:05:01 +00:00
|
|
|
|
libutil/archive.hh). */
|
2019-12-05 18:11:09 +00:00
|
|
|
|
virtual StorePath addToStore(const string & name, const Path & srcPath,
|
2020-03-29 05:04:55 +00:00
|
|
|
|
FileIngestionMethod method = FileIngestionMethod::Recursive, HashType hashAlgo = htSHA256,
|
2020-08-03 04:13:45 +00:00
|
|
|
|
PathFilter & filter = defaultPathFilter, RepairFlag repair = NoRepair);
|
2006-11-30 17:43:04 +00:00
|
|
|
|
|
2020-07-10 11:21:37 +00:00
|
|
|
|
/* Copy the contents of a path to the store and register the
|
|
|
|
|
validity the resulting path, using a constant amount of
|
|
|
|
|
memory. */
|
|
|
|
|
ValidPathInfo addToStoreSlow(std::string_view name, const Path & srcPath,
|
|
|
|
|
FileIngestionMethod method = FileIngestionMethod::Recursive, HashType hashAlgo = htSHA256,
|
|
|
|
|
std::optional<Hash> expectedCAHash = {});
|
|
|
|
|
|
2020-08-03 04:13:45 +00:00
|
|
|
|
/* Like addToStore(), but the contents of the path are contained
|
|
|
|
|
in `dump', which is either a NAR serialisation (if recursive ==
|
|
|
|
|
true) or simply the contents of a regular file (if recursive ==
|
2020-09-18 09:58:45 +00:00
|
|
|
|
false).
|
|
|
|
|
`dump` may be drained */
|
2018-09-25 16:55:37 +00:00
|
|
|
|
// FIXME: remove?
|
2020-07-11 15:55:04 +00:00
|
|
|
|
virtual StorePath addToStoreFromDump(Source & dump, const string & name,
|
2020-03-29 05:04:55 +00:00
|
|
|
|
FileIngestionMethod method = FileIngestionMethod::Recursive, HashType hashAlgo = htSHA256, RepairFlag repair = NoRepair)
|
2020-08-15 16:41:28 +00:00
|
|
|
|
{ unsupported("addToStoreFromDump"); }
|
2018-09-25 16:55:37 +00:00
|
|
|
|
|
2006-11-30 17:43:04 +00:00
|
|
|
|
/* Like addToStore, but the contents written to the output path is
|
|
|
|
|
a regular file containing the given string. */
|
2019-12-05 18:11:09 +00:00
|
|
|
|
virtual StorePath addTextToStore(const string & name, const string & s,
|
|
|
|
|
const StorePathSet & references, RepairFlag repair = NoRepair) = 0;
|
2006-11-30 18:02:04 +00:00
|
|
|
|
|
2020-10-08 15:36:51 +00:00
|
|
|
|
/**
|
|
|
|
|
* Add a mapping indicating that `deriver!outputName` maps to the output path
|
|
|
|
|
* `output`.
|
|
|
|
|
*
|
|
|
|
|
* This is redundant for known-input-addressed and fixed-output derivations
|
|
|
|
|
* as this information is already present in the drv file, but necessary for
|
|
|
|
|
* floating-ca derivations and their dependencies as there's no way to
|
|
|
|
|
* retrieve this information otherwise.
|
|
|
|
|
*/
|
|
|
|
|
virtual void registerDrvOutput(const Realisation & output)
|
|
|
|
|
{ unsupported("registerDrvOutput"); }
|
|
|
|
|
|
2016-03-21 16:55:57 +00:00
|
|
|
|
/* Write a NAR dump of a store path. */
|
2019-12-05 18:11:09 +00:00
|
|
|
|
virtual void narFromPath(const StorePath & path, Sink & sink) = 0;
|
2016-03-21 16:55:57 +00:00
|
|
|
|
|
2012-06-27 20:58:15 +00: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 18:02:04 +00:00
|
|
|
|
they are already valid, this is a no-op. Otherwise, validity
|
2007-08-12 00:29:28 +00: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 20:58:15 +00:00
|
|
|
|
recursively building any sub-derivations. For inputs that are
|
|
|
|
|
not derivations, substitute them. */
|
2019-12-05 18:11:09 +00:00
|
|
|
|
virtual void buildPaths(
|
|
|
|
|
const std::vector<StorePathWithOutputs> & paths,
|
|
|
|
|
BuildMode buildMode = bmNormal);
|
2006-11-30 18:02:04 +00: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 15:57:40 +00:00
|
|
|
|
/* Build a single non-materialized derivation (i.e. not from an
|
2020-08-22 20:44:47 +00:00
|
|
|
|
on-disk .drv file).
|
|
|
|
|
|
|
|
|
|
‘drvPath’ is used to deduplicate worker goals so it is imperative that
|
|
|
|
|
is correct. That said, it doesn't literally need to be store path that
|
|
|
|
|
would be calculated from writing this derivation to the store: it is OK
|
|
|
|
|
if it instead is that of a Derivation which would resolve to this (by
|
|
|
|
|
taking the outputs of it's input derivations and adding them as input
|
|
|
|
|
sources) such that the build time referenceable-paths are the same.
|
|
|
|
|
|
|
|
|
|
In the input-addressed case, we usually *do* use an "original"
|
|
|
|
|
unresolved derivations's path, as that is what will be used in the
|
|
|
|
|
`buildPaths` case. Also, the input-addressed output paths are verified
|
|
|
|
|
only by that contents of that specific unresolved derivation, so it is
|
|
|
|
|
nice to keep that information around so if the original derivation is
|
|
|
|
|
ever obtained later, it can be verified whether the trusted user in fact
|
|
|
|
|
used the proper output path.
|
|
|
|
|
|
|
|
|
|
In the content-addressed case, we want to always use the
|
|
|
|
|
resolved drv path calculated from the provided derivation. This serves
|
|
|
|
|
two purposes:
|
|
|
|
|
|
|
|
|
|
- It keeps the operation trustless, by ruling out a maliciously
|
|
|
|
|
invalid drv path corresponding to a non-resolution-equivalent
|
|
|
|
|
derivation.
|
|
|
|
|
|
|
|
|
|
- For the floating case in particular, it ensures that the derivation
|
|
|
|
|
to output mapping respects the resolution equivalence relation, so
|
|
|
|
|
one cannot choose different resolution-equivalent derivations to
|
|
|
|
|
subvert dependency coherence (i.e. the property that one doesn't end
|
|
|
|
|
up with multiple different versions of dependencies without
|
|
|
|
|
explicitly choosing to allow it).
|
|
|
|
|
*/
|
2019-12-05 18:11:09 +00:00
|
|
|
|
virtual BuildResult buildDerivation(const StorePath & drvPath, const BasicDerivation & drv,
|
2020-12-20 17:54:57 +00:00
|
|
|
|
BuildMode buildMode = bmNormal);
|
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 15:57:40 +00:00
|
|
|
|
|
2006-11-30 18:02:04 +00: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). */
|
2020-12-20 17:54:57 +00:00
|
|
|
|
virtual void ensurePath(const StorePath & path);
|
2006-12-02 16:41:36 +00:00
|
|
|
|
|
|
|
|
|
/* Add a store path as a temporary root of the garbage collector.
|
|
|
|
|
The root disappears as soon as we exit. */
|
2019-12-05 18:11:09 +00:00
|
|
|
|
virtual void addTempRoot(const StorePath & path)
|
2020-12-20 17:54:57 +00:00
|
|
|
|
{ warn("not creating temp root, store doesn't support GC"); }
|
2006-12-02 16:41:36 +00:00
|
|
|
|
|
2006-12-04 23:29:16 +00: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. */
|
2019-01-18 12:34:23 +00:00
|
|
|
|
virtual void addIndirectRoot(const Path & path)
|
|
|
|
|
{ unsupported("addIndirectRoot"); }
|
2006-12-04 23:29:16 +00:00
|
|
|
|
|
2006-12-02 16:41:36 +00: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
|
2020-08-22 20:44:47 +00:00
|
|
|
|
permanent root and sees ours.
|
2006-12-02 16:41:36 +00:00
|
|
|
|
|
|
|
|
|
In either case the permanent root is seen by the collector. */
|
2017-02-07 18:22:48 +00:00
|
|
|
|
virtual void syncWithGC() { };
|
2006-12-02 16:41:36 +00:00
|
|
|
|
|
2006-12-05 01:31:45 +00:00
|
|
|
|
/* Find the roots of the garbage collector. Each root is a pair
|
|
|
|
|
(link, storepath) where `link' is the path of the symlink
|
2019-03-14 12:50:07 +00:00
|
|
|
|
outside of the Nix store that point to `storePath'. If
|
|
|
|
|
'censor' is true, privacy-sensitive information about roots
|
|
|
|
|
found in /proc is censored. */
|
|
|
|
|
virtual Roots findRoots(bool censor)
|
2019-01-18 12:34:23 +00:00
|
|
|
|
{ unsupported("findRoots"); }
|
2006-12-05 01:31:45 +00:00
|
|
|
|
|
2008-06-18 09:34:17 +00:00
|
|
|
|
/* Perform a garbage collection. */
|
2019-01-18 12:34:23 +00:00
|
|
|
|
virtual void collectGarbage(const GCOptions & options, GCResults & results)
|
|
|
|
|
{ unsupported("collectGarbage"); }
|
2010-05-04 10:45:10 +00:00
|
|
|
|
|
2010-11-16 17:11:46 +00: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'. */
|
2019-12-05 18:11:09 +00:00
|
|
|
|
string makeValidityRegistration(const StorePathSet & paths,
|
2010-11-16 17:11:46 +00:00
|
|
|
|
bool showDerivers, bool showHash);
|
2014-09-01 20:21:42 +00: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 19:36:20 +00: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. */
|
2019-12-05 18:11:09 +00:00
|
|
|
|
void pathInfoToJSON(JSONPlaceholder & jsonOut, const StorePathSet & storePaths,
|
2017-07-14 13:27:21 +00:00
|
|
|
|
bool includeImpureInfo, bool showClosureSize,
|
2020-02-11 22:50:16 +00:00
|
|
|
|
Base hashBase = Base32,
|
2017-07-14 13:27:21 +00:00
|
|
|
|
AllowInvalidFlag allowInvalid = DisallowInvalid);
|
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 19:36:20 +00:00
|
|
|
|
|
|
|
|
|
/* 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. */
|
2019-12-05 18:11:09 +00:00
|
|
|
|
std::pair<uint64_t, uint64_t> getClosureSize(const StorePath & storePath);
|
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 19:36:20 +00:00
|
|
|
|
|
2014-09-01 20:21:42 +00:00
|
|
|
|
/* Optimise the disk space usage of the Nix store by hard-linking files
|
|
|
|
|
with the same contents. */
|
2017-02-07 18:22:48 +00:00
|
|
|
|
virtual void optimiseStore() { };
|
2015-06-01 21:20:11 +00:00
|
|
|
|
|
|
|
|
|
/* Check the integrity of the Nix store. Returns true if errors
|
|
|
|
|
remain. */
|
2017-06-28 16:11:01 +00:00
|
|
|
|
virtual bool verifyStore(bool checkContents, RepairFlag repair = NoRepair) { 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 13:28:26 +00:00
|
|
|
|
|
2016-02-25 16:43:19 +00:00
|
|
|
|
/* Return an object to access files in the Nix store. */
|
2019-01-18 12:34:23 +00:00
|
|
|
|
virtual ref<FSAccessor> getFSAccessor()
|
|
|
|
|
{ unsupported("getFSAccessor"); }
|
2016-02-25 16:43:19 +00:00
|
|
|
|
|
2021-01-13 22:27:39 +00:00
|
|
|
|
/* Repair the contents of the given path by redownloading it using
|
|
|
|
|
a substituter (if available). */
|
|
|
|
|
virtual void repairPath(const StorePath & path)
|
|
|
|
|
{ unsupported("repairPath"); }
|
|
|
|
|
|
2016-04-05 13:30:22 +00:00
|
|
|
|
/* Add signatures to the specified store path. The signatures are
|
|
|
|
|
not verified. */
|
2019-12-05 18:11:09 +00:00
|
|
|
|
virtual void addSignatures(const StorePath & storePath, const StringSet & sigs)
|
2019-01-18 12:34:23 +00:00
|
|
|
|
{ unsupported("addSignatures"); }
|
2016-04-05 13:30:22 +00:00
|
|
|
|
|
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 13:28:26 +00:00
|
|
|
|
/* Utility functions. */
|
|
|
|
|
|
|
|
|
|
/* Read a derivation, after ensuring its existence through
|
|
|
|
|
ensurePath(). */
|
2019-12-05 18:11:09 +00:00
|
|
|
|
Derivation derivationFromPath(const StorePath & drvPath);
|
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 13:28:26 +00:00
|
|
|
|
|
2020-06-12 11:04:52 +00:00
|
|
|
|
/* Read a derivation (which must already be valid). */
|
|
|
|
|
Derivation readDerivation(const StorePath & drvPath);
|
|
|
|
|
|
2020-11-17 12:58:55 +00:00
|
|
|
|
/* Read a derivation from a potentially invalid path. */
|
|
|
|
|
Derivation readInvalidDerivation(const StorePath & drvPath);
|
|
|
|
|
|
2016-11-10 16:45:04 +00: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 13:28:26 +00:00
|
|
|
|
closure of `storePath'; that is, all paths than can be directly
|
2016-11-10 16:45:04 +00: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 13:28:26 +00: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. */
|
2019-12-05 18:11:09 +00:00
|
|
|
|
virtual void computeFSClosure(const StorePathSet & paths,
|
|
|
|
|
StorePathSet & out, bool flipDirection = false,
|
2016-11-10 16:45:04 +00:00
|
|
|
|
bool includeOutputs = false, bool includeDerivers = false);
|
|
|
|
|
|
2019-12-05 18:11:09 +00:00
|
|
|
|
void computeFSClosure(const StorePath & path,
|
|
|
|
|
StorePathSet & 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 13:28:26 +00: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. */
|
2019-12-05 18:11:09 +00:00
|
|
|
|
virtual void queryMissing(const std::vector<StorePathWithOutputs> & targets,
|
|
|
|
|
StorePathSet & willBuild, StorePathSet & willSubstitute, StorePathSet & unknown,
|
2020-07-30 11:10:49 +00:00
|
|
|
|
uint64_t & downloadSize, uint64_t & narSize);
|
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 13:28:26 +00:00
|
|
|
|
|
|
|
|
|
/* Sort a set of paths topologically under the references
|
2019-12-01 00:04:14 +00:00
|
|
|
|
relation. If p refers to q, then p precedes q in this list. */
|
2019-12-05 18:11:09 +00:00
|
|
|
|
StorePaths topoSortPaths(const StorePathSet & paths);
|
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 13:28:26 +00:00
|
|
|
|
|
2016-11-25 23:37:43 +00:00
|
|
|
|
/* Export multiple paths in the format expected by ‘nix-store
|
|
|
|
|
--import’. */
|
2019-12-05 18:11:09 +00:00
|
|
|
|
void exportPaths(const StorePathSet & paths, Sink & sink);
|
2016-05-04 11:36:54 +00:00
|
|
|
|
|
2019-12-05 18:11:09 +00:00
|
|
|
|
void exportPath(const StorePath & path, Sink & sink);
|
2016-05-04 11:36:54 +00:00
|
|
|
|
|
|
|
|
|
/* 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. */
|
2020-07-13 15:37:44 +00:00
|
|
|
|
StorePaths importPaths(Source & source, CheckSigsFlag checkSigs = CheckSigs);
|
2016-05-04 11:36:54 +00:00
|
|
|
|
|
2016-04-19 16:50:15 +00: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 11:07:50 +00:00
|
|
|
|
/* Return the build log of the specified store path, if available,
|
|
|
|
|
or null otherwise. */
|
2019-12-05 18:11:09 +00:00
|
|
|
|
virtual std::shared_ptr<std::string> getBuildLog(const StorePath & path)
|
2017-03-13 11:07:50 +00:00
|
|
|
|
{ return nullptr; }
|
|
|
|
|
|
2017-04-06 13:22:37 +00: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 12:18:46 +00: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() { };
|
|
|
|
|
|
2018-08-30 21:28:47 +00:00
|
|
|
|
/* Get the protocol version of this store or it's connection. */
|
|
|
|
|
virtual unsigned int getProtocol()
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
};
|
|
|
|
|
|
2018-01-12 16:31:08 +00:00
|
|
|
|
virtual Path toRealPath(const Path & storePath)
|
|
|
|
|
{
|
|
|
|
|
return storePath;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-24 13:26:13 +00:00
|
|
|
|
Path toRealPath(const StorePath & storePath)
|
|
|
|
|
{
|
|
|
|
|
return toRealPath(printStorePath(storePath));
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-09 16:01:21 +00:00
|
|
|
|
virtual void createUser(const std::string & userName, uid_t userId)
|
|
|
|
|
{ }
|
|
|
|
|
|
2016-04-19 16:50:15 +00:00
|
|
|
|
protected:
|
|
|
|
|
|
|
|
|
|
Stats stats;
|
|
|
|
|
|
2017-05-01 11:43:34 +00:00
|
|
|
|
/* Unsupported methods. */
|
2019-01-18 12:34:23 +00:00
|
|
|
|
[[noreturn]] void unsupported(const std::string & op)
|
2017-05-01 11:43:34 +00:00
|
|
|
|
{
|
2019-01-18 12:34:23 +00:00
|
|
|
|
throw Unsupported("operation '%s' is not supported by store '%s'", op, getUri());
|
2017-05-01 11:43:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-11-30 17:43:04 +00:00
|
|
|
|
};
|
|
|
|
|
|
2016-02-25 16:43:19 +00:00
|
|
|
|
|
2016-05-03 12:45:50 +00:00
|
|
|
|
/* Copy a path from one store to another. */
|
|
|
|
|
void copyStorePath(ref<Store> srcStore, ref<Store> dstStore,
|
2019-12-05 18:11:09 +00:00
|
|
|
|
const StorePath & storePath, RepairFlag repair = NoRepair, CheckSigsFlag checkSigs = CheckSigs);
|
2017-06-28 16:11:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Copy store paths from one store to another. The paths may be copied
|
2020-06-19 18:48:57 +00:00
|
|
|
|
in parallel. They are copied in a topologically sorted order (i.e.
|
|
|
|
|
if A is a reference of B, then A is copied before B), but the set
|
|
|
|
|
of store paths is not automatically closed; use copyClosure() for
|
|
|
|
|
that. Returns a map of what each path was copied to the dstStore
|
|
|
|
|
as. */
|
|
|
|
|
std::map<StorePath, StorePath> copyPaths(ref<Store> srcStore, ref<Store> dstStore,
|
2021-02-25 16:10:45 +00:00
|
|
|
|
const RealisedPath::Set &,
|
2017-06-28 16:11:01 +00:00
|
|
|
|
RepairFlag repair = NoRepair,
|
|
|
|
|
CheckSigsFlag checkSigs = CheckSigs,
|
|
|
|
|
SubstituteFlag substitute = NoSubstitute);
|
2020-12-14 18:43:53 +00:00
|
|
|
|
std::map<StorePath, StorePath> copyPaths(ref<Store> srcStore, ref<Store> dstStore,
|
|
|
|
|
const StorePathSet& paths,
|
2017-06-28 16:11:01 +00:00
|
|
|
|
RepairFlag repair = NoRepair,
|
|
|
|
|
CheckSigsFlag checkSigs = CheckSigs,
|
|
|
|
|
SubstituteFlag substitute = NoSubstitute);
|
2016-10-07 17:15:25 +00:00
|
|
|
|
|
|
|
|
|
|
2006-12-05 02:18:46 +00: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 13:48:16 +00:00
|
|
|
|
/* Return a Store object to access the Nix store denoted by
|
2016-11-25 23:37:43 +00:00
|
|
|
|
‘uri’ (slight misnomer...). Supported values are:
|
2016-02-24 13:48:16 +00:00
|
|
|
|
|
2017-05-01 15:35:30 +00:00
|
|
|
|
* ‘local’: The Nix store in /nix/store and database in
|
2016-02-24 13:48:16 +00:00
|
|
|
|
/nix/var/nix/db, accessed directly.
|
|
|
|
|
|
2016-11-25 23:37:43 +00:00
|
|
|
|
* ‘daemon’: The Nix store accessed via a Unix domain socket
|
2016-02-24 13:48:16 +00:00
|
|
|
|
connection to nix-daemon.
|
|
|
|
|
|
2018-01-31 22:47:16 +00:00
|
|
|
|
* ‘unix://<path>’: The Nix store accessed via a Unix domain socket
|
|
|
|
|
connection to nix-daemon, with the socket located at <path>.
|
|
|
|
|
|
2017-05-01 15:35:30 +00:00
|
|
|
|
* ‘auto’ or ‘’: Equivalent to ‘local’ or ‘daemon’ depending on
|
|
|
|
|
whether the user has write access to the local Nix
|
|
|
|
|
store/database.
|
|
|
|
|
|
2016-11-25 23:37:43 +00:00
|
|
|
|
* ‘file://<path>’: A binary cache stored in <path>.
|
2016-02-24 13:48:16 +00:00
|
|
|
|
|
2017-05-01 15:35:30 +00: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 13:48:16 +00:00
|
|
|
|
|
2017-05-01 15:35:30 +00:00
|
|
|
|
You can pass parameters to the store implementation by appending
|
|
|
|
|
‘?key=value&key=value&...’ to the URI.
|
|
|
|
|
*/
|
2017-10-23 17:34:49 +00:00
|
|
|
|
ref<Store> openStore(const std::string & uri = settings.storeUri.get(),
|
2017-05-01 15:35:30 +00:00
|
|
|
|
const Store::Params & extraParams = Store::Params());
|
2017-03-03 18:23:20 +00:00
|
|
|
|
|
2016-02-24 13:48:16 +00:00
|
|
|
|
|
2016-04-29 11:57:08 +00:00
|
|
|
|
/* Return the default substituter stores, defined by the
|
2019-06-25 11:27:16 +00:00
|
|
|
|
‘substituters’ option and various legacy options. */
|
2016-04-29 11:57:08 +00:00
|
|
|
|
std::list<ref<Store>> getDefaultSubstituters();
|
|
|
|
|
|
2020-09-08 12:50:23 +00:00
|
|
|
|
struct StoreFactory
|
|
|
|
|
{
|
2020-09-11 09:11:05 +00:00
|
|
|
|
std::set<std::string> uriSchemes;
|
|
|
|
|
std::function<std::shared_ptr<Store> (const std::string & scheme, const std::string & uri, const Store::Params & params)> create;
|
2020-09-10 08:55:51 +00:00
|
|
|
|
std::function<std::shared_ptr<StoreConfig> ()> getConfig;
|
2020-09-08 12:50:23 +00:00
|
|
|
|
};
|
2020-10-05 15:53:30 +00:00
|
|
|
|
|
2020-09-09 09:18:12 +00:00
|
|
|
|
struct Implementations
|
2016-02-29 15:11:11 +00:00
|
|
|
|
{
|
2020-09-09 09:18:12 +00:00
|
|
|
|
static std::vector<StoreFactory> * registered;
|
2016-04-29 11:57:08 +00:00
|
|
|
|
|
2020-09-10 08:55:51 +00:00
|
|
|
|
template<typename T, typename TConfig>
|
2020-09-09 09:18:12 +00:00
|
|
|
|
static void add()
|
2016-02-29 15:11:11 +00:00
|
|
|
|
{
|
2020-09-09 09:18:12 +00:00
|
|
|
|
if (!registered) registered = new std::vector<StoreFactory>();
|
2020-09-08 12:50:23 +00:00
|
|
|
|
StoreFactory factory{
|
2020-09-14 12:12:47 +00:00
|
|
|
|
.uriSchemes = T::uriSchemes(),
|
2020-09-09 09:29:17 +00:00
|
|
|
|
.create =
|
2020-09-11 09:11:05 +00:00
|
|
|
|
([](const std::string & scheme, const std::string & uri, const Store::Params & params)
|
2020-09-08 12:50:23 +00:00
|
|
|
|
-> std::shared_ptr<Store>
|
2020-09-11 09:11:05 +00:00
|
|
|
|
{ return std::make_shared<T>(scheme, uri, params); }),
|
2020-09-10 08:55:51 +00:00
|
|
|
|
.getConfig =
|
|
|
|
|
([]()
|
|
|
|
|
-> std::shared_ptr<StoreConfig>
|
2020-09-14 12:12:47 +00:00
|
|
|
|
{ return std::make_shared<TConfig>(StringMap({})); })
|
2020-09-08 12:50:23 +00:00
|
|
|
|
};
|
2020-09-09 09:18:12 +00:00
|
|
|
|
registered->push_back(factory);
|
|
|
|
|
}
|
|
|
|
|
};
|
2016-02-29 15:11:11 +00:00
|
|
|
|
|
2020-09-10 08:55:51 +00:00
|
|
|
|
template<typename T, typename TConfig>
|
2016-02-29 15:11:11 +00:00
|
|
|
|
struct RegisterStoreImplementation
|
|
|
|
|
{
|
2020-09-09 09:18:12 +00:00
|
|
|
|
RegisterStoreImplementation()
|
2016-02-29 15:11:11 +00:00
|
|
|
|
{
|
2020-09-10 08:55:51 +00:00
|
|
|
|
Implementations::add<T, TConfig>();
|
2016-02-29 15:11:11 +00:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2008-06-09 13:52:45 +00: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 17:43:04 +00:00
|
|
|
|
|
|
|
|
|
|
2019-12-05 18:11:09 +00:00
|
|
|
|
std::optional<ValidPathInfo> decodeValidPathInfo(
|
|
|
|
|
const Store & store,
|
|
|
|
|
std::istream & str,
|
2020-08-06 18:31:48 +00:00
|
|
|
|
std::optional<HashResult> hashGiven = std::nullopt);
|
2007-08-12 00:29:28 +00:00
|
|
|
|
|
2019-02-21 10:44:25 +00:00
|
|
|
|
/* Split URI into protocol+hierarchy part and its parameter set. */
|
|
|
|
|
std::pair<std::string, Store::Params> splitUriAndParams(const std::string & uri);
|
|
|
|
|
|
2020-06-22 17:08:11 +00:00
|
|
|
|
std::optional<ContentAddress> getDerivationCA(const BasicDerivation & drv);
|
2020-06-13 05:07:42 +00:00
|
|
|
|
|
2006-11-30 17:43:04 +00:00
|
|
|
|
}
|