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;
|
|
|
|
|
2020-09-10 11:55:51 +03:00
|
|
|
struct BinaryCacheStoreConfig : virtual StoreConfig
|
2016-02-24 15:48:16 +02:00
|
|
|
{
|
2020-09-10 11:55:51 +03:00
|
|
|
using StoreConfig::StoreConfig;
|
2016-02-24 15:48:16 +02:00
|
|
|
|
2020-09-15 10:10:37 +03:00
|
|
|
const Setting<std::string> compression{(StoreConfig*) this, "xz", "compression", "NAR compression method ('xz', 'bzip2', or 'none')"};
|
|
|
|
const Setting<bool> writeNARListing{(StoreConfig*) this, false, "write-nar-listing", "whether to write a JSON file listing the files in each NAR"};
|
|
|
|
const Setting<bool> writeDebugInfo{(StoreConfig*) this, false, "index-debug-info", "whether to index DWARF debug info files by build ID"};
|
|
|
|
const Setting<Path> secretKeyFile{(StoreConfig*) this, "", "secret-key", "path to secret key used to sign the binary cache"};
|
|
|
|
const Setting<Path> localNarCache{(StoreConfig*) this, "", "local-nar-cache", "path to a local cache of NARs"};
|
|
|
|
const Setting<bool> parallelCompression{(StoreConfig*) this, false, "parallel-compression",
|
2018-02-07 22:06:11 +02:00
|
|
|
"enable multi-threading compression, available for xz only currently"};
|
2020-09-10 11:55:51 +03:00
|
|
|
};
|
|
|
|
|
2020-12-20 17:33:12 +02:00
|
|
|
class BinaryCacheStore : public virtual BinaryCacheStoreConfig, public virtual Store
|
2020-09-10 11:55:51 +03:00
|
|
|
{
|
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:
|
|
|
|
|
2020-10-08 18:36:51 +03:00
|
|
|
// The prefix under which realisation infos will be stored
|
2021-05-04 11:35:34 +03:00
|
|
|
const std::string realisationsPrefix = "realisations";
|
2020-10-08 18:36:51 +03:00
|
|
|
|
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,
|
2020-07-13 21:07:19 +03:00
|
|
|
std::shared_ptr<std::basic_iostream<char>> istream,
|
2017-03-14 16:26:01 +02:00
|
|
|
const std::string & mimeType) = 0;
|
2016-02-24 15:48:16 +02:00
|
|
|
|
2020-07-10 21:58:02 +03:00
|
|
|
void upsertFile(const std::string & path,
|
2020-07-13 21:07:19 +03:00
|
|
|
std::string && data,
|
2020-07-10 21:58:02 +03:00
|
|
|
const std::string & mimeType);
|
|
|
|
|
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,
|
2019-09-03 14:00:55 +03:00
|
|
|
Callback<std::shared_ptr<std::string>> callback) noexcept;
|
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
|
|
|
|
|
|
|
public:
|
|
|
|
|
2020-09-09 12:29:17 +03:00
|
|
|
virtual void init() override;
|
2016-02-24 15:48:16 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2016-02-24 17:52:28 +02:00
|
|
|
std::string narMagic;
|
|
|
|
|
2019-12-05 20:11:09 +02:00
|
|
|
std::string narInfoFileFor(const StorePath & storePath);
|
2016-02-24 15:48:16 +02:00
|
|
|
|
2017-11-14 19:44:05 +02:00
|
|
|
void writeNarInfo(ref<NarInfo> narInfo);
|
|
|
|
|
2020-09-23 17:40:41 +03:00
|
|
|
ref<const ValidPathInfo> addToStoreCommon(
|
2020-08-15 19:41:28 +03:00
|
|
|
Source & narSource, RepairFlag repair, CheckSigsFlag checkSigs,
|
|
|
|
std::function<ValidPathInfo(HashResult)> mkInfo);
|
|
|
|
|
2016-02-24 15:48:16 +02:00
|
|
|
public:
|
|
|
|
|
2019-12-05 20:11:09 +02:00
|
|
|
bool isValidPathUncached(const StorePath & path) override;
|
2016-02-24 15:48:16 +02:00
|
|
|
|
2019-12-05 20:11:09 +02:00
|
|
|
void queryPathInfoUncached(const StorePath & path,
|
2018-09-25 19:54:16 +03:00
|
|
|
Callback<std::shared_ptr<const ValidPathInfo>> callback) noexcept override;
|
2016-02-24 15:48:16 +02:00
|
|
|
|
2019-12-05 20:11:09 +02:00
|
|
|
std::optional<StorePath> queryPathFromHashPart(const std::string & hashPart) override
|
2019-01-18 14:34:23 +02:00
|
|
|
{ unsupported("queryPathFromHashPart"); }
|
2016-02-24 15:48:16 +02:00
|
|
|
|
2020-05-29 23:19:48 +03:00
|
|
|
void addToStore(const ValidPathInfo & info, Source & narSource,
|
2020-07-13 18:37:44 +03:00
|
|
|
RepairFlag repair, CheckSigsFlag checkSigs) override;
|
2016-05-04 14:36:54 +03:00
|
|
|
|
2020-08-15 19:41:28 +03:00
|
|
|
StorePath addToStoreFromDump(Source & dump, const string & name,
|
|
|
|
FileIngestionMethod method, HashType hashAlgo, RepairFlag repair) override;
|
|
|
|
|
2019-12-05 20:11:09 +02:00
|
|
|
StorePath addToStore(const string & name, const Path & srcPath,
|
2020-05-27 21:04:20 +03:00
|
|
|
FileIngestionMethod method, HashType hashAlgo,
|
2017-06-28 19:11:01 +03:00
|
|
|
PathFilter & filter, RepairFlag repair) override;
|
2016-02-24 15:48:16 +02:00
|
|
|
|
2019-12-05 20:11:09 +02:00
|
|
|
StorePath addTextToStore(const string & name, const string & s,
|
|
|
|
const StorePathSet & references, RepairFlag repair) override;
|
2016-02-24 15:48:16 +02:00
|
|
|
|
2020-10-08 18:36:51 +03:00
|
|
|
void registerDrvOutput(const Realisation & info) override;
|
|
|
|
|
|
|
|
std::optional<const Realisation> queryRealisation(const DrvOutput &) override;
|
|
|
|
|
2019-12-05 20:11:09 +02:00
|
|
|
void narFromPath(const StorePath & path, Sink & sink) override;
|
2016-03-21 18:55:57 +02:00
|
|
|
|
2016-02-25 18:43:19 +02:00
|
|
|
ref<FSAccessor> getFSAccessor() override;
|
|
|
|
|
2019-12-05 20:11:09 +02:00
|
|
|
void addSignatures(const StorePath & storePath, const StringSet & sigs) override;
|
2016-04-05 16:30:22 +03:00
|
|
|
|
2019-12-05 20:11:09 +02:00
|
|
|
std::shared_ptr<std::string> getBuildLog(const StorePath & path) override;
|
2017-03-13 15:07:58 +02:00
|
|
|
|
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
|
|
|
}
|