2018-10-12 21:38:54 +00:00
|
|
|
{ config, lib, pkgs, ... }: with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.dnscrypt-proxy2;
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
options.services.dnscrypt-proxy2 = {
|
|
|
|
enable = mkEnableOption "dnscrypt-proxy2";
|
|
|
|
|
|
|
|
settings = mkOption {
|
|
|
|
description = ''
|
|
|
|
Attrset that is converted and passed as TOML config file.
|
2020-09-28 10:28:12 +00:00
|
|
|
For available params, see: <link xlink:href="https://github.com/DNSCrypt/dnscrypt-proxy/blob/${pkgs.dnscrypt-proxy2.version}/dnscrypt-proxy/example-dnscrypt-proxy.toml"/>
|
2018-10-12 21:38:54 +00:00
|
|
|
'';
|
|
|
|
example = literalExample ''
|
|
|
|
{
|
|
|
|
sources.public-resolvers = {
|
|
|
|
urls = [ "https://download.dnscrypt.info/resolvers-list/v2/public-resolvers.md" ];
|
|
|
|
cache_file = "public-resolvers.md";
|
|
|
|
minisign_key = "RWQf6LRCGA9i53mlYecO4IzT51TGPpvWucNSCh1CBM0QTaLn73Y7GFO3";
|
|
|
|
refresh_delay = 72;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
type = types.attrs;
|
|
|
|
default = {};
|
|
|
|
};
|
|
|
|
|
2020-03-14 13:42:52 +00:00
|
|
|
upstreamDefaults = mkOption {
|
|
|
|
description = ''
|
|
|
|
Whether to base the config declared in <literal>services.dnscrypt-proxy2.settings</literal> on the upstream example config (<link xlink:href="https://github.com/DNSCrypt/dnscrypt-proxy/blob/master/dnscrypt-proxy/example-dnscrypt-proxy.toml"/>)
|
|
|
|
|
|
|
|
Disable this if you want to declare your dnscrypt config from scratch.
|
|
|
|
'';
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
};
|
|
|
|
|
2018-10-12 21:38:54 +00:00
|
|
|
configFile = mkOption {
|
|
|
|
description = ''
|
|
|
|
Path to TOML config file. See: <link xlink:href="https://github.com/DNSCrypt/dnscrypt-proxy/blob/master/dnscrypt-proxy/example-dnscrypt-proxy.toml"/>
|
|
|
|
If this option is set, it will override any configuration done in options.services.dnscrypt-proxy2.settings.
|
|
|
|
'';
|
|
|
|
example = "/etc/dnscrypt-proxy/dnscrypt-proxy.toml";
|
|
|
|
type = types.path;
|
|
|
|
default = pkgs.runCommand "dnscrypt-proxy.toml" {
|
|
|
|
json = builtins.toJSON cfg.settings;
|
|
|
|
passAsFile = [ "json" ];
|
|
|
|
} ''
|
2020-03-14 13:42:52 +00:00
|
|
|
${if cfg.upstreamDefaults then ''
|
|
|
|
${pkgs.remarshal}/bin/toml2json ${pkgs.dnscrypt-proxy2.src}/dnscrypt-proxy/example-dnscrypt-proxy.toml > example.json
|
|
|
|
${pkgs.jq}/bin/jq --slurp add example.json $jsonPath > config.json # merges the two
|
|
|
|
'' else ''
|
|
|
|
cp $jsonPath config.json
|
|
|
|
''}
|
|
|
|
${pkgs.remarshal}/bin/json2toml < config.json > $out
|
2018-10-12 21:38:54 +00:00
|
|
|
'';
|
|
|
|
defaultText = literalExample "TOML file generated from services.dnscrypt-proxy2.settings";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
|
|
|
networking.nameservers = lib.mkDefault [ "127.0.0.1" ];
|
|
|
|
|
|
|
|
systemd.services.dnscrypt-proxy2 = {
|
2020-09-28 11:41:20 +00:00
|
|
|
description = "DNSCrypt-proxy client";
|
|
|
|
wants = [
|
|
|
|
"network-online.target"
|
|
|
|
"nss-lookup.target"
|
|
|
|
];
|
|
|
|
before = [
|
|
|
|
"nss-lookup.target"
|
|
|
|
];
|
|
|
|
wantedBy = [
|
|
|
|
"multi-user.target"
|
|
|
|
];
|
2018-10-12 21:38:54 +00:00
|
|
|
serviceConfig = {
|
|
|
|
AmbientCapabilities = "CAP_NET_BIND_SERVICE";
|
2020-09-28 11:41:20 +00:00
|
|
|
CacheDirectory = "dnscrypt-proxy";
|
2018-10-12 21:38:54 +00:00
|
|
|
DynamicUser = true;
|
|
|
|
ExecStart = "${pkgs.dnscrypt-proxy2}/bin/dnscrypt-proxy -config ${cfg.configFile}";
|
2020-09-28 11:41:20 +00:00
|
|
|
LockPersonality = true;
|
|
|
|
LogsDirectory = "dnscrypt-proxy";
|
|
|
|
MemoryDenyWriteExecute = true;
|
|
|
|
NoNewPrivileges = true;
|
|
|
|
NonBlocking = true;
|
|
|
|
PrivateDevices = true;
|
2021-01-02 17:09:49 +00:00
|
|
|
ProtectClock = true;
|
2020-09-28 11:41:20 +00:00
|
|
|
ProtectControlGroups = true;
|
|
|
|
ProtectHome = true;
|
|
|
|
ProtectHostname = true;
|
|
|
|
ProtectKernelLogs = true;
|
|
|
|
ProtectKernelModules = true;
|
|
|
|
ProtectKernelTunables = true;
|
|
|
|
ProtectSystem = "strict";
|
2020-05-06 22:00:42 +00:00
|
|
|
Restart = "always";
|
2020-09-28 11:41:20 +00:00
|
|
|
RestrictAddressFamilies = [
|
|
|
|
"AF_INET"
|
|
|
|
"AF_INET6"
|
|
|
|
];
|
|
|
|
RestrictNamespaces = true;
|
|
|
|
RestrictRealtime = true;
|
|
|
|
RuntimeDirectory = "dnscrypt-proxy";
|
|
|
|
StateDirectory = "dnscrypt-proxy";
|
|
|
|
SystemCallArchitectures = "native";
|
|
|
|
SystemCallFilter = [
|
|
|
|
"@system-service"
|
|
|
|
"@chown"
|
2021-01-02 17:09:49 +00:00
|
|
|
"~@aio"
|
|
|
|
"~@keyring"
|
|
|
|
"~@memlock"
|
2020-09-28 11:41:20 +00:00
|
|
|
"~@resources"
|
2021-01-02 17:09:49 +00:00
|
|
|
"~@setuid"
|
|
|
|
"~@timer"
|
2020-09-28 11:41:20 +00:00
|
|
|
];
|
2018-10-12 21:38:54 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|