2021-10-25 13:53:01 +00:00
|
|
|
#include "experimental-features.hh"
|
2021-10-26 12:29:48 +00:00
|
|
|
#include "util.hh"
|
|
|
|
|
2021-10-25 13:53:01 +00:00
|
|
|
#include "nlohmann/json.hpp"
|
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
|
|
|
std::map<ExperimentalFeature, std::string> stringifiedXpFeatures = {
|
|
|
|
{ Xp::CaDerivations, "ca-derivations" },
|
|
|
|
{ Xp::Flakes, "flakes" },
|
|
|
|
{ Xp::NixCommand, "nix-command" },
|
|
|
|
{ Xp::RecursiveNix, "recursive-nix" },
|
|
|
|
{ Xp::NoUrlLiterals, "no-url-literals" },
|
|
|
|
};
|
|
|
|
|
|
|
|
const std::optional<ExperimentalFeature> parseExperimentalFeature(const std::string_view & name)
|
|
|
|
{
|
|
|
|
using ReverseXpMap = std::map<std::string_view, ExperimentalFeature>;
|
2021-10-26 12:29:48 +00:00
|
|
|
|
|
|
|
static auto reverseXpMap = []()
|
|
|
|
{
|
|
|
|
auto reverseXpMap = std::make_unique<ReverseXpMap>();
|
2021-10-25 13:53:01 +00:00
|
|
|
for (auto & [feature, name] : stringifiedXpFeatures)
|
|
|
|
(*reverseXpMap)[name] = feature;
|
2021-10-26 12:29:48 +00:00
|
|
|
return reverseXpMap;
|
|
|
|
}();
|
2021-10-25 13:53:01 +00:00
|
|
|
|
2021-10-26 12:29:48 +00:00
|
|
|
if (auto feature = get(*reverseXpMap, name))
|
|
|
|
return *feature;
|
|
|
|
else
|
2021-10-25 13:53:01 +00:00
|
|
|
return std::nullopt;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string_view showExperimentalFeature(const ExperimentalFeature feature)
|
|
|
|
{
|
|
|
|
return stringifiedXpFeatures.at(feature);
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
2021-10-26 12:29:48 +00:00
|
|
|
{}
|
2021-10-25 13:53:01 +00:00
|
|
|
|
|
|
|
std::ostream & operator <<(std::ostream & str, const ExperimentalFeature & feature)
|
|
|
|
{
|
|
|
|
return str << showExperimentalFeature(feature);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|