aboutsummaryrefslogtreecommitdiff
path: root/src/libfetchers
diff options
context:
space:
mode:
authorAlois Wohlschlager <alois1@gmx-topmail.de>2024-08-20 19:36:49 +0200
committerAlois Wohlschlager <alois1@gmx-topmail.de>2024-09-02 18:50:15 +0200
commit63ee2cdda36e48f932dd5a1ae7f35f85687ce1f5 (patch)
tree30a3f2b2e35f7161af378a34d66d9bbbb1fddd5c /src/libfetchers
parentd7c37324bb77f8348a11f7fbf168fc1a085f2505 (diff)
libfetchers: serialise accept-flake-config properly
The AcceptFlakeConfig type used was missing its JSON serialisation definition, so it was incorrectly serialised as an integer, ending up that way for example in the nix.conf manual page. Declare a proper serialisation. Change-Id: If8ec210f9d4dd42fe480c4e97d0a4920eb66a01e
Diffstat (limited to 'src/libfetchers')
-rw-r--r--src/libfetchers/fetch-settings.cc26
-rw-r--r--src/libfetchers/fetch-settings.hh3
2 files changed, 29 insertions, 0 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();