Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Loading...
Searching...
No Matches
store-reference.hh
Go to the documentation of this file.
1#pragma once
3
4#include <variant>
5
6#include "nix/util/types.hh"
10
11namespace nix {
12
45struct StoreReference
46{
47 using Params = StringMap;
48
52 struct Auto
53 {
54 inline bool operator==(const Auto & rhs) const = default;
55 inline auto operator<=>(const Auto & rhs) const = default;
56 };
57
62 struct Specified
63 {
64 std::string scheme;
65 std::string authority = "";
66
67 bool operator==(const Specified & rhs) const = default;
68 auto operator<=>(const Specified & rhs) const = default;
69 };
70
74 struct Daemon : Specified
75 {
76 Daemon()
77 : Specified({.scheme = "unix"})
78 {
79 }
80 };
81
85 struct Local : Specified
86 {
87 Local()
88 : Specified({.scheme = "local"})
89 {
90 }
91 };
92
93 typedef std::variant<Auto, Specified, Daemon, Local> Variant;
94
95 Variant variant;
96
97 Params params;
98
99 bool operator==(const StoreReference & rhs) const = default;
100 auto operator<=>(const StoreReference & rhs) const = default;
101
105 std::string render(bool withParams = true) const;
106
107 std::string to_string() const
108 {
109 return render();
110 }
111
115 static StoreReference parse(const std::string & uri, const Params & extraParams = Params{});
116};
117
118static inline std::ostream & operator<<(std::ostream & os, const StoreReference & ref)
119{
120 return os << ref.render();
121}
122
126std::pair<std::string, StoreReference::Params> splitUriAndParams(const std::string & uri);
127
128template<>
129struct json_avoids_null<StoreReference> : std::true_type
130{};
131
132NIX_DECLARE_CONFIG_SERIALISER(StoreReference)
133NIX_DECLARE_CONFIG_SERIALISER(std::vector<StoreReference>)
134NIX_DECLARE_CONFIG_SERIALISER(std::set<StoreReference>)
135
136} // namespace nix
137
138JSON_IMPL(nix::StoreReference)
Definition ref.hh:58
std::pair< std::string, StoreReference::Params > splitUriAndParams(const std::string &uri)
Definition store-reference.cc:176
std::string render(bool withParams=true) const
Definition store-reference.hh:53
Definition store-reference.hh:63
std::map< std::string, std::string, std::less<> > StringMap
Definition types.hh:26