1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
#include "experimental-features.hh"
#include "util.hh"
#include "nlohmann/json.hpp"
namespace nix {
struct ExperimentalFeatureDetails
{
ExperimentalFeature tag;
std::string_view name;
std::string_view description;
};
constexpr std::array<ExperimentalFeatureDetails, 11> xpFeatureDetails = {{
{
.tag = Xp::CaDerivations,
.name = "ca-derivations",
.description = R"(
Allows derivations to be content-addressed in order to prevent rebuilds
when changes to the derivation do not result in changes to the
derivation's output. See
[__contentAddressed](../language/advanced-attributes.md#adv-attr-__contentAddressed)
for more info.
)",
},
{
.tag = Xp::ImpureDerivations,
.name = "impure-derivations",
.description = R"(
Allows derivations to produce non-fixed outputs by setting the `__impure`
derivation attribute to `true`. See [these release
notes](../release-notes/rl-2.8.md) for an example.
)",
},
{
.tag = Xp::Flakes,
.name = "flakes",
.description = R"(
Allows for derivations to be packaged in flakes. See the manual entry for
[`nix flake`](../command-ref/new-cli/nix3-flake.md) or this [detailed
introduction](https://www.tweag.io/blog/2020-05-25-flakes/) for more info.
)",
},
{
.tag = Xp::NixCommand,
.name = "nix-command",
.description = R"(
Allows the usage of the new `nix` CLI subcommands, such as `nix build`, `nix
develop`, `nix run`, etc. See the manual for
[`nix`](../command-ref/new-cli/nix.md) for more info.
)",
},
{
.tag = Xp::RecursiveNix,
.name = "recursive-nix",
.description = R"(
Allow Nix derivations to call Nix in order to recursively build derivations.
See [this
commit](https://github.com/edolstra/nix/commit/1a27aa7d64ffe6fc36cfca4d82bdf51c4d8cf717)
for more info.
)",
},
{
.tag = Xp::NoUrlLiterals,
.name = "no-url-literals",
.description = R"(
Disallows unquoted URLs as part of the Nix language syntax. See [RFC
45](https://github.com/NixOS/rfcs/pull/45) for more info.
)",
},
{
.tag = Xp::FetchClosure,
.name = "fetch-closure",
.description = R"(
Enables the use of the `fetchClosure` function in the standard library. See
the docs for [`fetchClosure`](../language/builtins.md#builtins-fetchClosure)
for more info.
)",
},
{
.tag = Xp::ReplFlake,
.name = "repl-flake",
.description = R"(
Allows the user to enter a Nix REPL within a flake, e.g. `nix repl nixpkgs`
or `nix repl .#foo`.
)",
},
{
.tag = Xp::AutoAllocateUids,
.name = "auto-allocate-uids",
.description = R"(
Allows Nix to automatically pick UIDs for builds, rather than creating
`nixbld*` user accounts. See [here](#conf-auto-allocate-uids) for more info.
)",
},
{
.tag = Xp::Cgroups,
.name = "cgroups",
.description = R"(
Allows Nix to execute builds inside cgroups. See
[`use-cgroups`](#conf-use-cgroups) for more info.
)",
},
{
.tag = Xp::DiscardReferences,
.name = "discard-references",
.description = R"(
Enables the use of the `unsafeDiscardReferences` attribute in derivations
that use structured attributes. This disables scanning of outputs for
runtime dependencies.
)",
},
}};
static_assert(
[]() constexpr {
for (auto [index, feature] : enumerate(xpFeatureDetails))
if (index != (size_t)feature.tag)
return false;
return true;
}(),
"array order does not match enum tag order");
const std::optional<ExperimentalFeature> parseExperimentalFeature(const std::string_view & name)
{
using ReverseXpMap = std::map<std::string_view, ExperimentalFeature>;
static std::unique_ptr<ReverseXpMap> reverseXpMap = [](){
auto reverseXpMap = std::make_unique<ReverseXpMap>();
for (auto & xpFeature : xpFeatureDetails)
(*reverseXpMap)[xpFeature.name] = xpFeature.tag;
return reverseXpMap;
}();
if (auto feature = get(*reverseXpMap, name))
return *feature;
else
return std::nullopt;
}
std::string_view showExperimentalFeature(const ExperimentalFeature tag)
{
assert((size_t)tag < xpFeatureDetails.size());
return xpFeatureDetails[(size_t)tag].name;
}
std::string getExperimentalFeaturesList() {
std::string experimentalFeaturesList = R"(
Experimental Nix features to enable.
Current experimental features are the following:
)";
for (auto & xpFeature : xpFeatureDetails) {
experimentalFeaturesList += std::string {}
/* length of this first string must be 12, matching the indent of
the descriptions in the xpFeatureDetails literal. FIXME compute
markdown in a less hacky way. */
+ " - "
+ "`" + xpFeature.name + "`"
+ "\n"
+ xpFeature.description
+ "\n\n";
}
return experimentalFeaturesList;
}
std::set<ExperimentalFeature> parseFeatures(const std::set<std::string> & rawFeatures)
{
std::set<ExperimentalFeature> res;
for (auto & rawFeature : rawFeatures)
if (auto feature = parseExperimentalFeature(rawFeature))
res.insert(*feature);
return res;
}
MissingExperimentalFeature::MissingExperimentalFeature(ExperimentalFeature feature)
: Error("experimental Nix feature '%1%' is disabled; use '--extra-experimental-features %1%' to override", showExperimentalFeature(feature))
, missingFeature(feature)
{}
std::ostream & operator <<(std::ostream & str, const ExperimentalFeature & feature)
{
return str << showExperimentalFeature(feature);
}
void to_json(nlohmann::json & j, const ExperimentalFeature & feature)
{
j = showExperimentalFeature(feature);
}
void from_json(const nlohmann::json & j, ExperimentalFeature & feature)
{
const std::string input = j;
const auto parsed = parseExperimentalFeature(input);
if (parsed.has_value())
feature = *parsed;
else
throw Error("Unknown experimental feature '%s' in JSON input", input);
}
}
|