7#include "lix/libutil/json-fwd.hh"
21#include "lix/libutil/json-fwd.hh"
31#include <unordered_map>
32#include <unordered_set>
65MakeError(SubstError, Error);
69MakeError(BuildError, Error);
74MakeError(InvalidPath, Error);
75MakeError(Unsupported, Error);
76MakeError(SubstituteGone, Error);
77MakeError(SubstituterDisabled, Error);
82MakeError(BadStorePath, Error);
84MakeError(InvalidStoreURI, Error);
93typedef std::map<std::string, StorePath> OutputPathMap;
96enum CheckSigsFlag :
bool { NoCheckSigs =
false, CheckSigs =
true };
97enum SubstituteFlag :
bool { NoSubstitute =
false, Substitute =
true };
98enum AllowInvalidFlag :
bool { DisallowInvalid =
false, AllowInvalid =
true };
106enum BuildMode { bmNormal, bmRepair, bmCheck };
108BuildMode buildModeFromInteger(
int);
110enum TrustedFlag :
bool { NotTrusted =
false, Trusted =
true };
119typedef std::map<StorePath, std::optional<ContentAddress>> StorePathCAMap;
123 typedef std::map<std::string, std::string> Params;
125 using Config::Config;
129 static StringSet getDefaultSystemFeatures();
136 virtual const std::string
name() = 0;
158 Logical location of the Nix store, usually
159 `/nix/store`. Note that you can only copy store paths
160 between stores if they have the same `store` setting.
162 const Path storeDir = storeDir_;
164 const Setting<int> pathInfoCacheSize{
this, 65536,
"path-info-cache-size",
165 "Size of the in-memory store path metadata cache."};
167 const Setting<bool> isTrusted{
this,
false,
"trusted",
169 Whether paths from this store can be used as substitutes
170 even if they are not signed by a key listed in the
171 [`trusted-public-keys`](@docroot@/command-ref/conf-file.md#conf-trusted-public-keys)
175 Setting<int> priority{this, 0,
"priority",
177 Priority of this store when used as a substituter. A lower value means a higher priority.
180 Setting<bool> wantMassQuery{this,
false,
"want-mass-query",
182 Whether this store (when used as a substituter) can be
183 queried efficiently for path validity.
186 Setting<StringSet> systemFeatures{this, getDefaultSystemFeatures(),
188 "Optional features that the system this store builds on implements (like \"kvm\").",
194class Store :
public std::enable_shared_from_this<Store>
203 std::chrono::time_point<std::chrono::steady_clock>
time_point = std::chrono::steady_clock::now();
208 std::shared_ptr<const ValidPathInfo>
value;
221 return value !=
nullptr;
232 std::shared_ptr<NarInfoDiskCache> diskCache;
241 virtual kj::Promise<Result<void>>
init()
243 return {result::success()};
249 virtual ~Store() noexcept(false) { }
251 virtual std::string getUri() = 0;
253 StorePath parseStorePath(std::string_view path)
const;
255 std::optional<StorePath> maybeParseStorePath(std::string_view path)
const;
257 std::string printStorePath(
const StorePath & path)
const;
266 PathSet printStorePathSet(
const StorePathSet & path)
const;
272 std::string
showPaths(
const StorePathSet & paths);
290 std::pair<StorePath, Path>
toStorePath(PathView path)
const;
307 std::string_view hash, std::string_view name)
const;
309 const Hash & hash, std::string_view name)
const;
311 StorePath makeOutputPath(std::string_view
id,
312 const Hash & hash, std::string_view name)
const;
314 StorePath makeFixedOutputPath(std::string_view name,
const FixedOutputInfo & info)
const;
316 StorePath makeTextPath(std::string_view name,
const TextInfo & info)
const;
318 StorePath makeFixedOutputPathFromCA(std::string_view name,
const ContentAddressWithReferences & ca)
const;
327 StorePath computeStorePathForPathFlat(std::string_view name,
const Path & srcPath)
const;
346 std::string_view name,
348 const StorePathSet & references)
const;
354 kj::Promise<Result<bool>>
isValidPath(
const StorePath & path);
358 virtual kj::Promise<Result<bool>> isValidPathUncached(
const StorePath & path);
373 virtual kj::Promise<Result<StorePathSet>>
queryValidPaths(
const StorePathSet & paths,
374 SubstituteFlag maybeSubstitute = NoSubstitute);
385 try {
unsupported(
"queryAllValidPaths"); }
catch (...) {
return {result::current_exception()}; }
387 constexpr static const char * MissingName =
"x";
393 kj::Promise<Result<ref<const ValidPathInfo>>>
queryPathInfo(
const StorePath & path);
398 kj::Promise<Result<std::shared_ptr<const Realisation>>>
queryRealisation(
const DrvOutput &);
417 virtual bool realisationIsUntrusted(
const Realisation & )
428 virtual kj::Promise<Result<std::shared_ptr<const ValidPathInfo>>>
430 virtual kj::Promise<Result<std::shared_ptr<const Realisation>>>
431 queryRealisationUncached(
const DrvOutput &) = 0;
439 virtual kj::Promise<Result<void>>
441 try {
unsupported(
"queryReferrers"); }
catch (...) {
return {result::current_exception()}; }
453 return {StorePathSet{}};
466 virtual kj::Promise<Result<std::map<std::string, std::optional<StorePath>>>>
477 virtual kj::Promise<Result<std::map<std::string, std::optional<StorePath>>>>
484 kj::Promise<Result<OutputPathMap>>
491 virtual kj::Promise<Result<std::optional<StorePath>>>
499 return {StorePathSet{}};
510 SubstitutablePathInfos & infos);
518 RepairFlag repair = NoRepair,
519 CheckSigsFlag checkSigs = CheckSigs
527 std::pair<ValidPathInfo, std::function<kj::Promise<Result<box_ptr<AsyncInputStream>>>()>>>;
535 RepairFlag repair = NoRepair,
536 CheckSigsFlag checkSigs = CheckSigs);
547 std::string_view name,
549 HashType hashAlgo = HashType::SHA256,
550 RepairFlag repair = NoRepair);
551 virtual kj::Promise<Result<StorePath>> addToStoreFlat(
552 std::string_view name,
553 const Path & srcPath,
554 HashType hashAlgo = HashType::SHA256,
555 RepairFlag repair = NoRepair);
562 kj::Promise<Result<ValidPathInfo>>
addToStoreSlow(std::string_view name,
const Path & srcPath,
563 FileIngestionMethod method = FileIngestionMethod::Recursive, HashType hashAlgo = HashType::SHA256,
564 std::optional<Hash> expectedCAHash = {});
577 std::string_view name,
579 HashType hashAlgo = HashType::SHA256,
580 RepairFlag repair = NoRepair,
581 const StorePathSet & references = StorePathSet()
583 try {
unsupported(
"addToStoreFromDump"); }
catch (...) {
return {result::current_exception()}; }
590 std::string_view name,
592 const StorePathSet & references,
593 RepairFlag repair = NoRepair) = 0;
605 try {
unsupported(
"registerDrvOutput"); }
catch (...) {
return {result::current_exception()}; }
606 virtual kj::Promise<Result<void>>
628 const std::vector<DerivedPath> & paths,
629 BuildMode buildMode = bmNormal,
630 std::shared_ptr<Store> evalStore =
nullptr);
639 const std::vector<DerivedPath> & paths,
640 BuildMode buildMode = bmNormal,
641 std::shared_ptr<Store> evalStore =
nullptr);
681 BuildMode buildMode = bmNormal
697 debug(
"not creating temporary root, store doesn't support GC");
698 return {result::success()};
700 return {result::current_exception()};
709 bool showDerivers,
bool showHash);
721 kj::Promise<Result<JSON>>
pathInfoToJSON(
const StorePathSet & storePaths,
722 bool includeImpureInfo,
bool showClosureSize,
723 Base hashBase = Base::Base32,
724 AllowInvalidFlag allowInvalid = DisallowInvalid);
731 kj::Promise<Result<std::pair<uint64_t, uint64_t>>>
getClosureSize(
const StorePath & storePath);
737 virtual kj::Promise<Result<void>>
optimiseStore() {
return {result::success()}; }
744 virtual kj::Promise<Result<bool>>
verifyStore(
bool checkContents, RepairFlag repair = NoRepair)
764 virtual kj::Promise<Result<void>>
766 try {
unsupported(
"addSignatures"); }
catch (...) {
return {result::current_exception()}; }
779 kj::Promise<Result<Derivation>>
readDerivation(
const StorePath & drvPath);
796 virtual kj::Promise<Result<void>>
computeFSClosure(
const StorePathSet & paths,
797 StorePathSet & out,
bool flipDirection =
false,
798 bool includeOutputs =
false,
bool includeDerivers =
false);
801 StorePathSet & out,
bool flipDirection =
false,
802 bool includeOutputs =
false,
bool includeDerivers =
false);
809 virtual kj::Promise<Result<void>>
queryMissing(
const std::vector<DerivedPath> & targets,
810 StorePathSet & willBuild, StorePathSet & willSubstitute, StorePathSet & unknown,
811 uint64_t & downloadSize, uint64_t & narSize);
817 kj::Promise<Result<StorePaths>>
topoSortPaths(
const StorePathSet & paths);
823 kj::Promise<Result<void>>
exportPaths(
const StorePathSet & paths, Sink & sink);
825 kj::Promise<Result<void>> exportPath(
const StorePath & path, Sink & sink);
832 kj::Promise<Result<StorePaths>>
833 importPaths(Source & source, CheckSigsFlag checkSigs = CheckSigs);
835 template<
template<
typename>
typename Wrapper = std::type_identity_t>
838 Wrapper<uint64_t> narInfoRead{0};
839 Wrapper<uint64_t> narInfoReadAverted{0};
840 Wrapper<uint64_t> narInfoMissing{0};
841 Wrapper<uint64_t> narInfoWrite{0};
842 Wrapper<uint64_t> pathInfoCacheSize{0};
843 Wrapper<uint64_t> narRead{0};
844 Wrapper<uint64_t> narReadBytes{0};
845 Wrapper<uint64_t> narReadCompressedBytes{0};
846 Wrapper<uint64_t> narWrite{0};
847 Wrapper<uint64_t> narWriteAverted{0};
848 Wrapper<uint64_t> narWriteBytes{0};
849 Wrapper<uint64_t> narWriteCompressedBytes{0};
850 Wrapper<uint64_t> narWriteCompressionTimeMs{0};
853 kj::Promise<Result<Stats<>>> getStats();
859 kj::Promise<Result<StorePathSet>>
860 exportReferences(
const StorePathSet & storePaths,
const StorePathSet & inputPaths);
875 (
co_await state.
lock())->pathInfoCache.clear();
882 virtual kj::Promise<Result<void>>
connect() {
return {result::success()}; }
889 return {result::success(0)};
903 virtual Path toRealPath(
const Path & storePath)
910 return toRealPath(printStorePath(storePath));
917 virtual kj::Promise<Result<void>>
setOptions() {
return {result::success()}; }
919 virtual kj::Promise<Result<std::optional<std::string>>> getVersion()
921 return {result::success(std::nullopt)};
926 Stats<std::atomic> stats;
937 throw Unsupported(
"operation '%s' is not supported by store '%s'", op, getUri());
946kj::Promise<Result<void>> copyStorePath(
949 const StorePath & storePath,
950 RepairFlag repair = NoRepair,
951 CheckSigsFlag checkSigs = CheckSigs);
962kj::Promise<Result<std::map<StorePath, StorePath>>> copyPaths(
963 Store & srcStore, Store & dstStore,
964 const RealisedPath::Set &,
965 RepairFlag repair = NoRepair,
966 CheckSigsFlag checkSigs = CheckSigs,
967 SubstituteFlag substitute = NoSubstitute);
969kj::Promise<Result<std::map<StorePath, StorePath>>> copyPaths(
970 Store & srcStore, Store & dstStore,
971 const StorePathSet & paths,
972 RepairFlag repair = NoRepair,
973 CheckSigsFlag checkSigs = CheckSigs,
974 SubstituteFlag substitute = NoSubstitute);
979kj::Promise<Result<void>> copyClosure(
980 Store & srcStore, Store & dstStore,
981 const RealisedPath::Set & paths,
982 RepairFlag repair = NoRepair,
983 CheckSigsFlag checkSigs = CheckSigs,
984 SubstituteFlag substitute = NoSubstitute);
986kj::Promise<Result<void>> copyClosure(
987 Store & srcStore, Store & dstStore,
988 const StorePathSet & paths,
989 RepairFlag repair = NoRepair,
990 CheckSigsFlag checkSigs = CheckSigs,
991 SubstituteFlag substitute = NoSubstitute);
1005kj::Promise<Result<StorePath>>
1007kj::Promise<Result<OutputPathMap>>
1042kj::Promise<Result<ref<Store>>> openStore(
const std::string & uri = settings.storeUri.get(),
1043 const StoreConfig::Params & extraParams = {});
1050kj::Promise<Result<std::list<ref<Store>>>> getDefaultSubstituters();
1054 std::set<std::string> uriSchemes;
1056 std::shared_ptr<Store> (
1057 const std::string & scheme,
1058 const std::string & uri,
1059 const StoreConfig::Params & params
1062 std::function<std::shared_ptr<StoreConfig> ()> getConfig;
1067 static std::vector<StoreFactory> * registered;
1069 template<
typename T,
typename TConfig>
1072 if (!registered) registered =
new std::vector<StoreFactory>();
1074 .uriSchemes = T::uriSchemes(),
1076 ([](
const std::string & scheme,
const std::string & uri,
const StoreConfig::Params & params)
1077 -> std::shared_ptr<Store>
1078 {
return std::make_shared<T>(scheme, uri, params); }),
1081 -> std::shared_ptr<StoreConfig>
1082 {
return std::make_shared<TConfig>(StringMap({})); })
1084 registered->push_back(factory);
1093std::string showPaths(
const PathSet & paths);
1096std::optional<ValidPathInfo> decodeValidPathInfo(
1097 const Store & store,
1099 std::optional<HashResult> hashGiven = std::nullopt);
1104std::pair<std::string, StoreConfig::Params> splitUriAndParams(
const std::string & uri);
1108kj::Promise<Result<std::map<DrvOutput, StorePath>>> drvOutputReferences(
1112 Store * evalStore =
nullptr);
Definition fs-accessor.hh:15
Definition lru-cache.hh:16
Definition nar-info-disk-cache.hh:11
Definition store-api.hh:195
virtual kj::Promise< Result< StorePathSet > > queryValidDerivers(const StorePath &path)
Definition store-api.hh:451
virtual kj::Promise< Result< StorePathSet > > querySubstitutablePaths(const StorePathSet &paths)
Definition store-api.hh:497
virtual kj::Promise< Result< std::map< std::string, std::optional< StorePath > > > > queryPartialDerivationOutputMap(const StorePath &path, Store *evalStore=nullptr)
Definition store-api.cc:532
kj::Promise< Result< ref< const ValidPathInfo > > > queryPathInfo(const StorePath &path)
Definition store-api.cc:708
virtual kj::Promise< Result< void > > buildPaths(const std::vector< DerivedPath > &paths, BuildMode buildMode=bmNormal, std::shared_ptr< Store > evalStore=nullptr)
Definition entry-points.cc:11
kj::Promise< Result< StorePathSet > > exportReferences(const StorePathSet &storePaths, const StorePathSet &inputPaths)
Definition store-api.cc:918
StorePath makeStorePath(std::string_view type, std::string_view hash, std::string_view name) const
Definition store-api.cc:161
virtual kj::Promise< Result< void > > queryMissing(const std::vector< DerivedPath > &targets, StorePathSet &willBuild, StorePathSet &willSubstitute, StorePathSet &unknown, uint64_t &downloadSize, uint64_t &narSize)
Definition misc.cc:358
virtual kj::Promise< Result< bool > > verifyStore(bool checkContents, RepairFlag repair=NoRepair)
Definition store-api.hh:744
kj::Promise< Result< std::optional< StorePath > > > getBuildDerivationPath(const StorePath &)
Definition store-api.cc:1440
virtual kj::Promise< Result< StorePath > > addToStoreRecursive(std::string_view name, const PreparedDump &source, HashType hashAlgo=HashType::SHA256, RepairFlag repair=NoRepair)
Definition store-api.cc:283
kj::Promise< Result< Derivation > > readDerivation(const StorePath &drvPath)
Definition store-api.cc:1469
virtual kj::Promise< Result< void > > ensurePath(const StorePath &path)
Definition entry-points.cc:110
kj::Promise< Result< std::shared_ptr< const Realisation > > > queryRealisation(const DrvOutput &)
Definition store-api.cc:762
virtual kj::Promise< Result< void > > optimiseStore()
Definition store-api.hh:737
virtual kj::Promise< Result< void > > repairPath(const StorePath &path)
Definition entry-points.cc:136
StorePathSet parseStorePathSet(const PathSet &paths) const
Definition path.cc:95
StorePath followLinksToStorePath(std::string_view path) const
Definition store-api.cc:73
virtual kj::Promise< Result< void > > registerDrvOutput(const Realisation &output)
Definition store-api.hh:604
virtual kj::Promise< Result< void > > querySubstitutablePathInfos(const StorePathCAMap &paths, SubstitutablePathInfos &infos)
Definition store-api.cc:588
kj::Promise< Result< Derivation > > readInvalidDerivation(const StorePath &drvPath)
Definition store-api.cc:1472
kj::Promise< Result< Derivation > > derivationFromPath(const StorePath &drvPath)
Definition store-api.cc:1415
virtual kj::Promise< Result< StorePath > > addToStoreFromDump(AsyncInputStream &dump, std::string_view name, FileIngestionMethod method=FileIngestionMethod::Recursive, HashType hashAlgo=HashType::SHA256, RepairFlag repair=NoRepair, const StorePathSet &references=StorePathSet())
Definition store-api.hh:575
kj::Promise< Result< ValidPathInfo > > addToStoreSlow(std::string_view name, const Path &srcPath, FileIngestionMethod method=FileIngestionMethod::Recursive, HashType hashAlgo=HashType::SHA256, std::optional< Hash > expectedCAHash={})
Definition store-api.cc:408
kj::Promise< void > clearPathInfoCache()
Definition store-api.hh:873
kj::Promise< Result< JSON > > pathInfoToJSON(const StorePathSet &storePaths, bool includeImpureInfo, bool showClosureSize, Base hashBase=Base::Base32, AllowInvalidFlag allowInvalid=DisallowInvalid)
Definition store-api.cc:955
kj::Promise< Result< bool > > isValidPath(const StorePath &path)
Definition store-api.cc:645
virtual kj::Promise< Result< std::optional< StorePath > > > queryPathFromHashPart(const std::string &hashPart)=0
virtual kj::Promise< Result< unsigned int > > getProtocol()
Definition store-api.hh:887
virtual kj::Promise< Result< BuildResult > > buildDerivation(const StorePath &drvPath, const BasicDerivation &drv, BuildMode buildMode=bmNormal)
Definition entry-points.cc:74
virtual kj::Promise< Result< StorePathSet > > queryDerivationOutputs(const StorePath &path)
Definition store-api.cc:575
virtual kj::Promise< Result< StorePathSet > > queryValidPaths(const StorePathSet &paths, SubstituteFlag maybeSubstitute=NoSubstitute)
Definition store-api.cc:823
kj::Promise< Result< StorePaths > > topoSortPaths(const StorePathSet &paths)
Definition misc.cc:376
Path followLinksToStore(std::string_view path) const
Definition store-api.cc:59
virtual kj::Promise< Result< std::optional< TrustedFlag > > > isTrustedClient()=0
virtual kj::Promise< Result< void > > setOptions()
Definition store-api.hh:917
kj::Promise< Result< OutputPathMap > > queryDerivationOutputMap(const StorePath &path, Store *evalStore=nullptr)
Definition store-api.cc:561
virtual kj::Promise< Result< std::shared_ptr< const ValidPathInfo > > > queryPathInfoUncached(const StorePath &path)=0
virtual ref< FSAccessor > getFSAccessor()=0
virtual kj::Promise< Result< void > > addTempRoot(const StorePath &path)
Definition store-api.hh:695
virtual kj::Promise< Result< void > > connect()
Definition store-api.hh:882
kj::Promise< Result< void > > substitutePaths(const StorePathSet &paths)
Definition store-api.cc:796
kj::Promise< Result< std::pair< uint64_t, uint64_t > > > getClosureSize(const StorePath &storePath)
Definition store-api.cc:1032
kj::Promise< Result< StorePaths > > importPaths(Source &source, CheckSigsFlag checkSigs=CheckSigs)
Definition export-import.cc:59
bool isInStore(PathView path) const
Definition store-api.cc:41
StorePath computeStorePathForText(std::string_view name, std::string_view s, const StorePathSet &references) const
Definition store-api.cc:271
virtual kj::Promise< Result< StorePath > > addTextToStore(std::string_view name, std::string_view s, const StorePathSet &references, RepairFlag repair=NoRepair)=0
virtual kj::Promise< Result< void > > addToStore(const ValidPathInfo &info, AsyncInputStream &narSource, RepairFlag repair=NoRepair, CheckSigsFlag checkSigs=CheckSigs)=0
std::string showPaths(const StorePathSet &paths)
Definition store-api.cc:1398
virtual kj::Promise< Result< void > > addMultipleToStore(PathsSource &pathsToCopy, Activity &act, RepairFlag repair=NoRepair, CheckSigsFlag checkSigs=CheckSigs)
Definition store-api.cc:312
virtual kj::Promise< Result< std::vector< KeyedBuildResult > > > buildPathsWithResults(const std::vector< DerivedPath > &paths, BuildMode buildMode=bmNormal, std::shared_ptr< Store > evalStore=nullptr)
Definition entry-points.cc:50
virtual kj::Promise< Result< void > > addSignatures(const StorePath &storePath, const StringSet &sigs)
Definition store-api.hh:765
kj::Promise< Result< std::string > > makeValidityRegistration(const StorePathSet &paths, bool showDerivers, bool showHash)
Definition store-api.cc:887
virtual kj::Promise< Result< std::map< std::string, std::optional< StorePath > > > > queryStaticPartialDerivationOutputMap(const StorePath &path)
Definition store-api.cc:519
virtual kj::Promise< Result< void > > init()
Definition store-api.hh:241
void unsupported(const std::string &op)
Definition store-api.hh:935
bool isStorePath(std::string_view path) const
Definition path.cc:90
kj::Promise< Result< void > > exportPaths(const StorePathSet &paths, Sink &sink)
Definition export-import.cc:12
virtual kj::Promise< Result< void > > computeFSClosure(const StorePathSet &paths, StorePathSet &out, bool flipDirection=false, bool includeOutputs=false, bool includeDerivers=false)
Definition misc.cc:17
std::vector< std::pair< ValidPathInfo, std::function< kj::Promise< Result< box_ptr< AsyncInputStream > > >()> > > PathsSource
Definition store-api.hh:526
virtual bool pathInfoIsUntrusted(const ValidPathInfo &)
Definition store-api.hh:412
virtual kj::Promise< Result< StorePathSet > > queryAllValidPaths()
Definition store-api.hh:384
StorePath computeStorePathForPathRecursive(std::string_view name, const PreparedDump &source) const
Definition store-api.cc:249
std::pair< StorePath, Path > toStorePath(PathView path) const
Definition store-api.cc:47
virtual kj::Promise< Result< box_ptr< Source > > > narFromPath(const StorePath &path)=0
virtual kj::Promise< Result< void > > queryReferrers(const StorePath &path, StorePathSet &referrers)
Definition store-api.hh:440
Lock lock()
Definition sync.hh:154
FileIngestionMethod
Definition content-address.hh:38
const uint32_t exportMagic
Definition store-api.hh:103
Definition logging.hh:185
Definition derivations.hh:274
Definition build-result.hh:17
Definition content-address.hh:126
Definition derivations.hh:324
Definition derived-path.hh:170
Definition realisation.hh:24
Definition build-result.hh:135
Definition realisation.hh:49
Definition derived-path.hh:101
Definition store-api.hh:122
virtual const std::string name()=0
virtual std::string doc()
Definition store-api.hh:141
virtual std::optional< ExperimentalFeature > experimentalFeature() const
Definition store-api.hh:150
Definition store-api.hh:1053
Definition store-api.hh:1066
Definition store-api.hh:198
std::shared_ptr< const ValidPathInfo > value
Definition store-api.hh:208
bool didExist()
Definition store-api.hh:220
bool isKnownNow()
Definition store-api.cc:509
std::chrono::time_point< std::chrono::steady_clock > time_point
Definition store-api.hh:203
Definition store-api.hh:226
Definition store-api.hh:837
Definition path-info.hh:83
Definition json-fwd.hh:21
std::string Path
Definition types.hh:28