diff --git a/maintainers/maintainer-list.nix b/maintainers/maintainer-list.nix index 5fc08c92e99..993e5c2d46d 100644 --- a/maintainers/maintainer-list.nix +++ b/maintainers/maintainer-list.nix @@ -4154,6 +4154,16 @@ githubId = 3425311; name = "Antoine Eiche"; }; + lexuge = { + name = "Harry Ying"; + email = "lexugeyky@outlook.com"; + github = "LEXUGE"; + githubId = 13804737; + keys = [{ + longkeyid = "rsa4096/0xAE53B4C2E58EDD45"; + fingerprint = "7FE2 113A A08B 695A C8B8 DDE6 AE53 B4C2 E58E DD45"; + }]; + }; lheckemann = { email = "git@sphalerite.org"; github = "lheckemann"; diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index 771d7e128ea..d7bc02cbdc1 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -709,6 +709,7 @@ ./services/networking/shorewall6.nix ./services/networking/shout.nix ./services/networking/sniproxy.nix + ./services/networking/smartdns.nix ./services/networking/smokeping.nix ./services/networking/softether.nix ./services/networking/spacecookie.nix diff --git a/nixos/modules/services/networking/smartdns.nix b/nixos/modules/services/networking/smartdns.nix new file mode 100644 index 00000000000..f1888af7041 --- /dev/null +++ b/nixos/modules/services/networking/smartdns.nix @@ -0,0 +1,61 @@ +{ lib, pkgs, config, ... }: + +with lib; + +let + inherit (lib.types) attrsOf coercedTo listOf oneOf str int bool; + cfg = config.services.smartdns; + + confFile = pkgs.writeText "smartdns.conf" (with generators; + toKeyValue { + mkKeyValue = mkKeyValueDefault { + mkValueString = v: + if isBool v then + if v then "yes" else "no" + else + mkValueStringDefault { } v; + } " "; + listsAsDuplicateKeys = + true; # Allowing duplications because we need to deal with multiple entries with the same key. + } cfg.settings); +in { + options.services.smartdns = { + enable = mkEnableOption "SmartDNS DNS server"; + + bindPort = mkOption { + type = types.port; + default = 53; + description = "DNS listening port number."; + }; + + settings = mkOption { + type = + let atom = oneOf [ str int bool ]; + in attrsOf (coercedTo atom toList (listOf atom)); + example = literalExample '' + { + bind = ":5353 -no-rule -group example"; + cache-size = 4096; + server-tls = [ "8.8.8.8:853" "1.1.1.1:853" ]; + server-https = "https://cloudflare-dns.com/dns-query -exclude-default-group"; + prefetch-domain = true; + speed-check-mode = "ping,tcp:80"; + }; + ''; + description = '' + A set that will be generated into configuration file, see the SmartDNS README for details of configuration parameters. + You could override the options here like by writing settings.bind = ":5353 -no-rule -group example";. + ''; + }; + }; + + config = lib.mkIf cfg.enable { + services.smartdns.settings.bind = mkDefault ":${toString cfg.bindPort}"; + + systemd.packages = [ pkgs.smartdns ]; + systemd.services.smartdns.wantedBy = [ "multi-user.target" ]; + environment.etc."smartdns/smartdns.conf".source = confFile; + environment.etc."default/smartdns".source = + "${pkgs.smartdns}/etc/default/smartdns"; + }; +} diff --git a/pkgs/tools/networking/smartdns/default.nix b/pkgs/tools/networking/smartdns/default.nix new file mode 100644 index 00000000000..62a9aaf216c --- /dev/null +++ b/pkgs/tools/networking/smartdns/default.nix @@ -0,0 +1,38 @@ +{ stdenv, fetchFromGitHub, openssl }: + +stdenv.mkDerivation rec { + pname = "smartdns"; + version = + "30"; # This would be used later in the next release as the FHS commit integrated into realse 31. + + src = fetchFromGitHub { + owner = "pymumu"; + repo = pname; + rev = "3ad7cd7f454eec2fbdf338c0eb0541da301f1e73"; + sha256 = "1y9p8gxpj2k4a10maggkxg8l55jvr7x1wyxi69waxf56ggh2dvv0"; + }; + + buildInputs = [ openssl ]; + + makeFlags = [ + "PREFIX=${placeholder "out"}" + "SYSTEMDSYSTEMUNITDIR=${placeholder "out"}/lib/systemd/system" + "RUNSTATEDIR=/run" + ]; + + installFlags = [ "SYSCONFDIR=${placeholder "out"}/etc" ]; + + meta = with stdenv.lib; { + description = + "A local DNS server to obtain the fastest website IP for the best Internet experience"; + longDescription = '' + SmartDNS is a local DNS server. SmartDNS accepts DNS query requests from local clients, obtains DNS query results from multiple upstream DNS servers, and returns the fastest access results to clients. + Avoiding DNS pollution and improving network access speed, supports high-performance ad filtering. + Unlike dnsmasq's all-servers, smartdns returns the fastest access resolution. + ''; + homepage = "https://github.com/pymumu/smartdns"; + maintainers = [ maintainers.lexuge ]; + license = licenses.gpl3Plus; + platforms = platforms.linux; + }; +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index e7f51e14b9b..79401516993 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -6540,6 +6540,8 @@ in conf = config.slstatus.conf or null; }; + smartdns = callPackage ../tools/networking/smartdns { }; + smartmontools = callPackage ../tools/system/smartmontools { inherit (darwin.apple_sdk.frameworks) IOKit ApplicationServices; };