diff options
Diffstat (limited to 'src/libexpr/flake/config.cc')
-rw-r--r-- | src/libexpr/flake/config.cc | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/src/libexpr/flake/config.cc b/src/libexpr/flake/config.cc index 41b6f78ed..a811e59a1 100644 --- a/src/libexpr/flake/config.cc +++ b/src/libexpr/flake/config.cc @@ -1,4 +1,6 @@ #include "flake.hh" +#include "globals.hh" +#include "fetch-settings.hh" #include <nlohmann/json.hpp> @@ -37,11 +39,11 @@ void ConfigFile::apply() // FIXME: Move into libutil/config.cc. std::string valueS; - if (auto s = std::get_if<std::string>(&value)) + if (auto* s = std::get_if<std::string>(&value)) valueS = *s; - else if (auto n = std::get_if<int64_t>(&value)) - valueS = fmt("%d", n); - else if (auto b = std::get_if<Explicit<bool>>(&value)) + else if (auto* n = std::get_if<int64_t>(&value)) + valueS = fmt("%d", *n); + else if (auto* b = std::get_if<Explicit<bool>>(&value)) valueS = b->t ? "true" : "false"; else if (auto ss = std::get_if<std::vector<std::string>>(&value)) valueS = concatStringsSep(" ", *ss); // FIXME: evil @@ -52,21 +54,19 @@ void ConfigFile::apply() auto trustedList = readTrustedList(); bool trusted = false; - - if (auto saved = get(get(trustedList, name).value_or(std::map<std::string, bool>()), valueS)) { + if (nix::fetchSettings.acceptFlakeConfig){ + trusted = true; + } else if (auto saved = get(get(trustedList, name).value_or(std::map<std::string, bool>()), valueS)) { trusted = *saved; + warn("Using saved setting for '%s = %s' from ~/.local/share/nix/trusted-settings.json.", name,valueS); } else { // FIXME: filter ANSI escapes, newlines, \r, etc. - if (std::tolower(logger->ask(fmt("do you want to allow configuration setting '%s' to be set to '" ANSI_RED "%s" ANSI_NORMAL "' (y/N)?", name, valueS)).value_or('n')) != 'y') { - if (std::tolower(logger->ask("do you want to permanently mark this value as untrusted (y/N)?").value_or('n')) == 'y') { - trustedList[name][valueS] = false; - writeTrustedList(trustedList); - } - } else { - if (std::tolower(logger->ask("do you want to permanently mark this value as trusted (y/N)?").value_or('n')) == 'y') { - trustedList[name][valueS] = trusted = true; - writeTrustedList(trustedList); - } + if (std::tolower(logger->ask(fmt("do you want to allow configuration setting '%s' to be set to '" ANSI_RED "%s" ANSI_NORMAL "' (y/N)?", name, valueS)).value_or('n')) == 'y') { + trusted = true; + } + if (std::tolower(logger->ask(fmt("do you want to permanently mark this value as %s (y/N)?", trusted ? "trusted": "untrusted" )).value_or('n')) == 'y') { + trustedList[name][valueS] = trusted; + writeTrustedList(trustedList); } } |