2016-02-24 14:48:16 +01:00
|
|
|
#pragma once
|
2023-04-01 05:18:41 +02:00
|
|
|
///@file
|
2016-02-24 14:48:16 +01:00
|
|
|
|
2024-01-03 21:02:20 +01:00
|
|
|
#include "signature/local-keys.hh"
|
2016-02-24 14:48:16 +01:00
|
|
|
#include "store-api.hh"
|
2022-03-08 19:20:39 +01:00
|
|
|
#include "log-store.hh"
|
2016-02-24 14:48:16 +01:00
|
|
|
|
|
|
|
#include "pool.hh"
|
|
|
|
|
|
|
|
#include <atomic>
|
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
|
|
|
struct NarInfo;
|
|
|
|
|
2020-09-10 10:55:51 +02:00
|
|
|
struct BinaryCacheStoreConfig : virtual StoreConfig
|
2016-02-24 14:48:16 +01:00
|
|
|
{
|
2020-09-10 10:55:51 +02:00
|
|
|
using StoreConfig::StoreConfig;
|
2016-02-24 14:48:16 +01:00
|
|
|
|
2023-10-30 23:12:37 +01:00
|
|
|
const Setting<std::string> compression{this, "xz", "compression",
|
2023-03-22 14:23:36 +01:00
|
|
|
"NAR compression method (`xz`, `bzip2`, `gzip`, `zstd`, or `none`)."};
|
|
|
|
|
2023-10-30 23:12:37 +01:00
|
|
|
const Setting<bool> writeNARListing{this, false, "write-nar-listing",
|
2023-03-22 14:23:36 +01:00
|
|
|
"Whether to write a JSON file that lists the files in each NAR."};
|
|
|
|
|
2023-10-30 23:12:37 +01:00
|
|
|
const Setting<bool> writeDebugInfo{this, false, "index-debug-info",
|
2023-03-22 14:23:36 +01:00
|
|
|
R"(
|
|
|
|
Whether to index DWARF debug info files by build ID. This allows [`dwarffs`](https://github.com/edolstra/dwarffs) to
|
|
|
|
fetch debug info on demand
|
|
|
|
)"};
|
|
|
|
|
2023-10-30 23:12:37 +01:00
|
|
|
const Setting<Path> secretKeyFile{this, "", "secret-key",
|
2023-03-22 14:23:36 +01:00
|
|
|
"Path to the secret key used to sign the binary cache."};
|
|
|
|
|
2023-10-30 23:12:37 +01:00
|
|
|
const Setting<Path> localNarCache{this, "", "local-nar-cache",
|
2023-03-22 14:23:36 +01:00
|
|
|
"Path to a local cache of NARs fetched from this binary cache, used by commands such as `nix store cat`."};
|
|
|
|
|
2023-10-30 23:12:37 +01:00
|
|
|
const Setting<bool> parallelCompression{this, false, "parallel-compression",
|
2023-03-22 14:23:36 +01:00
|
|
|
"Enable multi-threaded compression of NARs. This is currently only available for `xz` and `zstd`."};
|
|
|
|
|
2023-10-30 23:12:37 +01:00
|
|
|
const Setting<int> compressionLevel{this, -1, "compression-level",
|
2023-03-22 14:23:36 +01:00
|
|
|
R"(
|
|
|
|
The *preset level* to be used when compressing NARs.
|
|
|
|
The meaning and accepted values depend on the compression method selected.
|
|
|
|
`-1` specifies that the default compression level should be used.
|
|
|
|
)"};
|
2020-09-10 10:55:51 +02:00
|
|
|
};
|
|
|
|
|
2023-04-07 15:55:28 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @note subclasses must implement at least one of the two
|
|
|
|
* virtual getFile() methods.
|
|
|
|
*/
|
2022-03-08 19:20:39 +01:00
|
|
|
class BinaryCacheStore : public virtual BinaryCacheStoreConfig,
|
|
|
|
public virtual Store,
|
|
|
|
public virtual LogStore
|
2020-09-10 10:55:51 +02:00
|
|
|
{
|
2016-02-24 14:48:16 +01:00
|
|
|
|
2017-04-13 15:55:38 +02:00
|
|
|
private:
|
2024-01-03 21:02:20 +01:00
|
|
|
std::unique_ptr<Signer> signer;
|
2016-10-21 16:50:28 +02:00
|
|
|
|
2016-02-24 14:48:16 +01:00
|
|
|
protected:
|
|
|
|
|
2020-10-08 17:36:51 +02:00
|
|
|
// The prefix under which realisation infos will be stored
|
2021-05-04 10:35:34 +02:00
|
|
|
const std::string realisationsPrefix = "realisations";
|
2020-10-08 17:36:51 +02:00
|
|
|
|
2016-06-01 14:49:12 +02:00
|
|
|
BinaryCacheStore(const Params & params);
|
2016-02-24 14:48:16 +01:00
|
|
|
|
2016-10-21 16:50:28 +02:00
|
|
|
public:
|
|
|
|
|
2016-02-24 14:48:16 +01:00
|
|
|
virtual bool fileExists(const std::string & path) = 0;
|
|
|
|
|
2017-03-14 15:26:01 +01:00
|
|
|
virtual void upsertFile(const std::string & path,
|
2020-07-13 20:07:19 +02:00
|
|
|
std::shared_ptr<std::basic_iostream<char>> istream,
|
2017-03-14 15:26:01 +01:00
|
|
|
const std::string & mimeType) = 0;
|
2016-02-24 14:48:16 +01:00
|
|
|
|
2020-07-10 20:58:02 +02:00
|
|
|
void upsertFile(const std::string & path,
|
2022-01-18 16:14:01 +01:00
|
|
|
// FIXME: use std::string_view
|
2020-07-13 20:07:19 +02:00
|
|
|
std::string && data,
|
2020-07-10 20:58:02 +02:00
|
|
|
const std::string & mimeType);
|
|
|
|
|
2023-04-07 15:55:28 +02:00
|
|
|
/**
|
|
|
|
* Dump the contents of the specified file to a sink.
|
|
|
|
*/
|
2018-03-27 23:12:31 +02:00
|
|
|
virtual void getFile(const std::string & path, Sink & sink);
|
|
|
|
|
2023-04-07 15:55:28 +02:00
|
|
|
/**
|
|
|
|
* Fetch the specified file and call the specified callback with
|
|
|
|
* the result. A subclass may implement this asynchronously.
|
|
|
|
*/
|
2022-01-17 22:20:05 +01:00
|
|
|
virtual void getFile(
|
|
|
|
const std::string & path,
|
|
|
|
Callback<std::optional<std::string>> callback) noexcept;
|
2016-09-16 18:54:14 +02:00
|
|
|
|
2022-01-17 22:20:05 +01:00
|
|
|
std::optional<std::string> getFile(const std::string & path);
|
2016-02-24 14:48:16 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2020-09-09 11:29:17 +02:00
|
|
|
virtual void init() override;
|
2016-02-24 14:48:16 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2016-02-24 16:52:28 +01:00
|
|
|
std::string narMagic;
|
|
|
|
|
2019-12-05 19:11:09 +01:00
|
|
|
std::string narInfoFileFor(const StorePath & storePath);
|
2016-02-24 14:48:16 +01:00
|
|
|
|
2017-11-14 18:44:05 +01:00
|
|
|
void writeNarInfo(ref<NarInfo> narInfo);
|
|
|
|
|
2020-09-23 16:40:41 +02:00
|
|
|
ref<const ValidPathInfo> addToStoreCommon(
|
2020-08-15 18:41:28 +02:00
|
|
|
Source & narSource, RepairFlag repair, CheckSigsFlag checkSigs,
|
|
|
|
std::function<ValidPathInfo(HashResult)> mkInfo);
|
|
|
|
|
2016-02-24 14:48:16 +01:00
|
|
|
public:
|
|
|
|
|
2019-12-05 19:11:09 +01:00
|
|
|
bool isValidPathUncached(const StorePath & path) override;
|
2016-02-24 14:48:16 +01:00
|
|
|
|
2019-12-05 19:11:09 +01:00
|
|
|
void queryPathInfoUncached(const StorePath & path,
|
2018-09-25 18:54:16 +02:00
|
|
|
Callback<std::shared_ptr<const ValidPathInfo>> callback) noexcept override;
|
2016-02-24 14:48:16 +01:00
|
|
|
|
2022-10-18 17:48:09 +02:00
|
|
|
std::optional<StorePath> queryPathFromHashPart(const std::string & hashPart) override;
|
2016-02-24 14:48:16 +01:00
|
|
|
|
2020-05-29 22:19:48 +02:00
|
|
|
void addToStore(const ValidPathInfo & info, Source & narSource,
|
2020-07-13 17:37:44 +02:00
|
|
|
RepairFlag repair, CheckSigsFlag checkSigs) override;
|
2016-05-04 13:36:54 +02:00
|
|
|
|
2023-11-04 21:25:41 +01:00
|
|
|
StorePath addToStoreFromDump(
|
|
|
|
Source & dump,
|
|
|
|
std::string_view name,
|
|
|
|
ContentAddressMethod method,
|
|
|
|
HashAlgorithm hashAlgo,
|
|
|
|
const StorePathSet & references,
|
|
|
|
RepairFlag repair) override;
|
2020-08-15 18:41:28 +02:00
|
|
|
|
2022-02-25 16:00:00 +01:00
|
|
|
StorePath addToStore(
|
2023-11-04 21:25:41 +01:00
|
|
|
std::string_view name,
|
|
|
|
SourceAccessor & accessor,
|
|
|
|
const CanonPath & srcPath,
|
|
|
|
ContentAddressMethod method,
|
|
|
|
HashAlgorithm hashAlgo,
|
|
|
|
const StorePathSet & references,
|
|
|
|
PathFilter & filter,
|
|
|
|
RepairFlag repair) override;
|
2022-02-25 16:00:00 +01:00
|
|
|
|
2020-10-08 17:36:51 +02:00
|
|
|
void registerDrvOutput(const Realisation & info) override;
|
|
|
|
|
2021-10-27 11:36:51 +02:00
|
|
|
void queryRealisationUncached(const DrvOutput &,
|
|
|
|
Callback<std::shared_ptr<const Realisation>> callback) noexcept override;
|
2020-10-08 17:36:51 +02:00
|
|
|
|
2019-12-05 19:11:09 +01:00
|
|
|
void narFromPath(const StorePath & path, Sink & sink) override;
|
2016-03-21 17:55:57 +01:00
|
|
|
|
2023-11-01 17:09:28 +01:00
|
|
|
ref<SourceAccessor> getFSAccessor(bool requireValidPath) override;
|
2016-02-25 17:43:19 +01:00
|
|
|
|
2019-12-05 19:11:09 +01:00
|
|
|
void addSignatures(const StorePath & storePath, const StringSet & sigs) override;
|
2016-04-05 15:30:22 +02:00
|
|
|
|
2022-12-15 21:58:54 +01:00
|
|
|
std::optional<std::string> getBuildLogExact(const StorePath & path) override;
|
2017-03-13 14:07:58 +01:00
|
|
|
|
2022-01-18 16:14:01 +01:00
|
|
|
void addBuildLog(const StorePath & drvPath, std::string_view log) override;
|
|
|
|
|
2016-02-24 14:48:16 +01:00
|
|
|
};
|
|
|
|
|
2018-03-27 23:12:31 +02:00
|
|
|
MakeError(NoSuchBinaryCacheFile, Error);
|
|
|
|
|
2016-02-24 14:48:16 +01:00
|
|
|
}
|