Nix
2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Toggle main menu visibility
Loading...
Searching...
No Matches
lockfile.hh
Go to the documentation of this file.
1
#pragma once
3
4
#include "
nix/flake/flakeref.hh
"
5
6
#include <nlohmann/json_fwd.hpp>
7
8
namespace
nix {
9
class
Store
;
10
class
StorePath
;
11
}
// namespace nix
12
13
namespace
nix::flake {
14
15
typedef
std::vector<FlakeId> InputAttrPath;
16
24
class
NonEmptyInputAttrPath
25
{
26
InputAttrPath path;
27
28
explicit
NonEmptyInputAttrPath(InputAttrPath && p)
29
: path(std::move(p))
30
{
31
assert(!path.empty());
32
}
33
34
public
:
39
static
std::optional<NonEmptyInputAttrPath>
parse
(std::string_view s);
40
45
static
std::optional<NonEmptyInputAttrPath>
make
(InputAttrPath path);
46
51
static
NonEmptyInputAttrPath
append
(
const
InputAttrPath & prefix,
const
FlakeId & element)
52
{
53
InputAttrPath path = prefix;
54
path.push_back(element);
55
return
NonEmptyInputAttrPath{std::move(path)};
56
}
57
58
const
InputAttrPath &
get
()
const
59
{
60
return
path;
61
}
62
63
operator
const
InputAttrPath &()
const
64
{
65
return
path;
66
}
67
72
const
FlakeId &
inputName
()
const
73
{
74
return
path.back();
75
}
76
81
InputAttrPath
parent
()
const
82
{
83
InputAttrPath result = path;
84
result.pop_back();
85
return
result;
86
}
87
88
auto
operator<=>(
const
NonEmptyInputAttrPath
& other)
const
=
default
;
89
};
90
91
struct
LockedNode;
92
98
struct
Node
: std::enable_shared_from_this<Node>
99
{
100
typedef
std::variant<ref<LockedNode>, InputAttrPath> Edge;
101
102
std::map<FlakeId, Edge> inputs;
103
104
virtual
~Node
() {}
105
};
106
110
struct
LockedNode :
Node
111
{
112
FlakeRef
lockedRef, originalRef;
113
bool
isFlake =
true
;
114
115
/* The node relative to which relative source paths
116
(e.g. 'path:../foo') are interpreted. */
117
std::optional<InputAttrPath> parentInputAttrPath;
118
119
LockedNode(
120
const
FlakeRef
& lockedRef,
121
const
FlakeRef
& originalRef,
122
bool
isFlake =
true
,
123
std::optional<InputAttrPath> parentInputAttrPath = {})
124
: lockedRef(std::move(lockedRef))
125
, originalRef(std::move(originalRef))
126
, isFlake(isFlake)
127
, parentInputAttrPath(std::move(parentInputAttrPath))
128
{
129
}
130
131
LockedNode(
const
fetchers::Settings
& fetchSettings,
const
nlohmann::json & json);
132
133
StorePath
computeStorePath(
Store
& store)
const
;
134
};
135
136
struct
LockFile
137
{
138
ref<Node>
root = make_ref<Node>();
139
140
LockFile() {};
141
LockFile(
const
fetchers::Settings
& fetchSettings, std::string_view contents, std::string_view path);
142
143
typedef
std::map<ref<const Node>, std::string> KeyMap;
144
145
std::pair<nlohmann::json, KeyMap> toJSON()
const
;
146
147
std::pair<std::string, KeyMap> to_string()
const
;
148
153
std::optional<FlakeRef>
isUnlocked
(
const
fetchers::Settings
& fetchSettings)
const
;
154
155
bool
operator==(
const
LockFile & other)
const
;
156
157
std::shared_ptr<Node> findInput(
const
InputAttrPath & path);
158
159
std::map<InputAttrPath, Node::Edge> getAllInputs()
const
;
160
161
static
std::string diff(
const
LockFile & oldLocks,
const
LockFile & newLocks);
162
166
void
check
();
167
};
168
169
std::ostream & operator<<(std::ostream & stream,
const
LockFile
& lockFile);
170
171
InputAttrPath parseInputAttrPath(std::string_view s);
172
173
std::string printInputAttrPath(
const
InputAttrPath & path);
174
175
}
// namespace nix::flake
nix::StorePath
Definition
path.hh:33
nix::Store
Definition
store-api.hh:397
nix::flake::NonEmptyInputAttrPath
Definition
lockfile.hh:25
nix::flake::NonEmptyInputAttrPath::parent
InputAttrPath parent() const
Definition
lockfile.hh:81
nix::flake::NonEmptyInputAttrPath::inputName
const FlakeId & inputName() const
Definition
lockfile.hh:72
nix::flake::NonEmptyInputAttrPath::make
static std::optional< NonEmptyInputAttrPath > make(InputAttrPath path)
Definition
lockfile.cc:327
nix::flake::NonEmptyInputAttrPath::parse
static std::optional< NonEmptyInputAttrPath > parse(std::string_view s)
Definition
lockfile.cc:321
nix::flake::NonEmptyInputAttrPath::append
static NonEmptyInputAttrPath append(const InputAttrPath &prefix, const FlakeId &element)
Definition
lockfile.hh:51
nix::ref
Definition
ref.hh:58
flakeref.hh
nix::FlakeRef
Definition
flakeref.hh:44
nix::fetchers::Settings
Definition
fetch-settings.hh:27
nix::flake::LockFile
Definition
lockfile.hh:137
nix::flake::LockFile::isUnlocked
std::optional< FlakeRef > isUnlocked(const fetchers::Settings &fetchSettings) const
Definition
lockfile.cc:270
nix::flake::LockFile::check
void check()
Definition
lockfile.cc:418
nix::flake::Node
Definition
lockfile.hh:99
nix::get
const T * get(const std::optional< T > &opt)
Definition
util.hh:286
libflake
include
nix
flake
lockfile.hh
Generated by
1.18.0