2016-02-24 13:48:16 +00: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 13:55:38 +00:00
|
|
|
public:
|
2016-02-24 13:48:16 +00:00
|
|
|
|
2017-04-13 13:55:38 +00: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"};
|
2019-09-04 17:24:35 +00:00
|
|
|
const Setting<bool> writeDebugInfo{this, false, "index-debug-info", "whether to index DWARF debug info files by build ID"};
|
2017-04-13 13:55:38 +00:00
|
|
|
const Setting<Path> secretKeyFile{this, "", "secret-key", "path to secret key used to sign the binary cache"};
|
2017-10-17 19:15:33 +00:00
|
|
|
const Setting<Path> localNarCache{this, "", "local-nar-cache", "path to a local cache of NARs"};
|
2018-02-07 20:06:11 +00:00
|
|
|
const Setting<bool> parallelCompression{this, false, "parallel-compression",
|
|
|
|
"enable multi-threading compression, available for xz only currently"};
|
2016-02-24 13:48:16 +00:00
|
|
|
|
2017-04-13 13:55:38 +00:00
|
|
|
private:
|
2016-04-29 15:02:57 +00:00
|
|
|
|
2017-04-13 13:55:38 +00:00
|
|
|
std::unique_ptr<SecretKey> secretKey;
|
2016-10-21 14:50:28 +00:00
|
|
|
|
2016-02-24 13:48:16 +00:00
|
|
|
protected:
|
|
|
|
|
2016-06-01 12:49:12 +00:00
|
|
|
BinaryCacheStore(const Params & params);
|
2016-02-24 13:48:16 +00:00
|
|
|
|
2016-10-21 14:50:28 +00:00
|
|
|
public:
|
|
|
|
|
2016-02-24 13:48:16 +00:00
|
|
|
virtual bool fileExists(const std::string & path) = 0;
|
|
|
|
|
2017-03-14 14:26:01 +00:00
|
|
|
virtual void upsertFile(const std::string & path,
|
|
|
|
const std::string & data,
|
|
|
|
const std::string & mimeType) = 0;
|
2016-02-24 13:48:16 +00:00
|
|
|
|
2018-03-27 21:12:31 +00: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 16:54:14 +00:00
|
|
|
virtual void getFile(const std::string & path,
|
2019-09-03 11:00:55 +00:00
|
|
|
Callback<std::shared_ptr<std::string>> callback) noexcept;
|
2016-09-16 16:54:14 +00:00
|
|
|
|
|
|
|
std::shared_ptr<std::string> getFile(const std::string & path);
|
2016-02-24 13:48:16 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
virtual void init();
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2016-02-24 15:52:28 +00:00
|
|
|
std::string narMagic;
|
|
|
|
|
2019-12-05 18:11:09 +00:00
|
|
|
std::string narInfoFileFor(const StorePath & storePath);
|
2016-02-24 13:48:16 +00:00
|
|
|
|
2017-11-14 17:44:05 +00:00
|
|
|
void writeNarInfo(ref<NarInfo> narInfo);
|
|
|
|
|
2016-02-24 13:48:16 +00:00
|
|
|
public:
|
|
|
|
|
2019-12-05 18:11:09 +00:00
|
|
|
bool isValidPathUncached(const StorePath & path) override;
|
2016-02-24 13:48:16 +00:00
|
|
|
|
2019-12-05 18:11:09 +00:00
|
|
|
void queryPathInfoUncached(const StorePath & path,
|
2018-09-25 16:54:16 +00:00
|
|
|
Callback<std::shared_ptr<const ValidPathInfo>> callback) noexcept override;
|
2016-02-24 13:48:16 +00:00
|
|
|
|
2019-12-05 18:11:09 +00:00
|
|
|
std::optional<StorePath> queryPathFromHashPart(const std::string & hashPart) override
|
2019-01-18 12:34:23 +00:00
|
|
|
{ unsupported("queryPathFromHashPart"); }
|
2016-02-24 13:48:16 +00:00
|
|
|
|
2016-10-21 14:50:28 +00:00
|
|
|
void addToStore(const ValidPathInfo & info, const ref<std::string> & nar,
|
2017-06-28 16:11:01 +00:00
|
|
|
RepairFlag repair, CheckSigsFlag checkSigs,
|
2016-10-21 16:09:30 +00:00
|
|
|
std::shared_ptr<FSAccessor> accessor) override;
|
2016-05-04 11:36:54 +00:00
|
|
|
|
2019-12-05 18:11:09 +00:00
|
|
|
StorePath addToStore(const string & name, const Path & srcPath,
|
2020-03-29 05:04:55 +00:00
|
|
|
FileIngestionMethod recursive, HashType hashAlgo,
|
2017-06-28 16:11:01 +00:00
|
|
|
PathFilter & filter, RepairFlag repair) override;
|
2016-02-24 13:48:16 +00:00
|
|
|
|
2019-12-05 18:11:09 +00:00
|
|
|
StorePath addTextToStore(const string & name, const string & s,
|
|
|
|
const StorePathSet & references, RepairFlag repair) override;
|
2016-02-24 13:48:16 +00:00
|
|
|
|
2019-12-05 18:11:09 +00:00
|
|
|
void narFromPath(const StorePath & path, Sink & sink) override;
|
2016-03-21 16:55:57 +00:00
|
|
|
|
2019-12-05 18:11:09 +00:00
|
|
|
BuildResult buildDerivation(const StorePath & drvPath, const BasicDerivation & drv,
|
2016-10-21 16:09:30 +00:00
|
|
|
BuildMode buildMode) override
|
2019-01-18 12:34:23 +00:00
|
|
|
{ unsupported("buildDerivation"); }
|
2016-02-24 13:48:16 +00:00
|
|
|
|
2019-12-05 18:11:09 +00:00
|
|
|
void ensurePath(const StorePath & path) override
|
2019-01-18 12:34:23 +00:00
|
|
|
{ unsupported("ensurePath"); }
|
2016-02-24 13:48:16 +00:00
|
|
|
|
2016-02-25 16:43:19 +00:00
|
|
|
ref<FSAccessor> getFSAccessor() override;
|
|
|
|
|
2019-12-05 18:11:09 +00:00
|
|
|
void addSignatures(const StorePath & storePath, const StringSet & sigs) override;
|
2016-04-05 13:30:22 +00:00
|
|
|
|
2019-12-05 18:11:09 +00:00
|
|
|
std::shared_ptr<std::string> getBuildLog(const StorePath & path) override;
|
2017-03-13 13:07:58 +00:00
|
|
|
|
2016-02-24 13:48:16 +00:00
|
|
|
};
|
|
|
|
|
2018-03-27 21:12:31 +00:00
|
|
|
MakeError(NoSuchBinaryCacheFile, Error);
|
|
|
|
|
2016-02-24 13:48:16 +00:00
|
|
|
}
|