From 9bdb928d360530119860eee1be545bc79a869fb9 Mon Sep 17 00:00:00 2001 From: Harry Ying Date: Mon, 24 Feb 2020 13:32:11 +0800 Subject: [PATCH 1/3] maintainers: add lexuge --- maintainers/maintainer-list.nix | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/maintainers/maintainer-list.nix b/maintainers/maintainer-list.nix index 6beba4aa74a..ebc4937a001 100644 --- a/maintainers/maintainer-list.nix +++ b/maintainers/maintainer-list.nix @@ -4107,6 +4107,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"; From 25300d75be2336ad9e938bd5102ad8ba11149eb7 Mon Sep 17 00:00:00 2001 From: Harry Ying Date: Fri, 13 Mar 2020 00:13:12 +0800 Subject: [PATCH 2/3] smartdns: init at 30 --- pkgs/tools/networking/smartdns/default.nix | 38 ++++++++++++++++++++++ pkgs/top-level/all-packages.nix | 2 ++ 2 files changed, 40 insertions(+) create mode 100644 pkgs/tools/networking/smartdns/default.nix 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 ad0159345cd..0a0f325e21f 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -6507,6 +6507,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; }; From 629d3bab18f1369fc9b535dde98bf920eff4b30b Mon Sep 17 00:00:00 2001 From: Harry Ying Date: Sun, 15 Mar 2020 08:53:20 +0800 Subject: [PATCH 3/3] nixos/smartdns: init first generation config --- nixos/modules/module-list.nix | 1 + .../modules/services/networking/smartdns.nix | 61 +++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 nixos/modules/services/networking/smartdns.nix diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index 6734929b9d4..afa9d9cc801 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -706,6 +706,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"; + }; +}