1 { config, lib, pkgs, ... }: with lib;
4 cfg = config.services.dnscrypt-proxy2;
8 options.services.dnscrypt-proxy2 = {
9 enable = mkEnableOption "dnscrypt-proxy2";
13 Attrset that is converted and passed as TOML config file.
14 For available params, see: <https://github.com/DNSCrypt/dnscrypt-proxy/blob/${pkgs.dnscrypt-proxy.version}/dnscrypt-proxy/example-dnscrypt-proxy.toml>
16 example = literalExpression ''
18 sources.public-resolvers = {
19 urls = [ "https://download.dnscrypt.info/resolvers-list/v2/public-resolvers.md" ];
20 cache_file = "public-resolvers.md";
21 minisign_key = "RWQf6LRCGA9i53mlYecO4IzT51TGPpvWucNSCh1CBM0QTaLn73Y7GFO3";
30 upstreamDefaults = mkOption {
32 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>)
34 Disable this if you want to declare your dnscrypt config from scratch.
40 configFile = mkOption {
42 Path to TOML config file. See: <https://github.com/DNSCrypt/dnscrypt-proxy/blob/master/dnscrypt-proxy/example-dnscrypt-proxy.toml>
43 If this option is set, it will override any configuration done in options.services.dnscrypt-proxy2.settings.
45 example = "/etc/dnscrypt-proxy/dnscrypt-proxy.toml";
47 default = pkgs.runCommand "dnscrypt-proxy.toml" {
48 json = builtins.toJSON cfg.settings;
49 passAsFile = [ "json" ];
51 ${if cfg.upstreamDefaults then ''
52 ${pkgs.buildPackages.remarshal}/bin/toml2json ${pkgs.dnscrypt-proxy.src}/dnscrypt-proxy/example-dnscrypt-proxy.toml > example.json
53 ${pkgs.buildPackages.jq}/bin/jq --slurp add example.json $jsonPath > config.json # merges the two
55 cp $jsonPath config.json
57 ${pkgs.buildPackages.remarshal}/bin/json2toml < config.json > $out
59 defaultText = literalMD "TOML file generated from {option}`services.dnscrypt-proxy2.settings`";
63 config = mkIf cfg.enable {
65 networking.nameservers = lib.mkDefault [ "127.0.0.1" ];
67 systemd.services.dnscrypt-proxy2 = {
68 description = "DNSCrypt-proxy client";
70 "network-online.target"
80 AmbientCapabilities = "CAP_NET_BIND_SERVICE";
81 CacheDirectory = "dnscrypt-proxy";
83 ExecStart = "${pkgs.dnscrypt-proxy}/bin/dnscrypt-proxy -config ${cfg.configFile}";
84 LockPersonality = true;
85 LogsDirectory = "dnscrypt-proxy";
86 MemoryDenyWriteExecute = true;
87 NoNewPrivileges = true;
89 PrivateDevices = true;
91 ProtectControlGroups = true;
93 ProtectHostname = true;
94 ProtectKernelLogs = true;
95 ProtectKernelModules = true;
96 ProtectKernelTunables = true;
97 ProtectSystem = "strict";
99 RestrictAddressFamilies = [
103 RestrictNamespaces = true;
104 RestrictRealtime = true;
105 RuntimeDirectory = "dnscrypt-proxy";
106 StateDirectory = "dnscrypt-proxy";
107 SystemCallArchitectures = "native";
121 # uses attributes of the linked package
122 meta.buildDocsInSandbox = false;