10 cfg = config.services.dnscrypt-proxy2;
14 options.services.dnscrypt-proxy2 = {
15 enable = mkEnableOption "dnscrypt-proxy2";
19 Attrset that is converted and passed as TOML config file.
20 For available params, see: <https://github.com/DNSCrypt/dnscrypt-proxy/blob/${pkgs.dnscrypt-proxy.version}/dnscrypt-proxy/example-dnscrypt-proxy.toml>
22 example = literalExpression ''
24 sources.public-resolvers = {
25 urls = [ "https://download.dnscrypt.info/resolvers-list/v2/public-resolvers.md" ];
26 cache_file = "public-resolvers.md";
27 minisign_key = "RWQf6LRCGA9i53mlYecO4IzT51TGPpvWucNSCh1CBM0QTaLn73Y7GFO3";
36 upstreamDefaults = mkOption {
38 Whether to base the config declared in {option}`services.dnscrypt-proxy2.settings` on the upstream example config (<https://github.com/DNSCrypt/dnscrypt-proxy/blob/master/dnscrypt-proxy/example-dnscrypt-proxy.toml>)
40 Disable this if you want to declare your dnscrypt config from scratch.
46 configFile = mkOption {
48 Path to TOML config file. See: <https://github.com/DNSCrypt/dnscrypt-proxy/blob/master/dnscrypt-proxy/example-dnscrypt-proxy.toml>
49 If this option is set, it will override any configuration done in options.services.dnscrypt-proxy2.settings.
51 example = "/etc/dnscrypt-proxy/dnscrypt-proxy.toml";
54 pkgs.runCommand "dnscrypt-proxy.toml"
56 json = builtins.toJSON cfg.settings;
57 passAsFile = [ "json" ];
61 if cfg.upstreamDefaults then
63 ${pkgs.buildPackages.remarshal}/bin/toml2json ${pkgs.dnscrypt-proxy.src}/dnscrypt-proxy/example-dnscrypt-proxy.toml > example.json
64 ${pkgs.buildPackages.jq}/bin/jq --slurp add example.json $jsonPath > config.json # merges the two
68 cp $jsonPath config.json
71 ${pkgs.buildPackages.remarshal}/bin/json2toml < config.json > $out
73 defaultText = literalMD "TOML file generated from {option}`services.dnscrypt-proxy2.settings`";
77 config = mkIf cfg.enable {
79 networking.nameservers = lib.mkDefault [ "127.0.0.1" ];
81 systemd.services.dnscrypt-proxy2 = {
82 description = "DNSCrypt-proxy client";
84 "network-online.target"
94 AmbientCapabilities = "CAP_NET_BIND_SERVICE";
95 CacheDirectory = "dnscrypt-proxy";
97 ExecStart = "${pkgs.dnscrypt-proxy}/bin/dnscrypt-proxy -config ${cfg.configFile}";
98 LockPersonality = true;
99 LogsDirectory = "dnscrypt-proxy";
100 MemoryDenyWriteExecute = true;
101 NoNewPrivileges = true;
103 PrivateDevices = true;
105 ProtectControlGroups = true;
107 ProtectHostname = true;
108 ProtectKernelLogs = true;
109 ProtectKernelModules = true;
110 ProtectKernelTunables = true;
111 ProtectSystem = "strict";
113 RestrictAddressFamilies = [
117 RestrictNamespaces = true;
118 RestrictRealtime = true;
119 RuntimeDirectory = "dnscrypt-proxy";
120 StateDirectory = "dnscrypt-proxy";
121 SystemCallArchitectures = "native";
135 # uses attributes of the linked package
136 meta.buildDocsInSandbox = false;