Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Loading...
Searching...
No Matches
nar-info.hh
Go to the documentation of this file.
1#pragma once
3
5#include "nix/util/types.hh"
6#include "nix/util/hash.hh"
8
9namespace nix {
10
11struct StoreDirConfig;
12
13struct UnkeyedNarInfo : virtual UnkeyedValidPathInfo
14{
15 std::string url;
16 std::optional<CompressionAlgo> compression;
17 std::optional<Hash> fileHash;
18 uint64_t fileSize = 0;
19
20 UnkeyedNarInfo(UnkeyedValidPathInfo info)
21 : UnkeyedValidPathInfo(std::move(info))
22 {
23 }
24
25 bool operator==(const UnkeyedNarInfo &) const = default;
26 // TODO libc++ 16 (used by darwin) missing `std::optional::operator <=>`, can't do yet
27 // auto operator <=>(const NarInfo &) const = default;
28
29 nlohmann::json
30 toJSON(const StoreDirConfig * store, bool includeImpureInfo, PathInfoJsonFormat format) const override;
31 static UnkeyedNarInfo fromJSON(const StoreDirConfig * store, const nlohmann::json & json);
32};
33
37struct NarInfo : ValidPathInfo, UnkeyedNarInfo
38{
39private:
40 void anchor() override;
41
42public:
43 NarInfo() = delete;
44
45 NarInfo(ValidPathInfo info)
46 : UnkeyedValidPathInfo{static_cast<UnkeyedValidPathInfo &&>(info)}
47 /* Later copies from `*this` are pointless. The argument is only
48 there so the constructors can also call
49 `UnkeyedValidPathInfo`, but this won't happen since the base
50 class is virtual. Only this constructor (assuming it is most
51 derived) will initialize that virtual base class. */
52 , ValidPathInfo{info.path, static_cast<const UnkeyedValidPathInfo &>(*this)}
53 , UnkeyedNarInfo{static_cast<const UnkeyedValidPathInfo &>(*this)}
54 {
55 }
56
57 NarInfo(const StoreDirConfig & store, StorePath path, Hash narHash)
58 : NarInfo{ValidPathInfo{std::move(path), UnkeyedValidPathInfo{store, narHash}}}
59 {
60 }
61
62 NarInfo(std::string storeDir, StorePath path, Hash narHash)
63 : NarInfo{ValidPathInfo{std::move(path), UnkeyedValidPathInfo{std::move(storeDir), narHash}}}
64 {
65 }
66
67 static NarInfo
68 makeFromCA(const StoreDirConfig & store, std::string_view name, ContentAddressWithReferences ca, Hash narHash)
69 {
70 return ValidPathInfo::makeFromCA(store, std::move(name), std::move(ca), narHash);
71 }
72
73 NarInfo(const StoreDirConfig & store, const std::string & s, const std::string & whence);
74
75 bool operator==(const NarInfo &) const = default;
76
77 std::string to_string(const StoreDirConfig & store) const;
78};
79
80} // namespace nix
81
82JSON_IMPL(nix::UnkeyedNarInfo)
Definition path.hh:33
PathInfoJsonFormat
Definition path-info.hh:20
Definition content-address.hh:284
Definition hash.hh:58
Definition store-dir-config.hh:29
Definition nar-info.hh:14
nlohmann::json toJSON(const StoreDirConfig *store, bool includeImpureInfo, PathInfoJsonFormat format) const override
Definition nar-info.cc:145
Definition path-info.hh:58
std::string storeDir
Definition path-info.hh:65
std::optional< ContentAddress > ca
Definition path-info.hh:118
Hash narHash
Definition path-info.hh:75