Nix 2.93.3
Lix: A modern, delicious implementation of the Nix package manager; unstable internal interfaces
Loading...
Searching...
No Matches
binary-cache-store.hh
Go to the documentation of this file.
1#pragma once
3
7
10#include "lix/libutil/pool.hh"
11
12#include <atomic>
13
14namespace nix {
15
16struct NarInfo;
17
18struct BinaryCacheStoreConfig : virtual StoreConfig
19{
20 using StoreConfig::StoreConfig;
21
22 const Setting<std::string> compression{this, "xz", "compression",
23 "NAR compression method (`xz`, `bzip2`, `gzip`, `zstd`, or `none`)."};
24
25 const Setting<bool> writeNARListing{this, false, "write-nar-listing",
26 "Whether to write a JSON file that lists the files in each NAR."};
27
28 const Setting<bool> writeDebugInfo{this, false, "index-debug-info",
29 R"(
30 Whether to index DWARF debug info files by build ID. This allows [`dwarffs`](https://github.com/edolstra/dwarffs) to
31 fetch debug info on demand
32 )"};
33
34 const Setting<Path> secretKeyFile{this, "", "secret-key",
35 "Path to the secret key used to sign the binary cache."};
36
37 const Setting<Path> localNarCache{this, "", "local-nar-cache",
38 "Path to a local cache of NARs fetched from this binary cache, used by commands such as `nix store cat`."};
39
40 const Setting<bool> parallelCompression{this, false, "parallel-compression",
41 "Enable multi-threaded compression of NARs. This is currently only available for `xz` and `zstd`."};
42
43 const Setting<int> compressionLevel{this, -1, "compression-level",
44 R"(
45 The *preset level* to be used when compressing NARs.
46 The meaning and accepted values depend on the compression method selected.
47 `-1` specifies that the default compression level should be used.
48 )"};
49};
50
51
56class BinaryCacheStore : public virtual Store,
57 public virtual LogStore
58{
59
60private:
61
62 std::unique_ptr<SecretKey> secretKey;
63
64protected:
65
66 // The prefix under which realisation infos will be stored
67 const std::string realisationsPrefix = "realisations";
68
69 BinaryCacheStore(const BinaryCacheStoreConfig & config);
70
71public:
72
73 BinaryCacheStoreConfig & config() override = 0;
74 const BinaryCacheStoreConfig & config() const override = 0;
75
76 virtual bool fileExists(const std::string & path) = 0;
77
78 virtual void upsertFile(const std::string & path,
79 std::shared_ptr<std::basic_iostream<char>> istream,
80 const std::string & mimeType) = 0;
81
82 void upsertFile(const std::string & path,
83 // FIXME: use std::string_view
84 std::string && data,
85 const std::string & mimeType);
86
90 virtual box_ptr<Source> getFile(const std::string & path) = 0;
91
92 virtual std::optional<std::string> getFileContents(const std::string & path);
93
94public:
95
96 virtual kj::Promise<Result<void>> init() override;
97
98private:
99
100 std::string narMagic;
101
102 std::string narInfoFileFor(const StorePath & storePath);
103
104 kj::Promise<Result<void>> writeNarInfo(ref<NarInfo> narInfo);
105
106 kj::Promise<Result<ref<const ValidPathInfo>>> addToStoreCommon(
107 AsyncInputStream & narSource, RepairFlag repair, CheckSigsFlag checkSigs,
108 std::function<ValidPathInfo(HashResult)> mkInfo);
109
110public:
111
112 kj::Promise<Result<bool>> isValidPathUncached(const StorePath & path) override;
113
114 kj::Promise<Result<std::shared_ptr<const ValidPathInfo>>>
115 queryPathInfoUncached(const StorePath & path) override;
116
117 kj::Promise<Result<std::optional<StorePath>>>
118 queryPathFromHashPart(const std::string & hashPart) override;
119
120 kj::Promise<Result<void>> addToStore(const ValidPathInfo & info, AsyncInputStream & narSource,
121 RepairFlag repair, CheckSigsFlag checkSigs) override;
122
123 kj::Promise<Result<StorePath>> addToStoreFromDump(
124 AsyncInputStream & dump,
125 std::string_view name,
126 FileIngestionMethod method,
127 HashType hashAlgo,
128 RepairFlag repair,
129 const StorePathSet & references
130 ) override;
131
132 kj::Promise<Result<StorePath>> addToStoreRecursive(
133 std::string_view name,
134 const PreparedDump & source,
135 HashType hashAlgo,
136 RepairFlag repair) override;
137 kj::Promise<Result<StorePath>> addToStoreFlat(
138 std::string_view name,
139 const Path & srcPath,
140 HashType hashAlgo,
141 RepairFlag repair) override;
142
143 kj::Promise<Result<StorePath>> addTextToStore(
144 std::string_view name,
145 std::string_view s,
146 const StorePathSet & references,
147 RepairFlag repair) override;
148
149 kj::Promise<Result<void>> registerDrvOutput(const Realisation & info) override;
150
151 kj::Promise<Result<std::shared_ptr<const Realisation>>>
152 queryRealisationUncached(const DrvOutput &) override;
153
154 kj::Promise<Result<box_ptr<Source>>> narFromPath(const StorePath & path) override;
155
157
158 kj::Promise<Result<void>>
159 addSignatures(const StorePath & storePath, const StringSet & sigs) override;
160
161 kj::Promise<Result<std::optional<std::string>>> getBuildLogExact(const StorePath & path) override;
162
163 kj::Promise<Result<void>> addBuildLog(const StorePath & drvPath, std::string_view log) override;
164
165};
166
167MakeError(NoSuchBinaryCacheFile, Error);
168
169}
Definition async-io.hh:19
kj::Promise< Result< StorePath > > addToStoreFromDump(AsyncInputStream &dump, std::string_view name, FileIngestionMethod method, HashType hashAlgo, RepairFlag repair, const StorePathSet &references) override
Definition binary-cache-store.cc:296
virtual box_ptr< Source > getFile(const std::string &path)=0
kj::Promise< Result< StorePath > > addTextToStore(std::string_view name, std::string_view s, const StorePathSet &references, RepairFlag repair) override
Definition binary-cache-store.cc:476
kj::Promise< Result< StorePath > > addToStoreRecursive(std::string_view name, const PreparedDump &source, HashType hashAlgo, RepairFlag repair) override
Definition binary-cache-store.cc:432
kj::Promise< Result< std::optional< StorePath > > > queryPathFromHashPart(const std::string &hashPart) override
Definition binary-cache-store.cc:340
kj::Promise< Result< void > > addSignatures(const StorePath &storePath, const StringSet &sigs) override
Definition binary-cache-store.cc:540
ref< FSAccessor > getFSAccessor() override
Definition binary-cache-store.cc:534
kj::Promise< Result< void > > registerDrvOutput(const Realisation &info) override
Definition binary-cache-store.cc:523
virtual kj::Promise< Result< void > > init() override
Definition binary-cache-store.cc:37
kj::Promise< Result< box_ptr< Source > > > narFromPath(const StorePath &path) override
Definition binary-cache-store.cc:353
kj::Promise< Result< std::shared_ptr< const ValidPathInfo > > > queryPathInfoUncached(const StorePath &path) override
Definition binary-cache-store.cc:389
kj::Promise< Result< void > > addToStore(const ValidPathInfo &info, AsyncInputStream &narSource, RepairFlag repair, CheckSigsFlag checkSigs) override
Definition binary-cache-store.cc:271
Definition config.hh:310
Definition path.hh:21
Definition box_ptr.hh:16
Definition ref.hh:19
FileIngestionMethod
Definition content-address.hh:38
std::pair< Hash, uint64_t > HashResult
Definition hash.hh:167
Definition binary-cache-store.hh:19
Definition realisation.hh:24
Definition log-store.hh:10
Definition nar-info.hh:13
Definition archive.hh:76
Definition realisation.hh:49
Definition path-info.hh:83
std::string Path
Definition types.hh:28