aboutsummaryrefslogtreecommitdiff
path: root/src/libfetchers/fetch-settings.cc
blob: 007f2725f2a1e2a8fef30d4115ead4c464059da7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "abstract-setting-to-json.hh"
#include "args.hh"
#include "config-impl.hh"
#include "fetch-settings.hh"

#include <nlohmann/json.hpp>

namespace nix {

template<> AcceptFlakeConfig BaseSetting<AcceptFlakeConfig>::parse(const std::string & str, const ApplyConfigOptions & options) const
{
    if (str == "true") return AcceptFlakeConfig::True;
    else if (str == "ask") return AcceptFlakeConfig::Ask;
    else if (str == "false") return AcceptFlakeConfig::False;
    else throw UsageError("option '%s' has invalid value '%s'", name, str);
}

template<> std::string BaseSetting<AcceptFlakeConfig>::to_string() const
{
    if (value == AcceptFlakeConfig::True) return "true";
    else if (value == AcceptFlakeConfig::Ask) return "ask";
    else if (value == AcceptFlakeConfig::False) return "false";
    else abort();
}

template<> void BaseSetting<AcceptFlakeConfig>::convertToArg(Args & args, const std::string & category)
{
    args.addFlag({
        .longName = name,
        .description = "Accept Lix configuration options from flakes without confirmation. This allows flakes to gain root access to your machine if you are a trusted user; see the nix.conf manual page for more details.",
        .category = category,
        .handler = {[this]() { override(AcceptFlakeConfig::True); }}
    });
    args.addFlag({
        .longName = "ask-" + name,
        .description = "Ask whether to accept Lix configuration options from flakes.",
        .category = category,
        .handler = {[this]() { override(AcceptFlakeConfig::Ask); }}
    });
    args.addFlag({
        .longName = "no-" + name,
        .description = "Reject Lix configuration options from flakes.",
        .category = category,
        .handler = {[this]() { override(AcceptFlakeConfig::False); }}
    });
}

FetchSettings::FetchSettings()
{
}

FetchSettings fetchSettings;

static GlobalConfig::Register rFetchSettings(&fetchSettings);

}