aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoralois31 <alois1@gmx-topmail.de>2024-09-09 16:14:23 +0000
committerGerrit Code Review <gerrit@localhost>2024-09-09 16:14:23 +0000
commit8f7ab26f96ec025db3f922fc50f5184167662596 (patch)
treead5613548fae7201fe6ad96a300021673f296559 /src
parentc14486ae8d3bbc862c625d948a6b2f4dc0927d5b (diff)
parent63ee2cdda36e48f932dd5a1ae7f35f85687ce1f5 (diff)
Merge changes If8ec210f,I6e2851b2 into main
* changes: libfetchers: serialise accept-flake-config properly libstore: declare SandboxMode JSON serialisation in the header
Diffstat (limited to 'src')
-rw-r--r--src/libfetchers/fetch-settings.cc26
-rw-r--r--src/libfetchers/fetch-settings.hh3
-rw-r--r--src/libstore/globals.cc30
-rw-r--r--src/libstore/globals.hh3
4 files changed, 57 insertions, 5 deletions
diff --git a/src/libfetchers/fetch-settings.cc b/src/libfetchers/fetch-settings.cc
index 007f2725f..b278835ad 100644
--- a/src/libfetchers/fetch-settings.cc
+++ b/src/libfetchers/fetch-settings.cc
@@ -7,6 +7,32 @@
namespace nix {
+void to_json(nlohmann::json & j, const AcceptFlakeConfig & e)
+{
+ if (e == AcceptFlakeConfig::False) {
+ j = false;
+ } else if (e == AcceptFlakeConfig::Ask) {
+ j = "ask";
+ } else if (e == AcceptFlakeConfig::True) {
+ j = true;
+ } else {
+ abort();
+ }
+}
+
+void from_json(const nlohmann::json & j, AcceptFlakeConfig & e)
+{
+ if (j == false) {
+ e = AcceptFlakeConfig::False;
+ } else if (j == "ask") {
+ e = AcceptFlakeConfig::Ask;
+ } else if (j == true) {
+ e = AcceptFlakeConfig::True;
+ } else {
+ throw Error("Invalid accept-flake-config value '%s'", std::string(j));
+ }
+}
+
template<> AcceptFlakeConfig BaseSetting<AcceptFlakeConfig>::parse(const std::string & str, const ApplyConfigOptions & options) const
{
if (str == "true") return AcceptFlakeConfig::True;
diff --git a/src/libfetchers/fetch-settings.hh b/src/libfetchers/fetch-settings.hh
index 93123463c..0bdc707ec 100644
--- a/src/libfetchers/fetch-settings.hh
+++ b/src/libfetchers/fetch-settings.hh
@@ -13,6 +13,9 @@ namespace nix {
enum class AcceptFlakeConfig { False, Ask, True };
+void to_json(nlohmann::json & j, const AcceptFlakeConfig & e);
+void from_json(const nlohmann::json & j, AcceptFlakeConfig & e);
+
struct FetchSettings : public Config
{
FetchSettings();
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 94aa60825..bfba6ab01 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,