2018-10-12 21:38:54 +00:00
|
|
|
{ config, lib, pkgs, ... }: with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.dnscrypt-proxy2;
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
options.services.dnscrypt-proxy2 = {
|
2022-08-28 19:18:44 +00:00
|
|
|
enable = mkEnableOption (lib.mdDoc "dnscrypt-proxy2");
|
2018-10-12 21:38:54 +00:00
|
|
|
|
|
|
|
settings = mkOption {
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
2018-10-12 21:38:54 +00:00
|
|
|
Attrset that is converted and passed as TOML config file.
|
2022-07-28 21:19:15 +00:00
|
|
|
For available params, see: <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
|
|
|
'';
|
2021-10-03 16:06:03 +00:00
|
|
|
example = literalExpression ''
|
2018-10-12 21:38:54 +00:00
|
|
|
{
|
|
|
|
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 {
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
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>)
|
2020-03-14 13:42:52 +00:00
|
|
|
|
|
|
|
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 {
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
Path to TOML config file. See: <https://github.com/DNSCrypt/dnscrypt-proxy/blob/master/dnscrypt-proxy/example-dnscrypt-proxy.toml>
|
2018-10-12 21:38:54 +00:00
|
|
|
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
|
|
|
'';
|
2022-08-20 20:27:20 +00:00
|
|
|
defaultText = literalMD "TOML file generated from {option}`services.dnscrypt-proxy2.settings`";
|
2018-10-12 21:38:54 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
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"
|
|
|
|
"~@setuid"
|
|
|
|
"~@timer"
|
2020-09-28 11:41:20 +00:00
|
|
|
];
|
2018-10-12 21:38:54 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2021-11-18 23:26:27 +00:00
|
|
|
|
|
|
|
# uses attributes of the linked package
|
|
|
|
meta.buildDocsInSandbox = false;
|
2018-10-12 21:38:54 +00:00
|
|
|
}
|