Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Loading...
Searching...
No Matches
realisation.hh
Go to the documentation of this file.
1#pragma once
3
4#include <variant>
5
6#include "nix/util/hash.hh"
8#include "nix/store/path.hh"
10#include <nlohmann/json_fwd.hpp>
12#include "nix/util/signature/signer.hh"
13
14namespace nix {
15
16class Store;
17struct OutputsSpec;
18
26{
31
36
40 std::string to_string() const;
41
45 static DrvOutput from_string(std::string_view);
46
50 std::string render(const StoreDirConfig & store) const;
51
55 static DrvOutput parse(const StoreDirConfig & store, std::string_view);
56
57 bool operator==(const DrvOutput &) const = default;
58 auto operator<=>(const DrvOutput &) const = default;
59};
60
62{
63 StorePath outPath;
64
65 std::set<Signature> signatures;
66
67 std::string fingerprint(const DrvOutput & key) const;
68
72 Signature sign(const DrvOutput & key, const Signer &) const;
73
77 void sign(const DrvOutput & key, const Signer &);
78
79 bool checkSignature(const DrvOutput & key, const PublicKeys & publicKeys, const Signature & sig) const;
80
81 size_t checkSignatures(const DrvOutput & key, const PublicKeys & publicKeys) const;
82
88 bool isCompatibleWith(const UnkeyedRealisation & other) const
89 {
90 return outPath == other.outPath;
91 }
92
93 const StorePath & getPath() const
94 {
95 return outPath;
96 }
97
98 // TODO sketchy that it avoids signatures
99 GENERATE_CMP(UnkeyedRealisation, me->outPath);
100};
101
103{
104 DrvOutput id;
105
106 bool operator==(const Realisation &) const = default;
107 auto operator<=>(const Realisation &) const = default;
108};
109
116typedef std::map<OutputName, UnkeyedRealisation> SingleDrvOutputs;
117
119{
120 StorePath path;
121
122 const StorePath & getPath() const &
123 {
124 return path;
125 }
126
127 bool operator==(const OpaquePath &) const = default;
128 auto operator<=>(const OpaquePath &) const = default;
129};
130
134struct RealisedPath
135{
140 using Raw = std::variant<Realisation, OpaquePath>;
141 Raw raw;
142
143 using Set = std::set<RealisedPath>;
144
145 RealisedPath(StorePath path)
146 : raw(OpaquePath{path})
147 {
148 }
149
151 : raw(r)
152 {
153 }
154
158 const StorePath & path() const &;
159
160 bool operator==(const RealisedPath &) const = default;
161 auto operator<=>(const RealisedPath &) const = default;
162};
163
164class MissingRealisation final : public CloneableError<MissingRealisation, Error>
165{
166 void anchor() override;
167
168public:
169 MissingRealisation(const StoreDirConfig & store, DrvOutput & outputId)
170 : MissingRealisation(store, outputId.drvPath, outputId.outputName)
171 {
172 }
173
174 MissingRealisation(const StoreDirConfig & store, const StorePath & drvPath, const OutputName & outputName);
175 MissingRealisation(
176 const StoreDirConfig & store,
177 const SingleDerivedPath & drvPath,
178 const StorePath & drvPathResolved,
179 const OutputName & outputName);
180};
181
182} // namespace nix
183
184template<>
185struct std::hash<nix::DrvOutput>
186{
187 std::size_t operator()(const nix::DrvOutput & id) const noexcept
188 {
189 std::size_t h = 0;
190 nix::hash_combine(h, id.drvPath, id.outputName);
191 return h;
192 }
193};
194
195namespace nix {
196
197inline std::size_t hash_value(const DrvOutput & id)
198{
199 return std::hash<DrvOutput>{}(id);
200}
201
202} // namespace nix
203
204JSON_IMPL(nix::DrvOutput)
205JSON_IMPL(nix::UnkeyedRealisation)
206JSON_IMPL(nix::Realisation)
Definition error.hh:310
Definition path.hh:33
Definition store-api.hh:397
#define GENERATE_CMP(args...)
Definition comparator.hh:39
std::string OutputName
Definition outputs-spec.hh:18
std::map< std::string, PublicKey > PublicKeys
Definition local-keys.hh:120
std::map< OutputName, UnkeyedRealisation > SingleDrvOutputs
Definition realisation.hh:116
void hash_combine(std::size_t &seed)
Definition std-hash.hh:17
Definition realisation.hh:26
StorePath drvPath
Definition realisation.hh:30
OutputName outputName
Definition realisation.hh:35
std::string to_string() const
Definition realisation.cc:31
static DrvOutput parse(const StoreDirConfig &store, std::string_view)
Definition realisation.cc:15
std::string render(const StoreDirConfig &store) const
Definition realisation.cc:26
static DrvOutput from_string(std::string_view)
Definition realisation.hh:119
Definition outputs-spec.hh:27
Definition realisation.hh:103
Definition realisation.hh:135
std::variant< Realisation, OpaquePath > Raw
Definition realisation.hh:140
const StorePath & path() const &
Definition realisation.cc:74
Definition local-keys.hh:16
Definition signer.hh:20
Definition derived-path.hh:105
Definition store-dir-config.hh:29
Definition realisation.hh:62
bool isCompatibleWith(const UnkeyedRealisation &other) const
Definition realisation.hh:88
Signature sign(const DrvOutput &key, const Signer &) const
Definition realisation.cc:45