2020-03-15 00:53:20 +00:00
{ lib , pkgs , config , . . . }:
with lib ;
let
inherit ( lib . types ) attrsOf coercedTo listOf oneOf str int bool ;
cfg = config . services . smartdns ;
confFile = pkgs . writeText " s m a r t d n s . c o n f " ( with generators ;
toKeyValue {
mkKeyValue = mkKeyValueDefault {
mkValueString = v :
if isBool v then
if v then " y e s " else " n o "
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 ( lib . mdDoc " S m a r t D N S D N S s e r v e r " ) ;
bindPort = mkOption {
type = types . port ;
default = 53 ;
description = lib . mdDoc " D N S l i s t e n i n g p o r t n u m b e r . " ;
} ;
settings = mkOption {
type =
let atom = oneOf [ str int bool ] ;
in attrsOf ( coercedTo atom toList ( listOf atom ) ) ;
2021-10-03 16:06:03 +00:00
example = literalExpression ''
2020-03-15 00:53:20 +00:00
{
bind = " : 5 3 5 3 - n o - r u l e - g r o u p e x a m p l e " ;
cache-size = 4096 ;
server-tls = [ " 8 . 8 . 8 . 8 : 8 5 3 " " 1 . 1 . 1 . 1 : 8 5 3 " ] ;
server-https = " h t t p s : / / c l o u d f l a r e - d n s . c o m / d n s - q u e r y - e x c l u d e - d e f a u l t - g r o u p " ;
prefetch-domain = true ;
speed-check-mode = " p i n g , t c p : 8 0 " ;
} ;
'' ;
description = lib . mdDoc ''
A set that will be generated into configuration file , see the [ SmartDNS README ] ( https://github.com/pymumu/smartdns/blob/master/ReadMe_en.md #configuration-parameter) for details of configuration parameters.
You could override the options here like { option } ` services . smartdns . bindPort ` by writing ` settings . bind = " : 5 3 5 3 - n o - r u l e - g r o u p e x a m p l e " ; ` .
'' ;
} ;
} ;
config = lib . mkIf cfg . enable {
services . smartdns . settings . bind = mkDefault " : ${ toString cfg . bindPort } " ;
systemd . packages = [ pkgs . smartdns ] ;
systemd . services . smartdns . wantedBy = [ " m u l t i - u s e r . t a r g e t " ] ;
2021-07-09 05:36:26 +00:00
systemd . services . smartdns . restartTriggers = [ confFile ] ;
2020-03-15 00:53:20 +00:00
environment . etc . " s m a r t d n s / s m a r t d n s . c o n f " . source = confFile ;
environment . etc . " d e f a u l t / s m a r t d n s " . source =
" ${ pkgs . smartdns } / e t c / d e f a u l t / s m a r t d n s " ;
} ;
}