aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlois Wohlschlager <alois1@gmx-topmail.de>2024-08-24 14:39:45 +0200
committerAlois Wohlschlager <alois1@gmx-topmail.de>2024-09-02 18:50:14 +0200
commitd7c37324bb77f8348a11f7fbf168fc1a085f2505 (patch)
treedc3c52c4c6cdca33be0201f453329cd14d5ef136 /src
parent02eb07cfd539c34c080cb1baf042e5e780c1fcc2 (diff)
libstore: declare SandboxMode JSON serialisation in the header
The JSON serialisation should be declared in the header so that all translation units can see it when needed, even though it seems that it has not been used anywhere else so far. Unfortunately, this means we cannot use the NLOHMANN_JSON_SERIALIZE_ENUM convenience macro, since it uses a slightly different signature, but the code is not too bad either. Change-Id: I6e2851b250e0b53114d2fecb8011ff1ea9379d0f
Diffstat (limited to 'src')
-rw-r--r--src/libstore/globals.cc30
-rw-r--r--src/libstore/globals.hh3
2 files changed, 28 insertions, 5 deletions
diff --git a/src/libstore/globals.cc b/src/libstore/globals.cc
index c114e22dc..ffc2543ef 100644
--- a/src/libstore/globals.cc
+++ b/src/libstore/globals.cc
@@ -269,11 +269,31 @@ Path Settings::getDefaultSSLCertFile()
const std::string nixVersion = PACKAGE_VERSION;
-NLOHMANN_JSON_SERIALIZE_ENUM(SandboxMode, {
- {SandboxMode::smEnabled, true},
- {SandboxMode::smRelaxed, "relaxed"},
- {SandboxMode::smDisabled, false},
-});
+void to_json(nlohmann::json & j, const SandboxMode & e)
+{
+ if (e == SandboxMode::smEnabled) {
+ j = true;
+ } else if (e == SandboxMode::smRelaxed) {
+ j = "relaxed";
+ } else if (e == SandboxMode::smDisabled) {
+ j = false;
+ } else {
+ abort();
+ }
+}
+
+void from_json(const nlohmann::json & j, SandboxMode & e)
+{
+ if (j == true) {
+ e = SandboxMode::smEnabled;
+ } else if (j == "relaxed") {
+ e = SandboxMode::smRelaxed;
+ } else if (j == false) {
+ e = SandboxMode::smDisabled;
+ } else {
+ throw Error("Invalid sandbox mode '%s'", std::string(j));
+ }
+}
template<> SandboxMode BaseSetting<SandboxMode>::parse(const std::string & str, const ApplyConfigOptions & options) const
{
diff --git a/src/libstore/globals.hh b/src/libstore/globals.hh
index 51550b2c3..ca2a917ed 100644
--- a/src/libstore/globals.hh
+++ b/src/libstore/globals.hh
@@ -14,6 +14,9 @@ namespace nix {
typedef enum { smEnabled, smRelaxed, smDisabled } SandboxMode;
+void to_json(nlohmann::json & j, const SandboxMode & e);
+void from_json(const nlohmann::json & j, SandboxMode & e);
+
struct MaxBuildJobsSetting : public BaseSetting<unsigned int>
{
MaxBuildJobsSetting(Config * options,