Nix
2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Toggle main menu visibility
Loading...
Searching...
No Matches
store-registration.hh
Go to the documentation of this file.
1
#pragma once
15
16
#include "
nix/store/store-api.hh
"
17
#include "
nix/util/url.hh
"
18
19
namespace
nix {
20
21
struct
StoreFactory
22
{
26
std::string
doc
;
27
31
StringSet
uriSchemes
;
32
37
std::optional<ExperimentalFeature>
experimentalFeature
;
38
43
fun<ref<StoreConfig>
(std::string_view scheme, std::string_view authorityPath,
const
Store::Config::Params & params)>
44
parseConfig
;
45
51
fun<ref<StoreConfig>
()>
getConfig
;
52
};
53
54
struct
Implementations
55
{
56
using
Map = std::map<std::string, StoreFactory>;
57
58
static
Map & registered();
59
60
template
<
typename
TConfig>
61
static
void
add()
62
{
63
StoreFactory
factory{
64
.doc = TConfig::doc(),
65
.uriSchemes = TConfig::uriSchemes(),
66
.experimentalFeature = TConfig::experimentalFeature(),
67
.parseConfig = ([](
auto
scheme,
auto
uri,
auto
& params) ->
ref<StoreConfig>
{
68
if
constexpr
(std::is_constructible_v<TConfig, std::filesystem::path, StoreConfig::Params>) {
69
auto
path =
70
uri.empty()
71
? std::filesystem::path{}
72
: canonPath(
urlPathToPath
(splitString<std::vector<std::string>>(percentDecode(uri),
"/"
)));
73
return
make_ref<TConfig>(std::move(path), params);
74
}
else
if
constexpr
(std::is_constructible_v<TConfig, ParsedURL, StoreConfig::Params>) {
75
return
make_ref<TConfig>(
parseURL
(concatStrings(scheme,
"://"
, uri)), params);
76
}
else
if
constexpr
(std::is_constructible_v<TConfig, ParsedURL::Authority, StoreConfig::Params>) {
77
return
make_ref<TConfig>(ParsedURL::Authority::parse(uri), params);
78
}
else
{
79
return
make_ref<TConfig>(scheme, uri, params);
80
}
81
}),
82
.getConfig = ([]() ->
ref<StoreConfig>
{
return
make_ref<TConfig>(Store::Config::Params{}); }),
83
};
84
auto
[it, didInsert] = registered().insert({TConfig::name(), std::move(factory)});
85
if
(!didInsert) {
86
throw
Error
(
"Already registered store with name '%s'"
, it->first);
87
}
88
}
89
};
90
91
template
<
typename
TConfig>
92
struct
RegisterStoreImplementation
93
{
94
RegisterStoreImplementation()
95
{
96
Implementations::add<TConfig>();
97
}
98
};
99
100
}
// namespace nix
nix::Error
Definition
error.hh:310
nix::fun
Definition
fun.hh:19
nix::ref
Definition
ref.hh:58
store-api.hh
nix::Implementations
Definition
store-registration.hh:55
nix::StoreFactory
Definition
store-registration.hh:22
nix::StoreFactory::experimentalFeature
std::optional< ExperimentalFeature > experimentalFeature
Definition
store-registration.hh:37
nix::StoreFactory::getConfig
fun< ref< StoreConfig >()> getConfig
Definition
store-registration.hh:51
nix::StoreFactory::uriSchemes
StringSet uriSchemes
Definition
store-registration.hh:31
nix::StoreFactory::parseConfig
fun< ref< StoreConfig >(std::string_view scheme, std::string_view authorityPath, const Store::Config::Params ¶ms)> parseConfig
Definition
store-registration.hh:44
nix::StoreFactory::doc
std::string doc
Definition
store-registration.hh:26
nix::StringSet
std::set< std::string, std::less<> > StringSet
Definition
types.hh:45
url.hh
nix::parseURL
ParsedURL parseURL(std::string_view url, bool lenient=false)
Definition
url.cc:120
nix::urlPathToPath
std::filesystem::path urlPathToPath(std::span< const std::string > urlPath)
Definition
url.cc:746
libstore
include
nix
store
store-registration.hh
Generated by
1.18.0