2020-04-24 23:36:52 +00:00
|
|
|
{ config, lib, pkgs, ... }: with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.dnscrypt-proxy2;
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
options.services.dnscrypt-proxy2 = {
|
2022-09-09 14:08:57 +00:00
|
|
|
enable = mkEnableOption (lib.mdDoc "dnscrypt-proxy2");
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
settings = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Attrset that is converted and passed as TOML config file.
|
2023-10-09 19:29:22 +00:00
|
|
|
For available params, see: <https://github.com/DNSCrypt/dnscrypt-proxy/blob/${pkgs.dnscrypt-proxy.version}/dnscrypt-proxy/example-dnscrypt-proxy.toml>
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
2021-10-06 13:57:05 +00:00
|
|
|
example = literalExpression ''
|
2020-04-24 23:36:52 +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-12-25 13:55:36 +00:00
|
|
|
upstreamDefaults = mkOption {
|
2022-08-12 12:06:08 +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-12-25 13:55:36 +00:00
|
|
|
|
|
|
|
Disable this if you want to declare your dnscrypt config from scratch.
|
|
|
|
'';
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
};
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
configFile = mkOption {
|
2022-08-12 12:06:08 +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>
|
2020-04-24 23:36:52 +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-12-25 13:55:36 +00:00
|
|
|
${if cfg.upstreamDefaults then ''
|
2023-10-09 19:29:22 +00:00
|
|
|
${pkgs.remarshal}/bin/toml2json ${pkgs.dnscrypt-proxy.src}/dnscrypt-proxy/example-dnscrypt-proxy.toml > example.json
|
2020-12-25 13:55:36 +00:00
|
|
|
${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
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
2022-09-09 14:08:57 +00:00
|
|
|
defaultText = literalMD "TOML file generated from {option}`services.dnscrypt-proxy2.settings`";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
|
|
|
networking.nameservers = lib.mkDefault [ "127.0.0.1" ];
|
|
|
|
|
|
|
|
systemd.services.dnscrypt-proxy2 = {
|
2020-10-07 09:15:18 +00:00
|
|
|
description = "DNSCrypt-proxy client";
|
|
|
|
wants = [
|
|
|
|
"network-online.target"
|
|
|
|
"nss-lookup.target"
|
|
|
|
];
|
|
|
|
before = [
|
|
|
|
"nss-lookup.target"
|
|
|
|
];
|
|
|
|
wantedBy = [
|
|
|
|
"multi-user.target"
|
|
|
|
];
|
2020-04-24 23:36:52 +00:00
|
|
|
serviceConfig = {
|
|
|
|
AmbientCapabilities = "CAP_NET_BIND_SERVICE";
|
2020-10-07 09:15:18 +00:00
|
|
|
CacheDirectory = "dnscrypt-proxy";
|
2020-04-24 23:36:52 +00:00
|
|
|
DynamicUser = true;
|
2023-10-09 19:29:22 +00:00
|
|
|
ExecStart = "${pkgs.dnscrypt-proxy}/bin/dnscrypt-proxy -config ${cfg.configFile}";
|
2020-10-07 09:15:18 +00:00
|
|
|
LockPersonality = true;
|
|
|
|
LogsDirectory = "dnscrypt-proxy";
|
|
|
|
MemoryDenyWriteExecute = true;
|
|
|
|
NoNewPrivileges = true;
|
|
|
|
NonBlocking = true;
|
|
|
|
PrivateDevices = true;
|
2021-02-13 14:23:35 +00:00
|
|
|
ProtectClock = true;
|
2020-10-07 09:15:18 +00:00
|
|
|
ProtectControlGroups = true;
|
|
|
|
ProtectHome = true;
|
|
|
|
ProtectHostname = true;
|
|
|
|
ProtectKernelLogs = true;
|
|
|
|
ProtectKernelModules = true;
|
|
|
|
ProtectKernelTunables = true;
|
|
|
|
ProtectSystem = "strict";
|
2020-05-29 06:06:01 +00:00
|
|
|
Restart = "always";
|
2020-10-07 09:15:18 +00:00
|
|
|
RestrictAddressFamilies = [
|
|
|
|
"AF_INET"
|
|
|
|
"AF_INET6"
|
|
|
|
];
|
|
|
|
RestrictNamespaces = true;
|
|
|
|
RestrictRealtime = true;
|
|
|
|
RuntimeDirectory = "dnscrypt-proxy";
|
|
|
|
StateDirectory = "dnscrypt-proxy";
|
|
|
|
SystemCallArchitectures = "native";
|
|
|
|
SystemCallFilter = [
|
|
|
|
"@system-service"
|
|
|
|
"@chown"
|
2021-02-13 14:23:35 +00:00
|
|
|
"~@aio"
|
|
|
|
"~@keyring"
|
|
|
|
"~@memlock"
|
|
|
|
"~@setuid"
|
|
|
|
"~@timer"
|
2020-10-07 09:15:18 +00:00
|
|
|
];
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2022-01-07 04:07:37 +00:00
|
|
|
|
|
|
|
# uses attributes of the linked package
|
|
|
|
meta.buildDocsInSandbox = false;
|
2020-04-24 23:36:52 +00:00
|
|
|
}
|