2012-07-18 21:59:03 +03:00
|
|
|
|
#pragma once
|
2023-04-01 06:18:41 +03:00
|
|
|
|
///@file
|
2006-11-30 19:43:04 +02:00
|
|
|
|
|
2019-12-05 20:11:09 +02:00
|
|
|
|
#include "path.hh"
|
2021-04-05 17:33:28 +03:00
|
|
|
|
#include "derived-path.hh"
|
2010-10-04 20:55:38 +03:00
|
|
|
|
#include "hash.hh"
|
2020-06-02 22:44:58 +03:00
|
|
|
|
#include "content-address.hh"
|
2010-10-04 20:55:38 +03:00
|
|
|
|
#include "serialise.hh"
|
2016-04-19 19:50:15 +03:00
|
|
|
|
#include "lru-cache.hh"
|
|
|
|
|
#include "sync.hh"
|
2016-09-02 13:39:29 +03:00
|
|
|
|
#include "globals.hh"
|
2017-04-13 16:55:38 +03:00
|
|
|
|
#include "config.hh"
|
2020-06-25 00:22:13 +03:00
|
|
|
|
#include "path-info.hh"
|
2022-03-18 00:29:15 +02:00
|
|
|
|
#include "repair-flag.hh"
|
2023-01-07 01:06:03 +02:00
|
|
|
|
#include "store-dir-config.hh"
|
2024-01-23 21:23:03 +02:00
|
|
|
|
#include "store-reference.hh"
|
2023-12-18 23:14:42 +02:00
|
|
|
|
#include "source-path.hh"
|
2010-10-04 20:55:38 +03:00
|
|
|
|
|
2022-11-16 17:49:49 +02:00
|
|
|
|
#include <nlohmann/json_fwd.hpp>
|
2016-04-19 19:50:15 +03:00
|
|
|
|
#include <atomic>
|
2006-12-05 03:31:45 +02:00
|
|
|
|
#include <map>
|
2014-03-30 01:49:23 +02:00
|
|
|
|
#include <memory>
|
2016-04-19 19:50:15 +03:00
|
|
|
|
#include <string>
|
2020-03-11 21:04:47 +02:00
|
|
|
|
#include <chrono>
|
2006-11-30 19:43:04 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
|
2020-09-14 12:18:45 +03:00
|
|
|
|
/**
|
2023-12-01 00:07:09 +02:00
|
|
|
|
* About the class hierarchy of the store types:
|
2020-09-14 12:18:45 +03:00
|
|
|
|
*
|
|
|
|
|
* Each store type `Foo` consists of two classes:
|
|
|
|
|
*
|
|
|
|
|
* 1. A class `FooConfig : virtual StoreConfig` that contains the configuration
|
|
|
|
|
* for the store
|
|
|
|
|
*
|
|
|
|
|
* It should only contain members of type `const Setting<T>` (or subclasses
|
|
|
|
|
* of it) and inherit the constructors of `StoreConfig`
|
|
|
|
|
* (`using StoreConfig::StoreConfig`).
|
|
|
|
|
*
|
|
|
|
|
* 2. A class `Foo : virtual Store, virtual FooConfig` that contains the
|
|
|
|
|
* implementation of the store.
|
|
|
|
|
*
|
|
|
|
|
* This class is expected to have a constructor `Foo(const Params & params)`
|
|
|
|
|
* that calls `StoreConfig(params)` (otherwise you're gonna encounter an
|
|
|
|
|
* `assertion failure` when trying to instantiate it).
|
|
|
|
|
*
|
|
|
|
|
* You can then register the new store using:
|
|
|
|
|
*
|
|
|
|
|
* ```
|
|
|
|
|
* cpp static RegisterStoreImplementation<Foo, FooConfig> regStore;
|
|
|
|
|
* ```
|
|
|
|
|
*/
|
2006-11-30 19:43:04 +02:00
|
|
|
|
|
2019-11-10 18:14:26 +02:00
|
|
|
|
MakeError(SubstError, Error);
|
2023-03-26 01:12:44 +02:00
|
|
|
|
/**
|
|
|
|
|
* denotes a permanent build failure
|
|
|
|
|
*/
|
|
|
|
|
MakeError(BuildError, Error);
|
2019-11-10 18:14:26 +02:00
|
|
|
|
MakeError(InvalidPath, Error);
|
|
|
|
|
MakeError(Unsupported, Error);
|
|
|
|
|
MakeError(SubstituteGone, Error);
|
|
|
|
|
MakeError(SubstituterDisabled, Error);
|
2017-05-01 14:43:34 +03:00
|
|
|
|
|
2024-01-23 21:23:03 +02:00
|
|
|
|
MakeError(InvalidStoreReference, Error);
|
2017-05-01 14:43:34 +03:00
|
|
|
|
|
2022-03-18 17:35:45 +02:00
|
|
|
|
struct Realisation;
|
|
|
|
|
struct RealisedPath;
|
|
|
|
|
struct DrvOutput;
|
|
|
|
|
|
2022-03-18 00:29:15 +02:00
|
|
|
|
struct BasicDerivation;
|
|
|
|
|
struct Derivation;
|
2022-03-18 17:35:45 +02:00
|
|
|
|
|
2023-11-01 18:09:28 +02:00
|
|
|
|
struct SourceAccessor;
|
2016-08-03 14:17:11 +03:00
|
|
|
|
class NarInfoDiskCache;
|
|
|
|
|
class Store;
|
|
|
|
|
|
|
|
|
|
|
2023-01-12 01:57:18 +02:00
|
|
|
|
typedef std::map<std::string, StorePath> OutputPathMap;
|
|
|
|
|
|
|
|
|
|
|
2017-06-28 19:11:01 +03:00
|
|
|
|
enum CheckSigsFlag : bool { NoCheckSigs = false, CheckSigs = true };
|
|
|
|
|
enum SubstituteFlag : bool { NoSubstitute = false, Substitute = true };
|
|
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
|
/**
|
|
|
|
|
* Magic header of exportPath() output (obsolete).
|
|
|
|
|
*/
|
2016-02-15 15:48:38 +02:00
|
|
|
|
const uint32_t exportMagic = 0x4558494e;
|
|
|
|
|
|
|
|
|
|
|
2024-05-27 07:18:58 +03:00
|
|
|
|
enum BuildMode : uint8_t { bmNormal, bmRepair, bmCheck };
|
2022-12-26 22:21:08 +02:00
|
|
|
|
enum TrustedFlag : bool { NotTrusted = false, Trusted = true };
|
2014-02-18 02:01:14 +02:00
|
|
|
|
|
2022-03-01 21:43:07 +02:00
|
|
|
|
struct BuildResult;
|
Make `KeyedBuildResult`, `BuildResult` like before, and fix bug another way
In https://github.com/NixOS/nix/pull/6311#discussion_r834863823, I
realized since derivation goals' wanted outputs can "grow" due to
overlapping dependencies (See `DerivationGoal::addWantedOutputs`, called
by `Worker::makeDerivationGoalCommon`), the previous bug fix had an
unfortunate side effect of causing more pointless rebuilds.
In paticular, we have this situation:
1. Goal made from `DerivedPath::Built { foo, {a} }`.
2. Goal gives on on substituting, starts building.
3. Goal made from `DerivedPath::Built { foo, {b} }`, in fact is just
modified original goal.
4. Though the goal had gotten as far as building, so all outputs were
going to be produced, `addWantedOutputs` no longer knows that and so
the goal is flagged to be restarted.
This might sound far-fetched with input-addressed drvs, where we usually
basically have all our goals "planned out" before we start doing
anything, but with CA derivation goals and especially RFC 92, where *drv
resolution* means goals are created after some building is completed, it
is more likely to happen.
So the first thing to do was restore the clearing of `wantedOutputs` we
used to do, and then filter the outputs in `buildPathsWithResults` to
only get the ones we care about.
But fix also has its own side effect in that the `DerivedPath` in the
`BuildResult` in `DerivationGoal` cannot be trusted; it is merely the
*first* `DerivedPath` for which this goal was originally created.
To remedy this, I made `BuildResult` be like it was before, and instead
made `KeyedBuildResult` be a subclass wit the path. Only
`buildPathsWithResults` returns `KeyedBuildResult`s, everything else
just becomes like it was before, where the "key" is unambiguous from
context.
I think separating the "primary key" field(s) from the other fields is
good practical in general anyways. (I would like to do the same thing
for `ValidPathInfo`.) Among other things, it allows constructions like
`std::map<Key, ThingWithKey>` where doesn't contain duplicate keys and
just precludes the possibility of those duplicate keys being out of
sync.
We might leverage the above someday to overload `buildPathsWithResults`
to take a *set* of return a *map* per the above.
-----
Unfortunately, we need to avoid C++20 strictness on designated
initializers.
(BTW
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2287r1.html
this offers some new syntax for this use-case. Hopefully this will be
adopted and we can eventually use it.)
No having that yet, maybe it would be better to not make
`KeyedBuildResult` a subclass to just avoid this.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2022-03-25 03:26:07 +02:00
|
|
|
|
struct KeyedBuildResult;
|
2014-02-18 02:01:14 +02:00
|
|
|
|
|
Allow remote builds without sending the derivation closure
Previously, to build a derivation remotely, we had to copy the entire
closure of the .drv file to the remote machine, even though we only
need the top-level derivation. This is very wasteful: the closure can
contain thousands of store paths, and in some Hydra use cases, include
source paths that are very large (e.g. Git/Mercurial checkouts).
So now there is a new operation, StoreAPI::buildDerivation(), that
performs a build from an in-memory representation of a derivation
(BasicDerivation) rather than from a on-disk .drv file. The only files
that need to be in the Nix store are the sources of the derivation
(drv.inputSrcs), and the needed output paths of the dependencies (as
described by drv.inputDrvs). "nix-store --serve" exposes this
interface.
Note that this is a privileged operation, because you can construct a
derivation that builds any store path whatsoever. Fixing this will
require changing the hashing scheme (i.e., the output paths should be
computed from the other fields in BasicDerivation, allowing them to be
verified without access to other derivations). However, this would be
quite nice because it would allow .drv-free building (e.g. "nix-env
-i" wouldn't have to write any .drv files to disk).
Fixes #173.
2015-07-17 18:57:40 +03:00
|
|
|
|
|
2023-01-30 17:12:44 +02:00
|
|
|
|
typedef std::map<StorePath, std::optional<ContentAddress>> StorePathCAMap;
|
|
|
|
|
|
2023-01-07 01:06:03 +02:00
|
|
|
|
struct StoreConfig : public StoreDirConfig
|
2006-11-30 19:43:04 +02:00
|
|
|
|
{
|
2024-01-23 21:23:03 +02:00
|
|
|
|
using Params = StoreReference::Params;
|
2023-04-17 19:17:35 +03:00
|
|
|
|
|
2023-01-07 01:06:03 +02:00
|
|
|
|
using StoreDirConfig::StoreDirConfig;
|
2020-09-14 12:18:45 +03:00
|
|
|
|
|
2020-12-20 17:33:12 +02:00
|
|
|
|
StoreConfig() = delete;
|
2020-09-11 12:12:25 +03:00
|
|
|
|
|
2024-01-25 04:32:29 +02:00
|
|
|
|
static StringSet getDefaultSystemFeatures();
|
2021-06-11 09:37:59 +03:00
|
|
|
|
|
2020-10-06 15:00:42 +03:00
|
|
|
|
virtual ~StoreConfig() { }
|
|
|
|
|
|
2023-04-17 18:58:47 +03:00
|
|
|
|
/**
|
|
|
|
|
* The name of this type of store.
|
|
|
|
|
*/
|
2020-09-14 15:04:02 +03:00
|
|
|
|
virtual const std::string name() = 0;
|
2016-06-01 15:49:12 +03:00
|
|
|
|
|
2023-04-17 18:58:47 +03:00
|
|
|
|
/**
|
|
|
|
|
* Documentation for this type of store.
|
|
|
|
|
*/
|
2023-03-21 15:03:05 +02:00
|
|
|
|
virtual std::string doc()
|
|
|
|
|
{
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-17 18:58:47 +03:00
|
|
|
|
/**
|
|
|
|
|
* An experimental feature this type store is gated, if it is to be
|
|
|
|
|
* experimental.
|
|
|
|
|
*/
|
|
|
|
|
virtual std::optional<ExperimentalFeature> experimentalFeature() const
|
|
|
|
|
{
|
|
|
|
|
return std::nullopt;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-22 15:23:36 +02:00
|
|
|
|
const Setting<int> pathInfoCacheSize{this, 65536, "path-info-cache-size",
|
|
|
|
|
"Size of the in-memory store path metadata cache."};
|
2016-06-01 15:49:12 +03:00
|
|
|
|
|
2023-03-22 15:23:36 +02:00
|
|
|
|
const Setting<bool> isTrusted{this, false, "trusted",
|
|
|
|
|
R"(
|
|
|
|
|
Whether paths from this store can be used as substitutes
|
|
|
|
|
even if they are not signed by a key listed in the
|
|
|
|
|
[`trusted-public-keys`](@docroot@/command-ref/conf-file.md#conf-trusted-public-keys)
|
|
|
|
|
setting.
|
|
|
|
|
)"};
|
2018-02-05 19:08:30 +02:00
|
|
|
|
|
2023-03-22 15:23:36 +02:00
|
|
|
|
Setting<int> priority{this, 0, "priority",
|
|
|
|
|
R"(
|
2023-07-17 12:28:12 +03:00
|
|
|
|
Priority of this store when used as a [substituter](@docroot@/command-ref/conf-file.md#conf-substituters).
|
|
|
|
|
A lower value means a higher priority.
|
2023-03-22 15:23:36 +02:00
|
|
|
|
)"};
|
2019-12-17 18:17:53 +02:00
|
|
|
|
|
2023-03-22 15:23:36 +02:00
|
|
|
|
Setting<bool> wantMassQuery{this, false, "want-mass-query",
|
|
|
|
|
R"(
|
2023-07-17 12:28:12 +03:00
|
|
|
|
Whether this store can be queried efficiently for path validity when used as a [substituter](@docroot@/command-ref/conf-file.md#conf-substituters).
|
2023-03-22 15:23:36 +02:00
|
|
|
|
)"};
|
2019-12-17 18:17:53 +02:00
|
|
|
|
|
2021-06-11 09:37:59 +03:00
|
|
|
|
Setting<StringSet> systemFeatures{this, getDefaultSystemFeatures(),
|
2020-08-12 19:32:36 +03:00
|
|
|
|
"system-features",
|
2023-07-17 12:28:12 +03:00
|
|
|
|
R"(
|
|
|
|
|
Optional [system features](@docroot@/command-ref/conf-file.md#conf-system-features) available on the system this store uses to build derivations.
|
2020-08-12 19:32:36 +03:00
|
|
|
|
|
2023-07-17 12:28:12 +03:00
|
|
|
|
Example: `"kvm"`
|
2023-11-24 18:17:35 +02:00
|
|
|
|
)",
|
|
|
|
|
{},
|
|
|
|
|
// Don't document the machine-specific default value
|
|
|
|
|
false};
|
2020-09-10 11:55:51 +03:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class Store : public std::enable_shared_from_this<Store>, public virtual StoreConfig
|
|
|
|
|
{
|
2016-04-19 19:50:15 +03:00
|
|
|
|
protected:
|
|
|
|
|
|
2020-03-11 21:04:47 +02:00
|
|
|
|
struct PathInfoCacheValue {
|
|
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
|
/**
|
|
|
|
|
* Time of cache entry creation or update
|
|
|
|
|
*/
|
2020-03-11 21:04:47 +02:00
|
|
|
|
std::chrono::time_point<std::chrono::steady_clock> time_point = std::chrono::steady_clock::now();
|
|
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
|
/**
|
|
|
|
|
* Null if missing
|
|
|
|
|
*/
|
2020-03-11 21:04:47 +02:00
|
|
|
|
std::shared_ptr<const ValidPathInfo> value;
|
|
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
|
/**
|
|
|
|
|
* Whether the value is valid as a cache entry. The path may not
|
|
|
|
|
* exist.
|
|
|
|
|
*/
|
2020-03-11 21:04:47 +02:00
|
|
|
|
bool isKnownNow();
|
|
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
|
/**
|
|
|
|
|
* Past tense, because a path can only be assumed to exists when
|
|
|
|
|
* isKnownNow() && didExist()
|
|
|
|
|
*/
|
2020-03-11 21:04:47 +02:00
|
|
|
|
inline bool didExist() {
|
|
|
|
|
return value != nullptr;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2016-04-19 19:50:15 +03:00
|
|
|
|
struct State
|
|
|
|
|
{
|
2020-03-11 21:04:47 +02:00
|
|
|
|
LRUCache<std::string, PathInfoCacheValue> pathInfoCache;
|
2016-04-19 19:50:15 +03:00
|
|
|
|
};
|
|
|
|
|
|
2024-07-26 17:14:03 +03:00
|
|
|
|
SharedSync<State> state;
|
2016-04-19 19:50:15 +03:00
|
|
|
|
|
2016-04-20 15:12:38 +03:00
|
|
|
|
std::shared_ptr<NarInfoDiskCache> diskCache;
|
|
|
|
|
|
2016-06-01 15:49:12 +03:00
|
|
|
|
Store(const Params & params);
|
|
|
|
|
|
2006-11-30 19:43:04 +02:00
|
|
|
|
public:
|
2020-09-09 12:29:17 +03:00
|
|
|
|
/**
|
|
|
|
|
* Perform any necessary effectful operation to make the store up and
|
|
|
|
|
* running
|
|
|
|
|
*/
|
|
|
|
|
virtual void init() {};
|
2006-11-30 19:43:04 +02:00
|
|
|
|
|
2016-02-04 15:48:42 +02:00
|
|
|
|
virtual ~Store() { }
|
2006-11-30 19:43:04 +02:00
|
|
|
|
|
2024-07-16 06:26:39 +03:00
|
|
|
|
/**
|
|
|
|
|
* @todo move to `StoreConfig` one we store enough information in
|
|
|
|
|
* those to recover the scheme and authority in all cases.
|
|
|
|
|
*/
|
2016-04-29 17:26:16 +03:00
|
|
|
|
virtual std::string getUri() = 0;
|
2016-04-20 15:12:38 +03:00
|
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
|
/**
|
|
|
|
|
* Follow symlinks until we end up with a path in the Nix store.
|
|
|
|
|
*/
|
2019-12-16 20:11:47 +02:00
|
|
|
|
Path followLinksToStore(std::string_view path) const;
|
2016-06-01 15:49:12 +03:00
|
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
|
/**
|
|
|
|
|
* Same as followLinksToStore(), but apply toStorePath() to the
|
|
|
|
|
* result.
|
|
|
|
|
*/
|
2019-12-16 20:11:47 +02:00
|
|
|
|
StorePath followLinksToStorePath(std::string_view path) const;
|
|
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
|
/**
|
|
|
|
|
* Check whether a path is valid.
|
|
|
|
|
*/
|
2019-12-05 20:11:09 +02:00
|
|
|
|
bool isValidPath(const StorePath & path);
|
2016-04-19 19:50:15 +03:00
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
2019-12-05 20:11:09 +02:00
|
|
|
|
virtual bool isValidPathUncached(const StorePath & path);
|
2016-04-19 19:50:15 +03:00
|
|
|
|
|
|
|
|
|
public:
|
2006-11-30 19:43:04 +02:00
|
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
|
/**
|
|
|
|
|
* If requested, substitute missing paths. This
|
|
|
|
|
* implements nix-copy-closure's --use-substitutes
|
|
|
|
|
* flag.
|
|
|
|
|
*/
|
2020-10-21 22:31:19 +03:00
|
|
|
|
void substitutePaths(const StorePathSet & paths);
|
|
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
|
/**
|
|
|
|
|
* Query which of the given paths is valid. Optionally, try to
|
|
|
|
|
* substitute missing paths.
|
|
|
|
|
*/
|
2019-12-05 20:11:09 +02:00
|
|
|
|
virtual StorePathSet queryValidPaths(const StorePathSet & paths,
|
2017-06-28 19:11:01 +03:00
|
|
|
|
SubstituteFlag maybeSubstitute = NoSubstitute);
|
2012-07-11 18:08:47 +03:00
|
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
|
/**
|
|
|
|
|
* Query the set of all valid paths. Note that for some store
|
|
|
|
|
* backends, the name part of store paths may be replaced by 'x'
|
|
|
|
|
* (i.e. you'll get /nix/store/<hash>-x rather than
|
|
|
|
|
* /nix/store/<hash>-<name>). Use queryPathInfo() to obtain the
|
|
|
|
|
* full store path. FIXME: should return a set of
|
|
|
|
|
* std::variant<StorePath, HashPart> to get rid of this hack.
|
|
|
|
|
*/
|
2019-12-05 20:11:09 +02:00
|
|
|
|
virtual StorePathSet queryAllValidPaths()
|
2019-01-18 14:34:23 +02:00
|
|
|
|
{ unsupported("queryAllValidPaths"); }
|
2008-01-29 20:17:36 +02:00
|
|
|
|
|
2020-07-13 15:35:01 +03:00
|
|
|
|
constexpr static const char * MissingName = "x";
|
|
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
|
/**
|
|
|
|
|
* Query information about a valid path. It is permitted to omit
|
|
|
|
|
* the name part of the store path.
|
|
|
|
|
*/
|
2019-12-05 20:11:09 +02:00
|
|
|
|
ref<const ValidPathInfo> queryPathInfo(const StorePath & path);
|
2016-04-19 19:50:15 +03:00
|
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
|
/**
|
|
|
|
|
* Asynchronous version of queryPathInfo().
|
|
|
|
|
*/
|
2019-12-05 20:11:09 +02:00
|
|
|
|
void queryPathInfo(const StorePath & path,
|
2018-09-25 19:54:16 +03:00
|
|
|
|
Callback<ref<const ValidPathInfo>> callback) noexcept;
|
2016-09-16 19:54:14 +03:00
|
|
|
|
|
2024-01-17 17:54:45 +02:00
|
|
|
|
/**
|
2024-01-17 18:54:03 +02:00
|
|
|
|
* Version of queryPathInfo() that only queries the local narinfo cache and not
|
2024-01-17 17:54:45 +02:00
|
|
|
|
* the actual store.
|
|
|
|
|
*
|
2024-01-19 18:00:39 +02:00
|
|
|
|
* @return `std::nullopt` if nothing is known about the path in the local narinfo cache.
|
|
|
|
|
* @return `std::make_optional(nullptr)` if the path is known to not exist.
|
|
|
|
|
* @return `std::make_optional(validPathInfo)` if the path is known to exist.
|
2024-01-17 17:54:45 +02:00
|
|
|
|
*/
|
2024-01-19 18:00:39 +02:00
|
|
|
|
std::optional<std::shared_ptr<const ValidPathInfo>> queryPathInfoFromClientCache(const StorePath & path);
|
2024-01-17 17:54:45 +02:00
|
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
|
/**
|
|
|
|
|
* Query the information about a realisation.
|
|
|
|
|
*/
|
2021-10-27 12:36:51 +03:00
|
|
|
|
std::shared_ptr<const Realisation> queryRealisation(const DrvOutput &);
|
|
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
|
/**
|
|
|
|
|
* Asynchronous version of queryRealisation().
|
|
|
|
|
*/
|
2021-10-27 12:36:51 +03:00
|
|
|
|
void queryRealisation(const DrvOutput &,
|
|
|
|
|
Callback<std::shared_ptr<const Realisation>> callback) noexcept;
|
|
|
|
|
|
|
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
|
/**
|
|
|
|
|
* Check whether the given valid path info is sufficiently attested, by
|
|
|
|
|
* either being signed by a trusted public key or content-addressed, in
|
|
|
|
|
* order to be included in the given store.
|
|
|
|
|
*
|
|
|
|
|
* These same checks would be performed in addToStore, but this allows an
|
|
|
|
|
* earlier failure in the case where dependencies need to be added too, but
|
|
|
|
|
* the addToStore wouldn't fail until those dependencies are added. Also,
|
|
|
|
|
* we don't really want to add the dependencies listed in a nar info we
|
|
|
|
|
* don't trust anyyways.
|
|
|
|
|
*/
|
2021-03-08 16:07:33 +02:00
|
|
|
|
virtual bool pathInfoIsUntrusted(const ValidPathInfo &)
|
2021-01-15 18:37:41 +02:00
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-08 12:56:33 +02:00
|
|
|
|
virtual bool realisationIsUntrusted(const Realisation & )
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-19 19:50:15 +03:00
|
|
|
|
protected:
|
2010-11-16 19:11:46 +02:00
|
|
|
|
|
2019-12-05 20:11:09 +02:00
|
|
|
|
virtual void queryPathInfoUncached(const StorePath & path,
|
2018-09-25 19:54:16 +03:00
|
|
|
|
Callback<std::shared_ptr<const ValidPathInfo>> callback) noexcept = 0;
|
2021-10-27 12:36:51 +03:00
|
|
|
|
virtual void queryRealisationUncached(const DrvOutput &,
|
|
|
|
|
Callback<std::shared_ptr<const Realisation>> callback) noexcept = 0;
|
2006-11-30 19:43:04 +02:00
|
|
|
|
|
2016-04-19 19:50:15 +03:00
|
|
|
|
public:
|
2006-11-30 19:43:04 +02:00
|
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
|
/**
|
|
|
|
|
* Queries the set of incoming FS references for a store path.
|
|
|
|
|
* The result is not cleared.
|
|
|
|
|
*/
|
2019-12-05 20:11:09 +02:00
|
|
|
|
virtual void queryReferrers(const StorePath & path, StorePathSet & referrers)
|
2019-01-18 14:34:23 +02:00
|
|
|
|
{ unsupported("queryReferrers"); }
|
2006-11-30 19:43:04 +02:00
|
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
|
/**
|
2023-04-07 16:55:28 +03:00
|
|
|
|
* @return all currently valid derivations that have `path` as an
|
2023-03-26 01:12:44 +02:00
|
|
|
|
* output.
|
|
|
|
|
*
|
2023-04-07 16:55:28 +03:00
|
|
|
|
* (Note that the result of `queryDeriver()` is the derivation that
|
|
|
|
|
* was actually used to produce `path`, which may not exist
|
2023-03-26 01:12:44 +02:00
|
|
|
|
* anymore.)
|
|
|
|
|
*/
|
2019-12-05 20:11:09 +02:00
|
|
|
|
virtual StorePathSet queryValidDerivers(const StorePath & path) { return {}; };
|
2012-12-20 19:41:44 +02:00
|
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
|
/**
|
2023-04-07 16:55:28 +03:00
|
|
|
|
* Query the outputs of the derivation denoted by `path`.
|
2023-03-26 01:12:44 +02:00
|
|
|
|
*/
|
2020-06-10 12:20:52 +03:00
|
|
|
|
virtual StorePathSet queryDerivationOutputs(const StorePath & path);
|
|
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
|
/**
|
|
|
|
|
* Query the mapping outputName => outputPath for the given
|
|
|
|
|
* derivation. All outputs are mentioned so ones mising the mapping
|
|
|
|
|
* are mapped to `std::nullopt`.
|
|
|
|
|
*/
|
2023-07-19 21:52:35 +03:00
|
|
|
|
virtual std::map<std::string, std::optional<StorePath>> queryPartialDerivationOutputMap(
|
|
|
|
|
const StorePath & path,
|
|
|
|
|
Store * evalStore = nullptr);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Like `queryPartialDerivationOutputMap` but only considers
|
|
|
|
|
* statically known output paths (i.e. those that can be gotten from
|
|
|
|
|
* the derivation itself.
|
|
|
|
|
*
|
|
|
|
|
* Just a helper function for implementing
|
|
|
|
|
* `queryPartialDerivationOutputMap`.
|
|
|
|
|
*/
|
|
|
|
|
virtual std::map<std::string, std::optional<StorePath>> queryStaticPartialDerivationOutputMap(
|
|
|
|
|
const StorePath & path);
|
2020-12-17 12:35:24 +02:00
|
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
|
/**
|
|
|
|
|
* Query the mapping outputName=>outputPath for the given derivation.
|
|
|
|
|
* Assume every output has a mapping and throw an exception otherwise.
|
|
|
|
|
*/
|
2023-12-11 01:51:23 +02:00
|
|
|
|
OutputPathMap queryDerivationOutputMap(const StorePath & path, Store * evalStore = nullptr);
|
2011-11-06 08:28:20 +02:00
|
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
|
/**
|
|
|
|
|
* Query the full store path given the hash part of a valid store
|
|
|
|
|
* path, or empty if the path doesn't exist.
|
|
|
|
|
*/
|
2019-12-05 20:11:09 +02:00
|
|
|
|
virtual std::optional<StorePath> queryPathFromHashPart(const std::string & hashPart) = 0;
|
2015-03-25 18:06:12 +02:00
|
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
|
/**
|
|
|
|
|
* Query which of the given paths have substitutes.
|
|
|
|
|
*/
|
2019-12-05 20:11:09 +02:00
|
|
|
|
virtual StorePathSet querySubstitutablePaths(const StorePathSet & paths) { return {}; };
|
2007-08-12 03:29:28 +03:00
|
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
|
/**
|
|
|
|
|
* Query substitute info (i.e. references, derivers and download
|
|
|
|
|
* sizes) of a map of paths to their optional ca values. The info of
|
|
|
|
|
* the first succeeding substituter for each path will be returned.
|
|
|
|
|
* If a path does not have substitute info, it's omitted from the
|
|
|
|
|
* resulting ‘infos’ map.
|
|
|
|
|
*/
|
2020-06-17 22:03:05 +03:00
|
|
|
|
virtual void querySubstitutablePathInfos(const StorePathCAMap & paths,
|
2023-04-03 03:28:10 +03:00
|
|
|
|
SubstitutablePathInfos & infos);
|
2015-03-25 18:06:12 +02:00
|
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
|
/**
|
|
|
|
|
* Import a path into the store.
|
|
|
|
|
*/
|
2018-03-16 21:22:34 +02:00
|
|
|
|
virtual void addToStore(const ValidPathInfo & info, Source & narSource,
|
2020-07-13 18:37:44 +03:00
|
|
|
|
RepairFlag repair = NoRepair, CheckSigsFlag checkSigs = CheckSigs) = 0;
|
2016-05-04 14:36:54 +03:00
|
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
|
/**
|
|
|
|
|
* A list of paths infos along with a source providing the content
|
|
|
|
|
* of the associated store path
|
|
|
|
|
*/
|
2022-06-08 15:03:46 +03:00
|
|
|
|
using PathsSource = std::vector<std::pair<ValidPathInfo, std::unique_ptr<Source>>>;
|
|
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
|
/**
|
|
|
|
|
* Import multiple paths into the store.
|
|
|
|
|
*/
|
2021-07-26 14:31:09 +03:00
|
|
|
|
virtual void addMultipleToStore(
|
|
|
|
|
Source & source,
|
|
|
|
|
RepairFlag repair = NoRepair,
|
|
|
|
|
CheckSigsFlag checkSigs = CheckSigs);
|
2022-08-22 16:30:38 +03:00
|
|
|
|
|
2022-06-03 18:01:16 +03:00
|
|
|
|
virtual void addMultipleToStore(
|
2022-06-08 15:03:46 +03:00
|
|
|
|
PathsSource & pathsToCopy,
|
2022-06-03 18:01:16 +03:00
|
|
|
|
Activity & act,
|
|
|
|
|
RepairFlag repair = NoRepair,
|
2022-08-22 16:30:38 +03:00
|
|
|
|
CheckSigsFlag checkSigs = CheckSigs);
|
2021-07-26 14:31:09 +03:00
|
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
|
/**
|
|
|
|
|
* Copy the contents of a path to the store and register the
|
|
|
|
|
* validity the resulting path.
|
|
|
|
|
*
|
|
|
|
|
* @return The resulting path is returned.
|
|
|
|
|
* @param filter This function can be used to exclude files (see
|
|
|
|
|
* libutil/archive.hh).
|
|
|
|
|
*/
|
2022-02-25 17:00:00 +02:00
|
|
|
|
virtual StorePath addToStore(
|
2023-11-04 22:25:41 +02:00
|
|
|
|
std::string_view name,
|
2024-05-06 20:05:42 +03:00
|
|
|
|
const SourcePath & path,
|
2024-05-17 02:08:28 +03:00
|
|
|
|
ContentAddressMethod method = ContentAddressMethod::Raw::NixArchive,
|
2023-11-04 22:25:41 +02:00
|
|
|
|
HashAlgorithm hashAlgo = HashAlgorithm::SHA256,
|
|
|
|
|
const StorePathSet & references = StorePathSet(),
|
|
|
|
|
PathFilter & filter = defaultPathFilter,
|
|
|
|
|
RepairFlag repair = NoRepair);
|
2006-11-30 19:43:04 +02:00
|
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
|
/**
|
|
|
|
|
* Copy the contents of a path to the store and register the
|
|
|
|
|
* validity the resulting path, using a constant amount of
|
|
|
|
|
* memory.
|
|
|
|
|
*/
|
2023-11-04 22:25:41 +02:00
|
|
|
|
ValidPathInfo addToStoreSlow(
|
|
|
|
|
std::string_view name,
|
2024-05-06 20:05:42 +03:00
|
|
|
|
const SourcePath & path,
|
2024-05-17 02:08:28 +03:00
|
|
|
|
ContentAddressMethod method = ContentAddressMethod::Raw::NixArchive,
|
2023-11-04 22:25:41 +02:00
|
|
|
|
HashAlgorithm hashAlgo = HashAlgorithm::SHA256,
|
|
|
|
|
const StorePathSet & references = StorePathSet(),
|
|
|
|
|
std::optional<Hash> expectedCAHash = {});
|
2020-07-10 14:21:37 +03:00
|
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
|
/**
|
|
|
|
|
* Like addToStore(), but the contents of the path are contained
|
2023-04-07 16:55:28 +03:00
|
|
|
|
* in `dump`, which is either a NAR serialisation (if recursive ==
|
2023-03-26 01:12:44 +02:00
|
|
|
|
* true) or simply the contents of a regular file (if recursive ==
|
|
|
|
|
* false).
|
|
|
|
|
*
|
2024-01-19 06:57:26 +02:00
|
|
|
|
* `dump` may be drained.
|
|
|
|
|
*
|
|
|
|
|
* @param dumpMethod What serialisation format is `dump`, i.e. how
|
|
|
|
|
* to deserialize it. Must either match hashMethod or be
|
2024-05-17 00:46:43 +03:00
|
|
|
|
* `FileSerialisationMethod::NixArchive`.
|
2024-01-19 06:57:26 +02:00
|
|
|
|
*
|
|
|
|
|
* @param hashMethod How content addressing? Need not match be the
|
|
|
|
|
* same as `dumpMethod`.
|
|
|
|
|
*
|
|
|
|
|
* @todo remove?
|
2023-03-26 01:12:44 +02:00
|
|
|
|
*/
|
2023-11-04 22:25:41 +02:00
|
|
|
|
virtual StorePath addToStoreFromDump(
|
|
|
|
|
Source & dump,
|
|
|
|
|
std::string_view name,
|
2024-05-17 00:46:43 +03:00
|
|
|
|
FileSerialisationMethod dumpMethod = FileSerialisationMethod::NixArchive,
|
2024-05-17 02:08:28 +03:00
|
|
|
|
ContentAddressMethod hashMethod = ContentAddressMethod::Raw::NixArchive,
|
2023-11-04 22:25:41 +02:00
|
|
|
|
HashAlgorithm hashAlgo = HashAlgorithm::SHA256,
|
|
|
|
|
const StorePathSet & references = StorePathSet(),
|
2024-01-18 06:46:03 +02:00
|
|
|
|
RepairFlag repair = NoRepair) = 0;
|
2018-09-25 19:55:37 +03:00
|
|
|
|
|
2020-10-08 18:36:51 +03:00
|
|
|
|
/**
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
virtual void registerDrvOutput(const Realisation & output)
|
|
|
|
|
{ unsupported("registerDrvOutput"); }
|
2021-03-08 17:43:11 +02:00
|
|
|
|
virtual void registerDrvOutput(const Realisation & output, CheckSigsFlag checkSigs)
|
|
|
|
|
{ return registerDrvOutput(output); }
|
2020-10-08 18:36:51 +03:00
|
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
|
/**
|
|
|
|
|
* Write a NAR dump of a store path.
|
|
|
|
|
*/
|
2019-12-05 20:11:09 +02:00
|
|
|
|
virtual void narFromPath(const StorePath & path, Sink & sink) = 0;
|
2016-03-21 18:55:57 +02:00
|
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
|
/**
|
|
|
|
|
* For each path, if it's a derivation, build it. Building a
|
|
|
|
|
* derivation means ensuring that the output paths are valid. If
|
|
|
|
|
* they are already valid, this is a no-op. Otherwise, validity
|
|
|
|
|
* can be reached in two ways. First, if the output paths is
|
|
|
|
|
* substitutable, then build the path that way. Second, the
|
|
|
|
|
* output paths can be created by running the builder, after
|
|
|
|
|
* recursively building any sub-derivations. For inputs that are
|
|
|
|
|
* not derivations, substitute them.
|
|
|
|
|
*/
|
2019-12-05 20:11:09 +02:00
|
|
|
|
virtual void buildPaths(
|
2021-04-05 16:48:18 +03:00
|
|
|
|
const std::vector<DerivedPath> & paths,
|
2022-03-08 20:50:46 +02:00
|
|
|
|
BuildMode buildMode = bmNormal,
|
|
|
|
|
std::shared_ptr<Store> evalStore = nullptr);
|
|
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
|
/**
|
|
|
|
|
* Like buildPaths(), but return a vector of \ref BuildResult
|
|
|
|
|
* BuildResults corresponding to each element in paths. Note that in
|
|
|
|
|
* case of a build/substitution error, this function won't throw an
|
|
|
|
|
* exception, but return a BuildResult containing an error message.
|
|
|
|
|
*/
|
Make `KeyedBuildResult`, `BuildResult` like before, and fix bug another way
In https://github.com/NixOS/nix/pull/6311#discussion_r834863823, I
realized since derivation goals' wanted outputs can "grow" due to
overlapping dependencies (See `DerivationGoal::addWantedOutputs`, called
by `Worker::makeDerivationGoalCommon`), the previous bug fix had an
unfortunate side effect of causing more pointless rebuilds.
In paticular, we have this situation:
1. Goal made from `DerivedPath::Built { foo, {a} }`.
2. Goal gives on on substituting, starts building.
3. Goal made from `DerivedPath::Built { foo, {b} }`, in fact is just
modified original goal.
4. Though the goal had gotten as far as building, so all outputs were
going to be produced, `addWantedOutputs` no longer knows that and so
the goal is flagged to be restarted.
This might sound far-fetched with input-addressed drvs, where we usually
basically have all our goals "planned out" before we start doing
anything, but with CA derivation goals and especially RFC 92, where *drv
resolution* means goals are created after some building is completed, it
is more likely to happen.
So the first thing to do was restore the clearing of `wantedOutputs` we
used to do, and then filter the outputs in `buildPathsWithResults` to
only get the ones we care about.
But fix also has its own side effect in that the `DerivedPath` in the
`BuildResult` in `DerivationGoal` cannot be trusted; it is merely the
*first* `DerivedPath` for which this goal was originally created.
To remedy this, I made `BuildResult` be like it was before, and instead
made `KeyedBuildResult` be a subclass wit the path. Only
`buildPathsWithResults` returns `KeyedBuildResult`s, everything else
just becomes like it was before, where the "key" is unambiguous from
context.
I think separating the "primary key" field(s) from the other fields is
good practical in general anyways. (I would like to do the same thing
for `ValidPathInfo`.) Among other things, it allows constructions like
`std::map<Key, ThingWithKey>` where doesn't contain duplicate keys and
just precludes the possibility of those duplicate keys being out of
sync.
We might leverage the above someday to overload `buildPathsWithResults`
to take a *set* of return a *map* per the above.
-----
Unfortunately, we need to avoid C++20 strictness on designated
initializers.
(BTW
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2287r1.html
this offers some new syntax for this use-case. Hopefully this will be
adopted and we can eventually use it.)
No having that yet, maybe it would be better to not make
`KeyedBuildResult` a subclass to just avoid this.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2022-03-25 03:26:07 +02:00
|
|
|
|
virtual std::vector<KeyedBuildResult> buildPathsWithResults(
|
2022-03-08 20:50:46 +02:00
|
|
|
|
const std::vector<DerivedPath> & paths,
|
2021-07-19 16:43:08 +03:00
|
|
|
|
BuildMode buildMode = bmNormal,
|
|
|
|
|
std::shared_ptr<Store> evalStore = nullptr);
|
2006-11-30 20:02:04 +02:00
|
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
|
/**
|
|
|
|
|
* Build a single non-materialized derivation (i.e. not from an
|
|
|
|
|
* on-disk .drv file).
|
|
|
|
|
*
|
|
|
|
|
* @param drvPath This is used to deduplicate worker goals so it is
|
|
|
|
|
* imperative that is correct. That said, it doesn't literally need
|
|
|
|
|
* to be store path that would be calculated from writing this
|
|
|
|
|
* derivation to the store: it is OK if it instead is that of a
|
|
|
|
|
* Derivation which would resolve to this (by taking the outputs of
|
|
|
|
|
* it's input derivations and adding them as input sources) such
|
|
|
|
|
* that the build time referenceable-paths are the same.
|
|
|
|
|
*
|
|
|
|
|
* In the input-addressed case, we usually *do* use an "original"
|
|
|
|
|
* unresolved derivations's path, as that is what will be used in the
|
|
|
|
|
* buildPaths case. Also, the input-addressed output paths are verified
|
|
|
|
|
* only by that contents of that specific unresolved derivation, so it is
|
|
|
|
|
* nice to keep that information around so if the original derivation is
|
|
|
|
|
* ever obtained later, it can be verified whether the trusted user in fact
|
|
|
|
|
* used the proper output path.
|
|
|
|
|
*
|
|
|
|
|
* In the content-addressed case, we want to always use the resolved
|
|
|
|
|
* drv path calculated from the provided derivation. This serves two
|
|
|
|
|
* purposes:
|
|
|
|
|
*
|
|
|
|
|
* - It keeps the operation trustless, by ruling out a maliciously
|
|
|
|
|
* invalid drv path corresponding to a non-resolution-equivalent
|
|
|
|
|
* derivation.
|
|
|
|
|
*
|
|
|
|
|
* - For the floating case in particular, it ensures that the derivation
|
|
|
|
|
* to output mapping respects the resolution equivalence relation, so
|
|
|
|
|
* one cannot choose different resolution-equivalent derivations to
|
|
|
|
|
* subvert dependency coherence (i.e. the property that one doesn't end
|
|
|
|
|
* up with multiple different versions of dependencies without
|
|
|
|
|
* explicitly choosing to allow it).
|
|
|
|
|
*/
|
2019-12-05 20:11:09 +02:00
|
|
|
|
virtual BuildResult buildDerivation(const StorePath & drvPath, const BasicDerivation & drv,
|
2020-12-20 19:54:57 +02:00
|
|
|
|
BuildMode buildMode = bmNormal);
|
Allow remote builds without sending the derivation closure
Previously, to build a derivation remotely, we had to copy the entire
closure of the .drv file to the remote machine, even though we only
need the top-level derivation. This is very wasteful: the closure can
contain thousands of store paths, and in some Hydra use cases, include
source paths that are very large (e.g. Git/Mercurial checkouts).
So now there is a new operation, StoreAPI::buildDerivation(), that
performs a build from an in-memory representation of a derivation
(BasicDerivation) rather than from a on-disk .drv file. The only files
that need to be in the Nix store are the sources of the derivation
(drv.inputSrcs), and the needed output paths of the dependencies (as
described by drv.inputDrvs). "nix-store --serve" exposes this
interface.
Note that this is a privileged operation, because you can construct a
derivation that builds any store path whatsoever. Fixing this will
require changing the hashing scheme (i.e., the output paths should be
computed from the other fields in BasicDerivation, allowing them to be
verified without access to other derivations). However, this would be
quite nice because it would allow .drv-free building (e.g. "nix-env
-i" wouldn't have to write any .drv files to disk).
Fixes #173.
2015-07-17 18:57:40 +03:00
|
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
|
/**
|
|
|
|
|
* Ensure that a path is valid. If it is not currently valid, it
|
|
|
|
|
* may be made valid by running a substitute (if defined for the
|
|
|
|
|
* path).
|
|
|
|
|
*/
|
2020-12-20 19:54:57 +02:00
|
|
|
|
virtual void ensurePath(const StorePath & path);
|
2006-12-02 18:41:36 +02:00
|
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
|
/**
|
|
|
|
|
* Add a store path as a temporary root of the garbage collector.
|
|
|
|
|
* The root disappears as soon as we exit.
|
|
|
|
|
*/
|
2019-12-05 20:11:09 +02:00
|
|
|
|
virtual void addTempRoot(const StorePath & path)
|
2021-07-19 13:07:23 +03:00
|
|
|
|
{ debug("not creating temporary root, store doesn't support GC"); }
|
2006-12-02 18:41:36 +02:00
|
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
|
/**
|
|
|
|
|
* @return a string representing information about the path that
|
2023-04-07 16:55:28 +03:00
|
|
|
|
* can be loaded into the database using `nix-store --load-db` or
|
|
|
|
|
* `nix-store --register-validity`.
|
2023-03-26 01:12:44 +02:00
|
|
|
|
*/
|
2022-02-25 17:00:00 +02:00
|
|
|
|
std::string makeValidityRegistration(const StorePathSet & paths,
|
2010-11-16 19:11:46 +02:00
|
|
|
|
bool showDerivers, bool showHash);
|
2014-09-01 23:21:42 +03:00
|
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
|
/**
|
|
|
|
|
* Optimise the disk space usage of the Nix store by hard-linking files
|
|
|
|
|
* with the same contents.
|
|
|
|
|
*/
|
2017-02-07 20:22:48 +02:00
|
|
|
|
virtual void optimiseStore() { };
|
2015-06-02 00:20:11 +03:00
|
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
|
/**
|
|
|
|
|
* Check the integrity of the Nix store.
|
|
|
|
|
*
|
|
|
|
|
* @return true if errors remain.
|
|
|
|
|
*/
|
2017-06-28 19:11:01 +03:00
|
|
|
|
virtual bool verifyStore(bool checkContents, RepairFlag repair = NoRepair) { return false; };
|
Eliminate the "store" global variable
Also, move a few free-standing functions into StoreAPI and Derivation.
Also, introduce a non-nullable smart pointer, ref<T>, which is just a
wrapper around std::shared_ptr ensuring that the pointer is never
null. (For reference-counted values, this is better than passing a
"T&", because the latter doesn't maintain the refcount. Usually, the
caller will have a shared_ptr keeping the value alive, but that's not
always the case, e.g., when passing a reference to a std::thread via
std::bind.)
2016-02-04 15:28:26 +02:00
|
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
|
/**
|
|
|
|
|
* @return An object to access files in the Nix store.
|
|
|
|
|
*/
|
2023-11-01 18:09:28 +02:00
|
|
|
|
virtual ref<SourceAccessor> getFSAccessor(bool requireValidPath = true) = 0;
|
2016-02-25 18:43:19 +02:00
|
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
|
/**
|
|
|
|
|
* Repair the contents of the given path by redownloading it using
|
|
|
|
|
* a substituter (if available).
|
|
|
|
|
*/
|
2023-04-13 17:38:35 +03:00
|
|
|
|
virtual void repairPath(const StorePath & path);
|
2021-01-14 00:27:39 +02:00
|
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
|
/**
|
|
|
|
|
* Add signatures to the specified store path. The signatures are
|
|
|
|
|
* not verified.
|
|
|
|
|
*/
|
2019-12-05 20:11:09 +02:00
|
|
|
|
virtual void addSignatures(const StorePath & storePath, const StringSet & sigs)
|
2019-01-18 14:34:23 +02:00
|
|
|
|
{ unsupported("addSignatures"); }
|
2016-04-05 16:30:22 +03:00
|
|
|
|
|
Eliminate the "store" global variable
Also, move a few free-standing functions into StoreAPI and Derivation.
Also, introduce a non-nullable smart pointer, ref<T>, which is just a
wrapper around std::shared_ptr ensuring that the pointer is never
null. (For reference-counted values, this is better than passing a
"T&", because the latter doesn't maintain the refcount. Usually, the
caller will have a shared_ptr keeping the value alive, but that's not
always the case, e.g., when passing a reference to a std::thread via
std::bind.)
2016-02-04 15:28:26 +02:00
|
|
|
|
/* Utility functions. */
|
|
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
|
/**
|
|
|
|
|
* Read a derivation, after ensuring its existence through
|
|
|
|
|
* ensurePath().
|
|
|
|
|
*/
|
2019-12-05 20:11:09 +02:00
|
|
|
|
Derivation derivationFromPath(const StorePath & drvPath);
|
Eliminate the "store" global variable
Also, move a few free-standing functions into StoreAPI and Derivation.
Also, introduce a non-nullable smart pointer, ref<T>, which is just a
wrapper around std::shared_ptr ensuring that the pointer is never
null. (For reference-counted values, this is better than passing a
"T&", because the latter doesn't maintain the refcount. Usually, the
caller will have a shared_ptr keeping the value alive, but that's not
always the case, e.g., when passing a reference to a std::thread via
std::bind.)
2016-02-04 15:28:26 +02:00
|
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
|
/**
|
|
|
|
|
* Read a derivation (which must already be valid).
|
|
|
|
|
*/
|
2020-06-12 14:04:52 +03:00
|
|
|
|
Derivation readDerivation(const StorePath & drvPath);
|
|
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
|
/**
|
|
|
|
|
* Read a derivation from a potentially invalid path.
|
|
|
|
|
*/
|
2020-11-17 14:58:55 +02:00
|
|
|
|
Derivation readInvalidDerivation(const StorePath & drvPath);
|
|
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
|
/**
|
|
|
|
|
* @param [out] out Place in here the set of all store paths in the
|
2023-04-07 16:55:28 +03:00
|
|
|
|
* file system closure of `storePath`; that is, all paths than can
|
|
|
|
|
* be directly or indirectly reached from it. `out` is not cleared.
|
2023-03-26 01:12:44 +02:00
|
|
|
|
*
|
|
|
|
|
* @param flipDirection If true, the set of paths that can reach
|
2023-04-07 16:55:28 +03:00
|
|
|
|
* `storePath` is returned; that is, the closures under the
|
|
|
|
|
* `referrers` relation instead of the `references` relation is
|
2023-03-26 01:12:44 +02:00
|
|
|
|
* returned.
|
|
|
|
|
*/
|
2019-12-05 20:11:09 +02:00
|
|
|
|
virtual void computeFSClosure(const StorePathSet & paths,
|
|
|
|
|
StorePathSet & out, bool flipDirection = false,
|
2016-11-10 18:45:04 +02:00
|
|
|
|
bool includeOutputs = false, bool includeDerivers = false);
|
|
|
|
|
|
2019-12-05 20:11:09 +02:00
|
|
|
|
void computeFSClosure(const StorePath & path,
|
|
|
|
|
StorePathSet & out, bool flipDirection = false,
|
Eliminate the "store" global variable
Also, move a few free-standing functions into StoreAPI and Derivation.
Also, introduce a non-nullable smart pointer, ref<T>, which is just a
wrapper around std::shared_ptr ensuring that the pointer is never
null. (For reference-counted values, this is better than passing a
"T&", because the latter doesn't maintain the refcount. Usually, the
caller will have a shared_ptr keeping the value alive, but that's not
always the case, e.g., when passing a reference to a std::thread via
std::bind.)
2016-02-04 15:28:26 +02:00
|
|
|
|
bool includeOutputs = false, bool includeDerivers = false);
|
|
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
|
/**
|
|
|
|
|
* Given a set of paths that are to be built, return the set of
|
|
|
|
|
* derivations that will be built, and the set of output paths that
|
|
|
|
|
* will be substituted.
|
|
|
|
|
*/
|
2021-04-05 16:48:18 +03:00
|
|
|
|
virtual void queryMissing(const std::vector<DerivedPath> & targets,
|
2019-12-05 20:11:09 +02:00
|
|
|
|
StorePathSet & willBuild, StorePathSet & willSubstitute, StorePathSet & unknown,
|
2020-07-30 14:10:49 +03:00
|
|
|
|
uint64_t & downloadSize, uint64_t & narSize);
|
Eliminate the "store" global variable
Also, move a few free-standing functions into StoreAPI and Derivation.
Also, introduce a non-nullable smart pointer, ref<T>, which is just a
wrapper around std::shared_ptr ensuring that the pointer is never
null. (For reference-counted values, this is better than passing a
"T&", because the latter doesn't maintain the refcount. Usually, the
caller will have a shared_ptr keeping the value alive, but that's not
always the case, e.g., when passing a reference to a std::thread via
std::bind.)
2016-02-04 15:28:26 +02:00
|
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
|
/**
|
|
|
|
|
* Sort a set of paths topologically under the references
|
|
|
|
|
* relation. If p refers to q, then p precedes q in this list.
|
|
|
|
|
*/
|
2019-12-05 20:11:09 +02:00
|
|
|
|
StorePaths topoSortPaths(const StorePathSet & paths);
|
Eliminate the "store" global variable
Also, move a few free-standing functions into StoreAPI and Derivation.
Also, introduce a non-nullable smart pointer, ref<T>, which is just a
wrapper around std::shared_ptr ensuring that the pointer is never
null. (For reference-counted values, this is better than passing a
"T&", because the latter doesn't maintain the refcount. Usually, the
caller will have a shared_ptr keeping the value alive, but that's not
always the case, e.g., when passing a reference to a std::thread via
std::bind.)
2016-02-04 15:28:26 +02:00
|
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
|
/**
|
|
|
|
|
* Export multiple paths in the format expected by ‘nix-store
|
|
|
|
|
* --import’.
|
|
|
|
|
*/
|
2019-12-05 20:11:09 +02:00
|
|
|
|
void exportPaths(const StorePathSet & paths, Sink & sink);
|
2016-05-04 14:36:54 +03:00
|
|
|
|
|
2019-12-05 20:11:09 +02:00
|
|
|
|
void exportPath(const StorePath & path, Sink & sink);
|
2016-05-04 14:36:54 +03:00
|
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
|
/**
|
|
|
|
|
* Import a sequence of NAR dumps created by exportPaths() into the
|
|
|
|
|
* Nix store. Optionally, the contents of the NARs are preloaded
|
|
|
|
|
* into the specified FS accessor to speed up subsequent access.
|
|
|
|
|
*/
|
2021-07-26 14:50:18 +03:00
|
|
|
|
StorePaths importPaths(Source & source, CheckSigsFlag checkSigs = CheckSigs);
|
2016-05-04 14:36:54 +03:00
|
|
|
|
|
2016-04-19 19:50:15 +03:00
|
|
|
|
struct Stats
|
|
|
|
|
{
|
|
|
|
|
std::atomic<uint64_t> narInfoRead{0};
|
|
|
|
|
std::atomic<uint64_t> narInfoReadAverted{0};
|
|
|
|
|
std::atomic<uint64_t> narInfoMissing{0};
|
|
|
|
|
std::atomic<uint64_t> narInfoWrite{0};
|
|
|
|
|
std::atomic<uint64_t> pathInfoCacheSize{0};
|
|
|
|
|
std::atomic<uint64_t> narRead{0};
|
|
|
|
|
std::atomic<uint64_t> narReadBytes{0};
|
|
|
|
|
std::atomic<uint64_t> narReadCompressedBytes{0};
|
|
|
|
|
std::atomic<uint64_t> narWrite{0};
|
|
|
|
|
std::atomic<uint64_t> narWriteAverted{0};
|
|
|
|
|
std::atomic<uint64_t> narWriteBytes{0};
|
|
|
|
|
std::atomic<uint64_t> narWriteCompressedBytes{0};
|
|
|
|
|
std::atomic<uint64_t> narWriteCompressionTimeMs{0};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const Stats & getStats();
|
|
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
|
/**
|
|
|
|
|
* Computes the full closure of of a set of store-paths for e.g.
|
|
|
|
|
* derivations that need this information for `exportReferencesGraph`.
|
2021-06-22 21:37:25 +03:00
|
|
|
|
*/
|
2021-05-02 18:24:14 +03:00
|
|
|
|
StorePathSet exportReferences(const StorePathSet & storePaths, const StorePathSet & inputPaths);
|
|
|
|
|
|
2022-03-08 07:02:25 +02:00
|
|
|
|
/**
|
|
|
|
|
* Given a store path, return the realisation actually used in the realisation of this path:
|
|
|
|
|
* - If the path is a content-addressed derivation, try to resolve it
|
|
|
|
|
* - Otherwise, find one of its derivers
|
|
|
|
|
*/
|
|
|
|
|
std::optional<StorePath> getBuildDerivationPath(const StorePath &);
|
|
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
|
/**
|
|
|
|
|
* Hack to allow long-running processes like hydra-queue-runner to
|
|
|
|
|
* occasionally flush their path info cache.
|
|
|
|
|
*/
|
2017-04-06 16:22:37 +03:00
|
|
|
|
void clearPathInfoCache()
|
|
|
|
|
{
|
|
|
|
|
state.lock()->pathInfoCache.clear();
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
|
/**
|
|
|
|
|
* Establish a connection to the store, for store types that have
|
|
|
|
|
* a notion of connection. Otherwise this is a no-op.
|
|
|
|
|
*/
|
2017-05-02 15:18:46 +03:00
|
|
|
|
virtual void connect() { };
|
|
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
|
/**
|
|
|
|
|
* Get the protocol version of this store or it's connection.
|
|
|
|
|
*/
|
2018-08-31 00:28:47 +03:00
|
|
|
|
virtual unsigned int getProtocol()
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
};
|
|
|
|
|
|
2022-12-26 22:21:08 +02:00
|
|
|
|
/**
|
|
|
|
|
* @return/ whether store trusts *us*.
|
|
|
|
|
*
|
|
|
|
|
* `std::nullopt` means we do not know.
|
|
|
|
|
*
|
|
|
|
|
* @note This is the opposite of the StoreConfig::isTrusted
|
|
|
|
|
* store setting. That is about whether *we* trust the store.
|
|
|
|
|
*/
|
|
|
|
|
virtual std::optional<TrustedFlag> isTrustedClient() = 0;
|
|
|
|
|
|
|
|
|
|
|
2018-01-12 18:31:08 +02:00
|
|
|
|
virtual Path toRealPath(const Path & storePath)
|
|
|
|
|
{
|
|
|
|
|
return storePath;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-24 15:26:13 +02:00
|
|
|
|
Path toRealPath(const StorePath & storePath)
|
|
|
|
|
{
|
|
|
|
|
return toRealPath(printStorePath(storePath));
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
|
/**
|
2021-11-05 17:17:49 +02:00
|
|
|
|
* Synchronises the options of the client with those of the daemon
|
|
|
|
|
* (a no-op when there’s no daemon)
|
|
|
|
|
*/
|
|
|
|
|
virtual void setOptions() { }
|
2022-01-25 22:14:27 +02:00
|
|
|
|
|
|
|
|
|
virtual std::optional<std::string> getVersion() { return {}; }
|
|
|
|
|
|
2016-04-19 19:50:15 +03:00
|
|
|
|
protected:
|
|
|
|
|
|
|
|
|
|
Stats stats;
|
|
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
|
/**
|
|
|
|
|
* Helper for methods that are not unsupported: this is used for
|
|
|
|
|
* default definitions for virtual methods that are meant to be overriden.
|
|
|
|
|
*
|
2024-01-19 06:57:26 +02:00
|
|
|
|
* @todo Using this should be a last resort. It is better to make
|
2023-03-26 01:12:44 +02:00
|
|
|
|
* the method "virtual pure" and/or move it to a subclass.
|
|
|
|
|
*/
|
2019-01-18 14:34:23 +02:00
|
|
|
|
[[noreturn]] void unsupported(const std::string & op)
|
2017-05-01 14:43:34 +03:00
|
|
|
|
{
|
2019-01-18 14:34:23 +02:00
|
|
|
|
throw Unsupported("operation '%s' is not supported by store '%s'", op, getUri());
|
2017-05-01 14:43:34 +03:00
|
|
|
|
}
|
|
|
|
|
|
2006-11-30 19:43:04 +02:00
|
|
|
|
};
|
|
|
|
|
|
2016-02-25 18:43:19 +02:00
|
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
|
/**
|
|
|
|
|
* Copy a path from one store to another.
|
|
|
|
|
*/
|
2021-07-19 13:01:06 +03:00
|
|
|
|
void copyStorePath(
|
|
|
|
|
Store & srcStore,
|
|
|
|
|
Store & dstStore,
|
|
|
|
|
const StorePath & storePath,
|
|
|
|
|
RepairFlag repair = NoRepair,
|
|
|
|
|
CheckSigsFlag checkSigs = CheckSigs);
|
2017-06-28 19:11:01 +03:00
|
|
|
|
|
|
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
|
/**
|
|
|
|
|
* Copy store paths from one store to another. The paths may be copied
|
|
|
|
|
* in parallel. They are copied in a topologically sorted order (i.e. if
|
|
|
|
|
* A is a reference of B, then A is copied before B), but the set of
|
|
|
|
|
* store paths is not automatically closed; use copyClosure() for that.
|
|
|
|
|
*
|
|
|
|
|
* @return a map of what each path was copied to the dstStore as.
|
|
|
|
|
*/
|
2021-07-19 13:01:06 +03:00
|
|
|
|
std::map<StorePath, StorePath> copyPaths(
|
|
|
|
|
Store & srcStore, Store & dstStore,
|
2022-03-18 17:35:45 +02:00
|
|
|
|
const std::set<RealisedPath> &,
|
2017-06-28 19:11:01 +03:00
|
|
|
|
RepairFlag repair = NoRepair,
|
|
|
|
|
CheckSigsFlag checkSigs = CheckSigs,
|
|
|
|
|
SubstituteFlag substitute = NoSubstitute);
|
2021-06-29 22:17:48 +03:00
|
|
|
|
|
2021-07-19 13:01:06 +03:00
|
|
|
|
std::map<StorePath, StorePath> copyPaths(
|
|
|
|
|
Store & srcStore, Store & dstStore,
|
2021-06-25 16:35:14 +03:00
|
|
|
|
const StorePathSet & paths,
|
2017-06-28 19:11:01 +03:00
|
|
|
|
RepairFlag repair = NoRepair,
|
|
|
|
|
CheckSigsFlag checkSigs = CheckSigs,
|
|
|
|
|
SubstituteFlag substitute = NoSubstitute);
|
2016-10-07 20:15:25 +03:00
|
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
|
/**
|
|
|
|
|
* Copy the closure of `paths` from `srcStore` to `dstStore`.
|
|
|
|
|
*/
|
2021-07-19 13:01:06 +03:00
|
|
|
|
void copyClosure(
|
|
|
|
|
Store & srcStore, Store & dstStore,
|
2022-03-18 17:35:45 +02:00
|
|
|
|
const std::set<RealisedPath> & paths,
|
2021-07-16 10:37:33 +03:00
|
|
|
|
RepairFlag repair = NoRepair,
|
|
|
|
|
CheckSigsFlag checkSigs = CheckSigs,
|
|
|
|
|
SubstituteFlag substitute = NoSubstitute);
|
2016-10-07 20:15:25 +03:00
|
|
|
|
|
2022-01-20 22:45:34 +02:00
|
|
|
|
void copyClosure(
|
|
|
|
|
Store & srcStore, Store & dstStore,
|
|
|
|
|
const StorePathSet & paths,
|
|
|
|
|
RepairFlag repair = NoRepair,
|
|
|
|
|
CheckSigsFlag checkSigs = CheckSigs,
|
|
|
|
|
SubstituteFlag substitute = NoSubstitute);
|
|
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
|
/**
|
|
|
|
|
* Remove the temporary roots file for this process. Any temporary
|
|
|
|
|
* root becomes garbage after this point unless it has been registered
|
|
|
|
|
* as a (permanent) root.
|
|
|
|
|
*/
|
2006-12-05 04:18:46 +02:00
|
|
|
|
void removeTempRoots();
|
|
|
|
|
|
|
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
|
/**
|
|
|
|
|
* Resolve the derived path completely, failing if any derivation output
|
|
|
|
|
* is unknown.
|
|
|
|
|
*/
|
Make the Derived Path family of types inductive for dynamic derivations
We want to be able to write down `foo.drv^bar.drv^baz`:
`foo.drv^bar.drv` is the dynamic derivation (since it is itself a
derivation output, `bar.drv` from `foo.drv`).
To that end, we create `Single{Derivation,BuiltPath}` types, that are
very similar except instead of having multiple outputs (in a set or
map), they have a single one. This is for everything to the left of the
rightmost `^`.
`NixStringContextElem` has an analogous change, and now can reuse
`SingleDerivedPath` at the top level. In fact, if we ever get rid of
`DrvDeep`, `NixStringContextElem` could be replaced with
`SingleDerivedPath` entirely!
Important note: some JSON formats have changed.
We already can *produce* dynamic derivations, but we can't refer to them
directly. Today, we can merely express building or example at the top
imperatively over time by building `foo.drv^bar.drv`, and then with a
second nix invocation doing `<result-from-first>^baz`, but this is not
declarative. The ethos of Nix of being able to write down the full plan
everything you want to do, and then execute than plan with a single
command, and for that we need the new inductive form of these types.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
2023-01-16 00:39:04 +02:00
|
|
|
|
StorePath resolveDerivedPath(Store &, const SingleDerivedPath &, Store * evalStore = nullptr);
|
2023-01-12 01:57:18 +02:00
|
|
|
|
OutputPathMap resolveDerivedPath(Store &, const DerivedPath::Built &, Store * evalStore = nullptr);
|
|
|
|
|
|
|
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
|
/**
|
|
|
|
|
* @return a Store object to access the Nix store denoted by
|
|
|
|
|
* ‘uri’ (slight misnomer...).
|
2024-01-23 21:23:03 +02:00
|
|
|
|
*/
|
|
|
|
|
ref<Store> openStore(StoreReference && storeURI);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Opens the store at `uri`, where `uri` is in the format expected by `StoreReference::parse`
|
|
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
|
*/
|
2017-10-23 20:34:49 +03:00
|
|
|
|
ref<Store> openStore(const std::string & uri = settings.storeUri.get(),
|
2017-05-01 18:35:30 +03:00
|
|
|
|
const Store::Params & extraParams = Store::Params());
|
2017-03-03 20:23:20 +02:00
|
|
|
|
|
2016-02-24 15:48:16 +02:00
|
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
|
/**
|
|
|
|
|
* @return the default substituter stores, defined by the
|
|
|
|
|
* ‘substituters’ option and various legacy options.
|
|
|
|
|
*/
|
2016-04-29 14:57:08 +03:00
|
|
|
|
std::list<ref<Store>> getDefaultSubstituters();
|
|
|
|
|
|
2020-09-08 15:50:23 +03:00
|
|
|
|
struct StoreFactory
|
|
|
|
|
{
|
2020-09-11 12:11:05 +03:00
|
|
|
|
std::set<std::string> uriSchemes;
|
2024-01-25 17:31:52 +02:00
|
|
|
|
/**
|
|
|
|
|
* The `authorityPath` parameter is `<authority>/<path>`, or really
|
|
|
|
|
* whatever comes after `<scheme>://` and before `?<query-params>`.
|
|
|
|
|
*/
|
|
|
|
|
std::function<std::shared_ptr<Store> (
|
|
|
|
|
std::string_view scheme,
|
|
|
|
|
std::string_view authorityPath,
|
|
|
|
|
const Store::Params & params)> create;
|
2020-09-10 11:55:51 +03:00
|
|
|
|
std::function<std::shared_ptr<StoreConfig> ()> getConfig;
|
2020-09-08 15:50:23 +03:00
|
|
|
|
};
|
2020-10-05 18:53:30 +03:00
|
|
|
|
|
2020-09-09 12:18:12 +03:00
|
|
|
|
struct Implementations
|
2016-02-29 17:11:11 +02:00
|
|
|
|
{
|
2020-09-09 12:18:12 +03:00
|
|
|
|
static std::vector<StoreFactory> * registered;
|
2016-04-29 14:57:08 +03:00
|
|
|
|
|
2020-09-10 11:55:51 +03:00
|
|
|
|
template<typename T, typename TConfig>
|
2020-09-09 12:18:12 +03:00
|
|
|
|
static void add()
|
2016-02-29 17:11:11 +02:00
|
|
|
|
{
|
2020-09-09 12:18:12 +03:00
|
|
|
|
if (!registered) registered = new std::vector<StoreFactory>();
|
2020-09-08 15:50:23 +03:00
|
|
|
|
StoreFactory factory{
|
2024-07-16 06:26:39 +03:00
|
|
|
|
.uriSchemes = TConfig::uriSchemes(),
|
2020-09-09 12:29:17 +03:00
|
|
|
|
.create =
|
2024-01-25 17:31:52 +02:00
|
|
|
|
([](auto scheme, auto uri, auto & params)
|
2020-09-08 15:50:23 +03:00
|
|
|
|
-> std::shared_ptr<Store>
|
2020-09-11 12:11:05 +03:00
|
|
|
|
{ return std::make_shared<T>(scheme, uri, params); }),
|
2020-09-10 11:55:51 +03:00
|
|
|
|
.getConfig =
|
|
|
|
|
([]()
|
|
|
|
|
-> std::shared_ptr<StoreConfig>
|
2020-09-14 15:12:47 +03:00
|
|
|
|
{ return std::make_shared<TConfig>(StringMap({})); })
|
2020-09-08 15:50:23 +03:00
|
|
|
|
};
|
2020-09-09 12:18:12 +03:00
|
|
|
|
registered->push_back(factory);
|
|
|
|
|
}
|
|
|
|
|
};
|
2016-02-29 17:11:11 +02:00
|
|
|
|
|
2020-09-10 11:55:51 +03:00
|
|
|
|
template<typename T, typename TConfig>
|
2016-02-29 17:11:11 +02:00
|
|
|
|
struct RegisterStoreImplementation
|
|
|
|
|
{
|
2020-09-09 12:18:12 +03:00
|
|
|
|
RegisterStoreImplementation()
|
2016-02-29 17:11:11 +02:00
|
|
|
|
{
|
2020-09-10 11:55:51 +03:00
|
|
|
|
Implementations::add<T, TConfig>();
|
2016-02-29 17:11:11 +02:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
|
/**
|
|
|
|
|
* Display a set of paths in human-readable form (i.e., between quotes
|
|
|
|
|
* and separated by commas).
|
|
|
|
|
*/
|
2022-02-25 17:00:00 +02:00
|
|
|
|
std::string showPaths(const PathSet & paths);
|
2006-11-30 19:43:04 +02:00
|
|
|
|
|
|
|
|
|
|
2019-12-05 20:11:09 +02:00
|
|
|
|
std::optional<ValidPathInfo> decodeValidPathInfo(
|
|
|
|
|
const Store & store,
|
|
|
|
|
std::istream & str,
|
2020-08-06 21:31:48 +03:00
|
|
|
|
std::optional<HashResult> hashGiven = std::nullopt);
|
2007-08-12 03:29:28 +03:00
|
|
|
|
|
2023-04-19 21:48:53 +03:00
|
|
|
|
const ContentAddress * getDerivationCA(const BasicDerivation & drv);
|
2020-06-13 08:07:42 +03:00
|
|
|
|
|
2021-05-26 17:09:02 +03:00
|
|
|
|
std::map<DrvOutput, StorePath> drvOutputReferences(
|
2021-05-19 11:35:31 +03:00
|
|
|
|
Store & store,
|
|
|
|
|
const Derivation & drv,
|
2023-12-11 04:21:21 +02:00
|
|
|
|
const StorePath & outputPath,
|
|
|
|
|
Store * evalStore = nullptr);
|
2021-05-19 11:35:31 +03:00
|
|
|
|
|
2006-11-30 19:43:04 +02:00
|
|
|
|
}
|