nixos/dnscrypt-proxy2: add package option

nixos/dnscrypt-proxy2: remove `with lib;`

Co-authored-by: Sizhe Zhao <prc.zhao@outlook.com>
This commit is contained in:
MidAutumnMoon 2025-05-27 23:46:20 +08:00
parent 050bbae7be
commit 101965187e
No known key found for this signature in database
2 changed files with 17 additions and 12 deletions

View file

@ -4,22 +4,25 @@
pkgs,
...
}:
with lib;
let
cfg = config.services.dnscrypt-proxy2;
in
{
options.services.dnscrypt-proxy2 = {
enable = mkEnableOption "dnscrypt-proxy2";
enable = lib.mkEnableOption "dnscrypt-proxy2";
settings = mkOption {
package = lib.mkPackageOption pkgs "dnscrypt-proxy" { };
settings = lib.mkOption {
description = ''
Attrset that is converted and passed as TOML config file.
For available params, see: <https://github.com/DNSCrypt/dnscrypt-proxy/blob/${pkgs.dnscrypt-proxy.version}/dnscrypt-proxy/example-dnscrypt-proxy.toml>
'';
example = literalExpression ''
example = lib.literalExpression ''
{
sources.public-resolvers = {
urls = [ "https://download.dnscrypt.info/resolvers-list/v2/public-resolvers.md" ];
@ -29,27 +32,27 @@ in
};
}
'';
type = types.attrs;
type = lib.types.attrs;
default = { };
};
upstreamDefaults = mkOption {
upstreamDefaults = lib.mkOption {
description = ''
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>)
Disable this if you want to declare your dnscrypt config from scratch.
'';
type = types.bool;
type = lib.types.bool;
default = true;
};
configFile = mkOption {
configFile = lib.mkOption {
description = ''
Path to TOML config file. See: <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;
type = lib.types.path;
default =
pkgs.runCommand "dnscrypt-proxy.toml"
{
@ -70,11 +73,11 @@ in
}
${pkgs.buildPackages.remarshal}/bin/json2toml < config.json > $out
'';
defaultText = literalMD "TOML file generated from {option}`services.dnscrypt-proxy2.settings`";
defaultText = lib.literalMD "TOML file generated from {option}`services.dnscrypt-proxy2.settings`";
};
};
config = mkIf cfg.enable {
config = lib.mkIf cfg.enable {
networking.nameservers = lib.mkDefault [ "127.0.0.1" ];
@ -94,7 +97,7 @@ in
AmbientCapabilities = "CAP_NET_BIND_SERVICE";
CacheDirectory = "dnscrypt-proxy";
DynamicUser = true;
ExecStart = "${pkgs.dnscrypt-proxy}/bin/dnscrypt-proxy -config ${cfg.configFile}";
ExecStart = "${lib.getExe cfg.package} -config ${cfg.configFile}";
LockPersonality = true;
LogsDirectory = "dnscrypt-proxy";
MemoryDenyWriteExecute = true;