aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/store-api.hh
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstore/store-api.hh')
-rw-r--r--src/libstore/store-api.hh136
1 files changed, 109 insertions, 27 deletions
diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh
index 72b0b0f03..29685c9d1 100644
--- a/src/libstore/store-api.hh
+++ b/src/libstore/store-api.hh
@@ -2,11 +2,15 @@
#include "hash.hh"
#include "serialise.hh"
+#include "crypto.hh"
+#include "lru-cache.hh"
+#include "sync.hh"
-#include <string>
+#include <atomic>
#include <limits>
#include <map>
#include <memory>
+#include <string>
namespace nix {
@@ -95,8 +99,15 @@ struct ValidPathInfo
Hash narHash;
PathSet references;
time_t registrationTime = 0;
- unsigned long long narSize = 0; // 0 = unknown
- unsigned long long id; // internal use only
+ uint64_t narSize = 0; // 0 = unknown
+ uint64_t id; // internal use only
+
+ /* Whether the path is ultimately trusted, that is, it was built
+ locally or is content-addressable (e.g. added via addToStore()
+ or the result of a fixed-output derivation). */
+ bool ultimate = false;
+
+ StringSet sigs; // note: not necessarily verified
bool operator == (const ValidPathInfo & i) const
{
@@ -105,6 +116,27 @@ struct ValidPathInfo
&& narHash == i.narHash
&& references == i.references;
}
+
+ /* 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. */
+ std::string fingerprint() const;
+
+ void sign(const SecretKey & secretKey);
+
+ /* Return the number of signatures on this .narinfo that were
+ produced by one of the specified keys. */
+ unsigned int checkSignatures(const PublicKeys & publicKeys) const;
+
+ /* Verify a single signature. */
+ bool checkSignature(const PublicKeys & publicKeys, const std::string & sig) const;
+
+ Strings shortRefs() const;
+
+ virtual ~ValidPathInfo() { }
};
typedef list<ValidPathInfo> ValidPathInfos;
@@ -123,7 +155,6 @@ struct BuildResult
InputRejected,
OutputRejected,
TransientFailure, // possibly transient
- CachedFailure,
TimedOut,
MiscFailure,
DependencyFailed,
@@ -141,42 +172,62 @@ struct BuildResult
struct BasicDerivation;
struct Derivation;
class FSAccessor;
+class NarInfoDiskCache;
class Store : public std::enable_shared_from_this<Store>
{
+protected:
+
+ struct State
+ {
+ LRUCache<std::string, std::shared_ptr<ValidPathInfo>> pathInfoCache{64 * 1024};
+ };
+
+ Sync<State> state;
+
+ std::shared_ptr<NarInfoDiskCache> diskCache;
+
public:
virtual ~Store() { }
+ virtual std::string getUri() = 0;
+
/* Check whether a path is valid. */
- virtual bool isValidPath(const Path & path) = 0;
+ bool isValidPath(const Path & path);
+
+protected:
+
+ virtual bool isValidPathUncached(const Path & path) = 0;
+
+public:
/* Query which of the given paths is valid. */
virtual PathSet queryValidPaths(const PathSet & paths) = 0;
- /* Query the set of all valid paths. */
+ /* 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. */
virtual PathSet queryAllValidPaths() = 0;
- /* Query information about a valid path. */
- virtual ValidPathInfo queryPathInfo(const Path & path) = 0;
+ /* Query information about a valid path. It is permitted to omit
+ the name part of the store path. */
+ ref<const ValidPathInfo> queryPathInfo(const Path & path);
- /* Query the hash of a valid path. */
- virtual Hash queryPathHash(const Path & path) = 0;
+protected:
- /* Query the set of outgoing FS references for a store path. The
- result is not cleared. */
- virtual void queryReferences(const Path & path, PathSet & references);
+ virtual std::shared_ptr<ValidPathInfo> queryPathInfoUncached(const Path & path) = 0;
+
+public:
/* Queries the set of incoming FS references for a store path.
The result is not cleared. */
virtual void queryReferrers(const Path & path,
PathSet & referrers) = 0;
- /* Query the deriver of a store path. Return the empty string if
- no deriver has been set. */
- virtual Path queryDeriver(const Path & path) = 0;
-
/* 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
@@ -215,6 +266,9 @@ public:
virtual Path addTextToStore(const string & name, const string & s,
const PathSet & references, bool repair = false) = 0;
+ /* Write a NAR dump of a store path. */
+ virtual void narFromPath(const Path & path, Sink & sink) = 0;
+
/* Export a store path, that is, create a NAR dump of the store
path and append its references and its deriver. Optionally, a
cryptographic signature (created by OpenSSL) of the preceding
@@ -297,13 +351,6 @@ public:
/* Perform a garbage collection. */
virtual void collectGarbage(const GCOptions & options, GCResults & results) = 0;
- /* Return the set of paths that have failed to build.*/
- virtual PathSet queryFailedPaths() = 0;
-
- /* Clear the "failed" status of the given paths. The special
- value `*' causes all failed paths to be cleared. */
- virtual void clearFailedPaths(const PathSet & paths) = 0;
-
/* 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'. */
@@ -321,6 +368,10 @@ public:
/* Return an object to access files in the Nix store. */
virtual ref<FSAccessor> getFSAccessor() = 0;
+ /* Add signatures to the specified store path. The signatures are
+ not verified. */
+ virtual void addSignatures(const Path & storePath, const StringSet & sigs) = 0;
+
/* Utility functions. */
/* Read a derivation, after ensuring its existence through
@@ -349,11 +400,36 @@ public:
relation. If p refers to q, then p preceeds q in this list. */
Paths topoSortPaths(const PathSet & paths);
+ 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();
+
+protected:
+
+ Stats stats;
+
};
class LocalFSStore : public Store
{
+public:
+ void narFromPath(const Path & path, Sink & sink) override;
ref<FSAccessor> getFSAccessor() override;
};
@@ -453,12 +529,17 @@ ref<Store> openStoreAt(const std::string & uri);
ref<Store> openStore();
-ref<Store> openLocalBinaryCacheStore(std::shared_ptr<Store> localStore,
- const Path & secretKeyFile, const Path & binaryCacheDir);
+/* Return the default substituter stores, defined by the
+ ‘substituters’ option and various legacy options like
+ ‘binary-caches’. */
+std::list<ref<Store>> getDefaultSubstituters();
/* Store implementation registration. */
-typedef std::function<std::shared_ptr<Store>(const std::string & uri)> OpenStore;
+typedef std::map<std::string, std::string> StoreParams;
+
+typedef std::function<std::shared_ptr<Store>(
+ const std::string & uri, const StoreParams & params)> OpenStore;
struct RegisterStoreImplementation
{
@@ -485,6 +566,7 @@ ValidPathInfo decodeValidPathInfo(std::istream & str,
MakeError(SubstError, Error)
MakeError(BuildError, Error) /* denotes a permanent build failure */
+MakeError(InvalidPath, Error)
}