2016-02-24 15:48:16 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "crypto.hh"
|
|
|
|
#include "store-api.hh"
|
|
|
|
|
|
|
|
#include "pool.hh"
|
|
|
|
|
|
|
|
#include <atomic>
|
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
|
|
|
struct NarInfo;
|
|
|
|
|
|
|
|
class BinaryCacheStore : public Store
|
|
|
|
{
|
2017-04-13 16:55:38 +03:00
|
|
|
public:
|
2016-02-24 15:48:16 +02:00
|
|
|
|
2017-04-13 16:55:38 +03:00
|
|
|
const Setting<std::string> compression{this, "xz", "compression", "NAR compression method ('xz', 'bzip2', or 'none')"};
|
|
|
|
const Setting<bool> writeNARListing{this, false, "write-nar-listing", "whether to write a JSON file listing the files in each NAR"};
|
|
|
|
const Setting<Path> secretKeyFile{this, "", "secret-key", "path to secret key used to sign the binary cache"};
|
2017-10-17 22:15:33 +03:00
|
|
|
const Setting<Path> localNarCache{this, "", "local-nar-cache", "path to a local cache of NARs"};
|
2018-02-07 22:06:11 +02:00
|
|
|
const Setting<bool> parallelCompression{this, false, "parallel-compression",
|
|
|
|
"enable multi-threading compression, available for xz only currently"};
|
2016-02-24 15:48:16 +02:00
|
|
|
|
2017-04-13 16:55:38 +03:00
|
|
|
private:
|
2016-04-29 18:02:57 +03:00
|
|
|
|
2017-04-13 16:55:38 +03:00
|
|
|
std::unique_ptr<SecretKey> secretKey;
|
2016-10-21 17:50:28 +03:00
|
|
|
|
2016-02-24 15:48:16 +02:00
|
|
|
protected:
|
|
|
|
|
2016-06-01 15:49:12 +03:00
|
|
|
BinaryCacheStore(const Params & params);
|
2016-02-24 15:48:16 +02:00
|
|
|
|
2016-10-21 17:50:28 +03:00
|
|
|
public:
|
|
|
|
|
2016-02-24 15:48:16 +02:00
|
|
|
virtual bool fileExists(const std::string & path) = 0;
|
|
|
|
|
2017-03-14 16:26:01 +02:00
|
|
|
virtual void upsertFile(const std::string & path,
|
|
|
|
const std::string & data,
|
|
|
|
const std::string & mimeType) = 0;
|
2016-02-24 15:48:16 +02:00
|
|
|
|
2018-03-28 00:12:31 +03:00
|
|
|
/* Note: subclasses must implement at least one of the two
|
|
|
|
following getFile() methods. */
|
|
|
|
|
|
|
|
/* Dump the contents of the specified file to a sink. */
|
|
|
|
virtual void getFile(const std::string & path, Sink & sink);
|
|
|
|
|
|
|
|
/* Fetch the specified file and call the specified callback with
|
|
|
|
the result. A subclass may implement this asynchronously. */
|
2016-09-16 19:54:14 +03:00
|
|
|
virtual void getFile(const std::string & path,
|
2018-03-28 00:12:31 +03:00
|
|
|
Callback<std::shared_ptr<std::string>> callback);
|
2016-09-16 19:54:14 +03:00
|
|
|
|
|
|
|
std::shared_ptr<std::string> getFile(const std::string & path);
|
2016-02-24 15:48:16 +02:00
|
|
|
|
2016-10-21 17:50:28 +03:00
|
|
|
protected:
|
|
|
|
|
2016-05-30 14:33:05 +03:00
|
|
|
bool wantMassQuery_ = false;
|
|
|
|
int priority = 50;
|
|
|
|
|
2016-02-24 15:48:16 +02:00
|
|
|
public:
|
|
|
|
|
|
|
|
virtual void init();
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2016-02-24 17:52:28 +02:00
|
|
|
std::string narMagic;
|
|
|
|
|
2016-02-24 15:48:16 +02:00
|
|
|
std::string narInfoFileFor(const Path & storePath);
|
|
|
|
|
2017-11-14 19:44:05 +02:00
|
|
|
void writeNarInfo(ref<NarInfo> narInfo);
|
|
|
|
|
2016-02-24 15:48:16 +02:00
|
|
|
public:
|
|
|
|
|
2016-04-19 19:50:15 +03:00
|
|
|
bool isValidPathUncached(const Path & path) override;
|
2016-02-24 15:48:16 +02:00
|
|
|
|
|
|
|
PathSet queryAllValidPaths() override
|
2017-05-01 14:43:34 +03:00
|
|
|
{ unsupported(); }
|
2016-02-24 15:48:16 +02:00
|
|
|
|
2016-09-16 19:54:14 +03:00
|
|
|
void queryPathInfoUncached(const Path & path,
|
2018-03-27 23:16:01 +03:00
|
|
|
Callback<std::shared_ptr<ValidPathInfo>> callback) override;
|
2016-02-24 15:48:16 +02:00
|
|
|
|
|
|
|
void queryReferrers(const Path & path,
|
|
|
|
PathSet & referrers) override
|
2017-05-01 14:43:34 +03:00
|
|
|
{ unsupported(); }
|
2016-02-24 15:48:16 +02:00
|
|
|
|
|
|
|
PathSet queryDerivationOutputs(const Path & path) override
|
2017-05-01 14:43:34 +03:00
|
|
|
{ unsupported(); }
|
2016-02-24 15:48:16 +02:00
|
|
|
|
|
|
|
StringSet queryDerivationOutputNames(const Path & path) override
|
2017-05-01 14:43:34 +03:00
|
|
|
{ unsupported(); }
|
2016-02-24 15:48:16 +02:00
|
|
|
|
|
|
|
Path queryPathFromHashPart(const string & hashPart) override
|
2017-05-01 14:43:34 +03:00
|
|
|
{ unsupported(); }
|
2016-02-24 15:48:16 +02:00
|
|
|
|
2016-05-31 14:31:04 +03:00
|
|
|
bool wantMassQuery() override { return wantMassQuery_; }
|
2016-05-30 14:33:05 +03:00
|
|
|
|
2016-10-21 17:50:28 +03:00
|
|
|
void addToStore(const ValidPathInfo & info, const ref<std::string> & nar,
|
2017-06-28 19:11:01 +03:00
|
|
|
RepairFlag repair, CheckSigsFlag checkSigs,
|
2016-10-21 19:09:30 +03:00
|
|
|
std::shared_ptr<FSAccessor> accessor) override;
|
2016-05-04 14:36:54 +03:00
|
|
|
|
2016-02-24 15:48:16 +02:00
|
|
|
Path addToStore(const string & name, const Path & srcPath,
|
2016-10-21 19:09:30 +03:00
|
|
|
bool recursive, HashType hashAlgo,
|
2017-06-28 19:11:01 +03:00
|
|
|
PathFilter & filter, RepairFlag repair) override;
|
2016-02-24 15:48:16 +02:00
|
|
|
|
|
|
|
Path addTextToStore(const string & name, const string & s,
|
2017-06-28 19:11:01 +03:00
|
|
|
const PathSet & references, RepairFlag repair) override;
|
2016-02-24 15:48:16 +02:00
|
|
|
|
2016-03-22 15:21:45 +02:00
|
|
|
void narFromPath(const Path & path, Sink & sink) override;
|
2016-03-21 18:55:57 +02:00
|
|
|
|
2016-02-24 15:48:16 +02:00
|
|
|
BuildResult buildDerivation(const Path & drvPath, const BasicDerivation & drv,
|
2016-10-21 19:09:30 +03:00
|
|
|
BuildMode buildMode) override
|
2017-05-01 14:43:34 +03:00
|
|
|
{ unsupported(); }
|
2016-02-24 15:48:16 +02:00
|
|
|
|
2016-05-04 21:15:41 +03:00
|
|
|
void ensurePath(const Path & path) override
|
2017-05-01 14:43:34 +03:00
|
|
|
{ unsupported(); }
|
2016-02-24 15:48:16 +02:00
|
|
|
|
|
|
|
void addTempRoot(const Path & path) override
|
2017-05-01 14:43:34 +03:00
|
|
|
{ unsupported(); }
|
2016-02-24 15:48:16 +02:00
|
|
|
|
|
|
|
void addIndirectRoot(const Path & path) override
|
2017-05-01 14:43:34 +03:00
|
|
|
{ unsupported(); }
|
2016-02-24 15:48:16 +02:00
|
|
|
|
|
|
|
Roots findRoots() override
|
2017-05-01 14:43:34 +03:00
|
|
|
{ unsupported(); }
|
2016-02-24 15:48:16 +02:00
|
|
|
|
|
|
|
void collectGarbage(const GCOptions & options, GCResults & results) override
|
2017-05-01 14:43:34 +03:00
|
|
|
{ unsupported(); }
|
2016-02-24 15:48:16 +02:00
|
|
|
|
2016-02-25 18:43:19 +02:00
|
|
|
ref<FSAccessor> getFSAccessor() override;
|
|
|
|
|
2017-11-14 19:44:05 +02:00
|
|
|
void addSignatures(const Path & storePath, const StringSet & sigs) override;
|
2016-04-05 16:30:22 +03:00
|
|
|
|
2017-03-13 15:07:58 +02:00
|
|
|
std::shared_ptr<std::string> getBuildLog(const Path & path) override;
|
|
|
|
|
2017-07-04 17:34:53 +03:00
|
|
|
int getPriority() override { return priority; }
|
|
|
|
|
2016-02-24 15:48:16 +02:00
|
|
|
};
|
|
|
|
|
2018-03-28 00:12:31 +03:00
|
|
|
MakeError(NoSuchBinaryCacheFile, Error);
|
|
|
|
|
2016-02-24 15:48:16 +02:00
|
|
|
}
|