Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Loading...
Searching...
No Matches
attrs.hh
Go to the documentation of this file.
1#pragma once
3
4#include "nix/util/types.hh"
5#include "nix/util/hash.hh"
6#include "nix/util/ref.hh"
7#include "nix/util/fun.hh"
8
9#include <variant>
10
11#include <nlohmann/json_fwd.hpp>
12
13#include <optional>
14
15namespace nix::fetchers {
16
20using ResolvedAttr = std::variant<std::string, uint64_t, Explicit<bool>>;
21
26{
27 fun<ResolvedAttr()> compute;
28};
29
30class LazyAttr
31{
33
34public:
35 LazyAttr(ref<LazyAttrComputation> inner)
36 : inner(std::move(inner))
37 {
38 }
39
40 ResolvedAttr compute() const
41 {
42 return inner->compute();
43 }
44
45 bool operator==(const LazyAttr & other) const = delete;
46 std::strong_ordering operator<=>(const LazyAttr & other) const = delete;
47};
48
55struct Attr : std::variant<std::string, uint64_t, Explicit<bool>, LazyAttr>
56{
57 using variant::variant;
58
59 bool operator==(const Attr & other) const;
60 std::strong_ordering operator<=>(const Attr & other) const;
61};
62
68typedef std::map<std::string, Attr> Attrs;
69
73ResolvedAttr forceAttr(const Attr & attr);
74
78std::optional<LazyAttr> maybeGetLazyAttr(const Attrs & attrs, const std::string & name);
79
80Attrs jsonToAttrs(const nlohmann::json & json);
81
82nlohmann::json attrsToJSON(const Attrs & attrs);
83
84std::optional<std::string> maybeGetStrAttr(const Attrs & attrs, const std::string & name);
85
86std::string getStrAttr(const Attrs & attrs, const std::string & name);
87
88std::optional<uint64_t> maybeGetIntAttr(const Attrs & attrs, const std::string & name);
89
90uint64_t getIntAttr(const Attrs & attrs, const std::string & name);
91
92std::optional<bool> maybeGetBoolAttr(const Attrs & attrs, const std::string & name);
93
94bool getBoolAttr(const Attrs & attrs, const std::string & name);
95
96StringMap attrsToQuery(const Attrs & attrs);
97
98Hash getRevAttr(const Attrs & attrs, const std::string & name);
99
100} // namespace nix::fetchers
std::map< std::string, Attr > Attrs
Definition attrs.hh:68
std::variant< std::string, uint64_t, Explicit< bool > > ResolvedAttr
Definition attrs.hh:20
Definition fun.hh:19
Definition ref.hh:58
Definition hash.hh:58
Definition attrs.hh:56
std::map< std::string, std::string, std::less<> > StringMap
Definition types.hh:26