Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Loading...
Searching...
No Matches
nix::BinaryCacheStore Struct Referenceabstract

#include <binary-cache-store.hh>

Inheritance diagram for nix::BinaryCacheStore:
nix::Store nix::LogStore nix::StoreDirConfig nix::Store nix::StoreDirConfig nix::HttpBinaryCacheStore nix::LocalBinaryCacheStore nix::S3BinaryCacheStore nix::testing::TestHttpBinaryCacheStore

Public Types

using Config = BinaryCacheStoreConfig
Public Types inherited from nix::Store
using Config = StoreConfig
using PathsSource = std::vector<std::pair<ValidPathInfo, std::unique_ptr<Source>>>

Public Member Functions

virtual bool fileExists (const std::string &path)=0
virtual void upsertFile (const std::string &path, RestartableSource &source, const std::string &mimeType, uint64_t sizeHint)=0
void upsertFile (const std::string &path, std::string &&data, const std::string &mimeType, uint64_t sizeHint)
void upsertFile (const std::string &path, std::string &&data, const std::string &mimeType)
virtual void getFile (const std::string &path, Sink &sink)
virtual std::optional< std::string > getNixCacheInfo ()
virtual void getFile (const std::string &path, Callback< std::optional< std::string > > callback) noexcept
std::optional< std::string > getFile (const std::string &path)
virtual void init () override
bool isValidPathUncached (const StorePath &path) override
void queryPathInfoUncached (const StorePath &path, Callback< std::shared_ptr< const ValidPathInfo > > callback) noexcept override
std::optional< StorePath > queryPathFromHashPart (const std::string &hashPart) override
void addToStore (const ValidPathInfo &info, Source &narSource, RepairFlag repair, CheckSigsFlag checkSigs) override
void addMultipleToStore (PathsSource &&pathsToCopy, Activity &act, RepairFlag repair, CheckSigsFlag checkSigs) override
StorePath addToStoreFromDump (Source &dump, std::string_view name, FileSerialisationMethod dumpMethod, ContentAddressMethod hashMethod, HashAlgorithm hashAlgo, const StorePathSet &references, RepairFlag repair) override
StorePath addToStore (std::string_view name, const SourcePath &path, ContentAddressMethod method, HashAlgorithm hashAlgo, const StorePathSet &references, PathFilter &filter, RepairFlag repair) override
void registerDrvOutputUnchecked (const Realisation &info) override
void queryRealisationUncached (const DrvOutput &, Callback< std::shared_ptr< const UnkeyedRealisation > > callback) noexcept override
void narFromPath (const StorePath &path, Sink &sink) override
ref< SourceAccessor > getFSAccessor (bool requireValidPath=true) override
std::shared_ptr< SourceAccessor > getFSAccessor (const StorePath &, bool requireValidPath=true) override
void addSignatures (const StorePath &storePath, const std::set< Signature > &sigs) override
std::optional< std::string > getBuildLogExact (const StorePath &path) override
void addBuildLog (const StorePath &drvPath, std::string_view log) override
Public Member Functions inherited from nix::Store
 operator const Config & () const
virtual ref< Builder > getBuilder (std::shared_ptr< Store > evalStore=nullptr)
std::filesystem::path followLinksToStore (std::string_view path) const
StorePath followLinksToStorePath (std::string_view path) const
bool isValidPath (const StorePath &path)
void substitutePaths (const StorePathSet &paths)
virtual StorePathSet queryValidPaths (const StorePathSet &paths, SubstituteFlag maybeSubstitute=NoSubstitute)
virtual StorePathSet queryAllValidPaths ()
ref< const ValidPathInfo > queryPathInfo (const StorePath &path)
void queryPathInfo (const StorePath &path, Callback< ref< const ValidPathInfo > > callback) noexcept
std::optional< std::shared_ptr< const ValidPathInfo > > queryPathInfoFromClientCache (const StorePath &path)
std::shared_ptr< const UnkeyedRealisation > queryRealisation (const DrvOutput &)
void queryRealisation (const DrvOutput &, Callback< std::shared_ptr< const UnkeyedRealisation > > callback) noexcept
virtual bool pathInfoIsUntrusted (const ValidPathInfo &)
virtual bool realisationIsUntrusted (const Realisation &)
virtual void queryReferrers (const StorePath &path, StorePathSet &referrers)
virtual StorePathSet queryValidDerivers (const StorePath &path)
virtual StorePathSet queryDerivationOutputs (const StorePath &path)
virtual std::map< std::string, std::optional< StorePath > > queryPartialDerivationOutputMap (const StorePath &path, Store *evalStore=nullptr)
virtual std::map< std::string, std::optional< StorePath > > queryStaticPartialDerivationOutputMap (const StorePath &path)
virtual std::optional< StorePath > queryStaticPartialDerivationOutput (const StorePath &path, const std::string &outputName)
OutputPathMap queryDerivationOutputMap (const StorePath &path, Store *evalStore=nullptr)
virtual StorePathSet querySubstitutablePaths (const StorePathSet &paths)
virtual void querySubstitutablePathInfos (const StorePathCAMap &paths, SubstitutablePathInfos &infos)
ValidPathInfo addToStoreSlow (std::string_view name, const SourcePath &path, ContentAddressMethod method=ContentAddressMethod::Raw::NixArchive, HashAlgorithm hashAlgo=HashAlgorithm::SHA256, const StorePathSet &references=StorePathSet(), std::optional< Hash > expectedCAHash={})
virtual void registerDrvOutput (const Realisation &output, CheckSigsFlag checkSigs)
virtual void addTempRoot (const StorePath &path)
virtual void addTempRoots (const StorePathSet &paths)
std::string makeValidityRegistration (const StorePathSet &paths, bool showDerivers, bool showHash)
virtual void optimiseStore ()
virtual bool verifyStore (bool checkContents, RepairFlag repair=NoRepair)
ref< SourceAccessor > requireStoreObjectAccessor (const StorePath &path, bool requireValidPath=true)
void signPathInfo (ValidPathInfo &info)
void signRealisation (Realisation &)
Derivation derivationFromPath (const StorePath &drvPath)
virtual StorePath writeDerivation (const Derivation &drv, RepairFlag repair=NoRepair)
virtual Derivation readDerivation (const StorePath &drvPath)
virtual Derivation readInvalidDerivation (const StorePath &drvPath)
virtual void computeFSClosure (const StorePathSet &paths, StorePathSet &out, bool flipDirection=false, bool includeOutputs=false, bool includeDerivers=false)
void computeFSClosure (const StorePath &path, StorePathSet &out, bool flipDirection=false, bool includeOutputs=false, bool includeDerivers=false)
virtual MissingPaths queryMissing (const std::vector< DerivedPath > &targets)
virtual StorePaths topoSortPaths (const StorePathSet &paths)
StorePathSet exportReferences (const StorePathSet &storePaths, const StorePathSet &inputPaths)
std::optional< StorePath > getBuildDerivationPath (const StorePath &)
void clearPathInfoCache ()
virtual void connect ()
virtual unsigned int getProtocol ()
virtual std::optional< TrustedFlag > isTrustedClient ()=0
virtual void setOptions ()
virtual std::optional< std::string > getVersion ()
Public Member Functions inherited from nix::StoreDirConfig
StorePath parseStorePath (std::string_view path) const
StorePath parseStorePathCanonical (std::string_view path) const
std::optional< StorePath > maybeParseStorePath (std::string_view path) const
std::string printStorePath (const StorePath &path) const
StringSet printStorePathSet (const StorePathSet &path) const
std::size_t maxCanonicalStorePathLen () const noexcept
bool isInStore (std::string_view path) const
bool isStorePath (std::string_view path) const
std::pair< StorePath, CanonPath > toStorePath (std::string_view path) const
StorePath makeStorePath (std::string_view type, std::string_view hash, std::string_view name) const
StorePath makeStorePath (std::string_view type, const Hash &hash, std::string_view name) const
StorePath makeOutputPath (std::string_view id, const Hash &hash, std::string_view name) const
StorePath makeFixedOutputPath (std::string_view name, const FixedOutputInfo &info) const
StorePath makeFixedOutputPathFromCA (std::string_view name, const ContentAddressWithReferences &ca) const
std::pair< StorePath, Hash > computeStorePath (std::string_view name, const SourcePath &path, ContentAddressMethod method=ContentAddressMethod::Raw::NixArchive, HashAlgorithm hashAlgo=HashAlgorithm::SHA256, const StorePathSet &references={}, PathFilter &filter=defaultPathFilter) const
Public Member Functions inherited from nix::LogStore
std::optional< std::string > getBuildLog (const StorePath &path)

Public Attributes

Config & config
Public Attributes inherited from nix::Store
const Config & config
Public Attributes inherited from nix::StoreDirConfig
const std::string & storeDir

Protected Member Functions

 BinaryCacheStore (Config &)
std::string makeRealisationPath (const DrvOutput &id)
Protected Member Functions inherited from nix::Store
void invalidatePathInfoCacheFor (const StorePath &path)
 Store (const Store::Config &config)
void unsupported (const std::string &op)

Static Protected Attributes

static constexpr const std::string realisationsPrefix = "build-trace-v2"
static constexpr const std::string cacheInfoFile = "nix-cache-info"

Additional Inherited Members

Static Public Attributes inherited from nix::Store
static constexpr const char * MissingName = "x"
Static Public Attributes inherited from nix::LogStore
static std::string operationName = "Build log storage and retrieval"
Protected Attributes inherited from nix::Store
std::shared_ptr< SharedSync< LRUCache< StorePath, PathInfoCacheValue > > > pathInfoCache
std::shared_ptr< NarInfoDiskCache > diskCache

Detailed Description

Note
subclasses must implement at least one of the two virtual getFile() methods.

Member Function Documentation

◆ addBuildLog()

void nix::BinaryCacheStore::addBuildLog ( const StorePath & drvPath,
std::string_view log )
overridevirtual

Implements nix::LogStore.

◆ addMultipleToStore()

void nix::BinaryCacheStore::addMultipleToStore ( PathsSource && pathsToCopy,
Activity & act,
RepairFlag repair,
CheckSigsFlag checkSigs )
overridevirtual

Import multiple paths into the store.

Reimplemented from nix::Store.

◆ addSignatures()

void nix::BinaryCacheStore::addSignatures ( const StorePath & storePath,
const std::set< Signature > & sigs )
overridevirtual

Add signatures to the specified store path. The signatures are not verified.

Reimplemented from nix::Store.

◆ addToStore() [1/2]

void nix::BinaryCacheStore::addToStore ( const ValidPathInfo & info,
Source & narSource,
RepairFlag repair,
CheckSigsFlag checkSigs )
overridevirtual

Import a path into the store. Note that the entire NAR may not be read from narSource, e.g. if the path is already valid.

Implements nix::Store.

◆ addToStore() [2/2]

StorePath nix::BinaryCacheStore::addToStore ( std::string_view name,
const SourcePath & path,
ContentAddressMethod method,
HashAlgorithm hashAlgo,
const StorePathSet & references,
PathFilter & filter,
RepairFlag repair )
overridevirtual

Copy the contents of a path to the store and register the validity the resulting path.

Returns
The resulting path is returned.
Parameters
filterThis function can be used to exclude files (see libutil/archive.hh).

Reimplemented from nix::Store.

◆ addToStoreFromDump()

StorePath nix::BinaryCacheStore::addToStoreFromDump ( Source & dump,
std::string_view name,
FileSerialisationMethod dumpMethod,
ContentAddressMethod hashMethod,
HashAlgorithm hashAlgo,
const StorePathSet & references,
RepairFlag repair )
overridevirtual

Like addToStore(), but the contents of the path are contained in dump, which is either a NAR serialisation (if recursive == true) or simply the contents of a regular file (if recursive == false).

dump may be drained.

Parameters
dumpMethodWhat serialisation format is dump, i.e. how to deserialize it. Must either match hashMethod or be FileSerialisationMethod::NixArchive.
hashMethodHow content addressing? Need not match be the same as dumpMethod.
Todo
remove?

Implements nix::Store.

◆ getBuildLogExact()

std::optional< std::string > nix::BinaryCacheStore::getBuildLogExact ( const StorePath & path)
overridevirtual

Implements nix::LogStore.

◆ getFile() [1/2]

void nix::BinaryCacheStore::getFile ( const std::string & path,
Callback< std::optional< std::string > > callback )
virtualnoexcept

Fetch the specified file and call the specified callback with the result. A subclass may implement this asynchronously.

Reimplemented in nix::HttpBinaryCacheStore.

◆ getFile() [2/2]

void nix::BinaryCacheStore::getFile ( const std::string & path,
Sink & sink )
virtual

Dump the contents of the specified file to a sink.

Reimplemented in nix::HttpBinaryCacheStore, and nix::LocalBinaryCacheStore.

◆ getFSAccessor() [1/2]

ref< SourceAccessor > nix::BinaryCacheStore::getFSAccessor ( bool requireValidPath = true)
overridevirtual
Returns
An object to access files in the Nix store, across all store objects.

Implements nix::Store.

◆ getFSAccessor() [2/2]

std::shared_ptr< SourceAccessor > nix::BinaryCacheStore::getFSAccessor ( const StorePath & path,
bool requireValidPath = true )
overridevirtual
Returns
An object to access files for a specific store object in the Nix store.
nullptr if the store doesn't contain an object at the given path.

Implements nix::Store.

◆ getNixCacheInfo()

std::optional< std::string > nix::BinaryCacheStore::getNixCacheInfo ( )
virtual

Get the contents of /nix-cache-info. Return std::nullopt if it doesn't exist.

Reimplemented in nix::HttpBinaryCacheStore.

◆ init()

void nix::BinaryCacheStore::init ( )
overridevirtual

Perform any necessary effectful operation to make the store up and running

Reimplemented from nix::Store.

Reimplemented in nix::HttpBinaryCacheStore, nix::LocalBinaryCacheStore, and nix::testing::TestHttpBinaryCacheStore.

◆ isValidPathUncached()

bool nix::BinaryCacheStore::isValidPathUncached ( const StorePath & path)
overridevirtual

Reimplemented from nix::Store.

◆ makeRealisationPath()

std::string nix::BinaryCacheStore::makeRealisationPath ( const DrvOutput & id)
protected

Compute the path to the given realisation

It's ${realisationsPrefix}/${drvPath}/${outputName}.

◆ narFromPath()

void nix::BinaryCacheStore::narFromPath ( const StorePath & path,
Sink & sink )
overridevirtual

Write a NAR dump of a store path.

Reimplemented from nix::Store.

◆ queryPathFromHashPart()

std::optional< StorePath > nix::BinaryCacheStore::queryPathFromHashPart ( const std::string & hashPart)
overridevirtual

Query the full store path given the hash part of a valid store path, or empty if the path doesn't exist.

Implements nix::Store.

◆ queryPathInfoUncached()

void nix::BinaryCacheStore::queryPathInfoUncached ( const StorePath & path,
Callback< std::shared_ptr< const ValidPathInfo > > callback )
overridevirtualnoexcept

Implements nix::Store.

◆ queryRealisationUncached()

void nix::BinaryCacheStore::queryRealisationUncached ( const DrvOutput & id,
Callback< std::shared_ptr< const UnkeyedRealisation > > callback )
overridevirtualnoexcept

Implements nix::Store.

◆ registerDrvOutputUnchecked()

void nix::BinaryCacheStore::registerDrvOutputUnchecked ( const Realisation & output)
overridevirtual

Add a mapping indicating that deriver!outputName maps to the output path output.

This is redundant for known-input-addressed and fixed-output derivations as this information is already present in the drv file, but necessary for floating-ca derivations and their dependencies as there's no way to retrieve this information otherwise.

The method that does not perform signature checks is internal only, users should explicitly set the checkSigs argument to NoCheckSigs.

Implements nix::Store.

Member Data Documentation

◆ config

Config& nix::BinaryCacheStore::config

Intentionally mutable because some things we update due to the cache's own (remote side) settings.

◆ realisationsPrefix

const std::string nix::BinaryCacheStore::realisationsPrefix = "build-trace-v2"
staticconstexprprotected

The prefix under which realisation infos will be stored

Note
The previous (still experimental, though) hash-keyed realisations were under "realisations". "build trace" is a better name anyways (issue #11895). This is call "v2" accordingly.

While we're experimenting, we'll freely increase this version number. Old build traces will just be "abandoned" at the old URL. When we are done experimenting, we'll try lean more on versioning the build trace entries themselves than the entire directory, for a smoother migration path.


The documentation for this struct was generated from the following files: