mirror of
https://github.com/NixOS/nix
synced 2024-09-19 10:50:24 -04:00
wip AdditionalAttributes
for DerivationOptions
This commit is contained in:
parent
b20e5f5b5d
commit
7c38df67a7
|
@ -1,8 +1,71 @@
|
|||
#include "derivation-options.hh"
|
||||
#include "json-utils.hh"
|
||||
#include "parsed-derivations.hh"
|
||||
#include "types.hh"
|
||||
#include "util.hh"
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <variant>
|
||||
|
||||
namespace nix {
|
||||
|
||||
std::optional<std::string> AdditionalAttributes::getStringAttr(const std::string & name) const
|
||||
{
|
||||
return std::visit(
|
||||
overloaded{
|
||||
[&](const nlohmann::json & json) -> std::optional<std::string> {
|
||||
if (!json.contains(name))
|
||||
return std::nullopt;
|
||||
|
||||
return std::optional{getString(valueAt(json, name))};
|
||||
},
|
||||
[&](const StringPairs & env) -> std::optional<std::string> {
|
||||
if (!env.contains(name))
|
||||
return std::nullopt;
|
||||
|
||||
return std::optional{env.at("name")};
|
||||
}},
|
||||
attrs);
|
||||
};
|
||||
|
||||
bool AdditionalAttributes::getBoolAttr(const std::string & name, bool def) const
|
||||
{
|
||||
return std::visit(
|
||||
overloaded{
|
||||
[&](const nlohmann::json & json) {
|
||||
if (!json.contains(name))
|
||||
return def;
|
||||
|
||||
return getBoolean(valueAt(json, name));
|
||||
},
|
||||
[&](const StringPairs & env) {
|
||||
if (!env.contains(name))
|
||||
return def;
|
||||
|
||||
return env.at(name) == "1";
|
||||
}},
|
||||
attrs);
|
||||
};
|
||||
|
||||
std::optional<Strings> AdditionalAttributes::getStringsAttr(const std::string & name) const
|
||||
{
|
||||
return std::visit(
|
||||
overloaded{
|
||||
[&](const nlohmann::json & json) -> std::optional<Strings> {
|
||||
if (!json.contains(name))
|
||||
return std::nullopt;
|
||||
|
||||
return std::optional{getStringList(valueAt(json, name))};
|
||||
},
|
||||
[&](const StringPairs & env) -> std::optional<Strings> {
|
||||
if (!env.contains(name))
|
||||
return std::nullopt;
|
||||
|
||||
return std::optional{tokenizeString<Strings>(env.at(name))};
|
||||
}},
|
||||
attrs);
|
||||
};
|
||||
|
||||
static std::map<std::string, DerivationOptions::OutputChecks> parseChecksPerOutput(const ParsedDerivation & parsed)
|
||||
{
|
||||
std::map<std::string, DerivationOptions::OutputChecks> res;
|
||||
|
@ -104,5 +167,4 @@ DerivationOptions DerivationOptions::fromEnv(const StringPairs & env, bool shoul
|
|||
.allowSubstitutes = parsed.getBoolAttr("allowSubstitutes", defaults.allowSubstitutes),
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,11 +2,24 @@
|
|||
///@file
|
||||
|
||||
#include <cstdint>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <optional>
|
||||
#include "types.hh"
|
||||
#include <variant>
|
||||
|
||||
namespace nix {
|
||||
|
||||
class AdditionalAttributes
|
||||
{
|
||||
typedef StringPairs Env;
|
||||
|
||||
std::variant<Env, nlohmann::json> attrs;
|
||||
|
||||
std::optional<std::string> getStringAttr(const std::string & name) const;
|
||||
bool getBoolAttr(const std::string & name, bool def = false) const;
|
||||
std::optional<Strings> getStringsAttr(const std::string & name) const;
|
||||
};
|
||||
|
||||
struct DerivationOptions
|
||||
{
|
||||
struct OutputChecks
|
||||
|
@ -52,6 +65,8 @@ struct DerivationOptions
|
|||
|
||||
OutputChecks checksAllOutputs;
|
||||
|
||||
AdditionalAttributes attrs;
|
||||
|
||||
/**
|
||||
* env: __sandboxProfile
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue