8 cfg = config.services.crab-hole;
10 settingsFormat = pkgs.formats.toml { };
14 pkgs.runCommand "check-config"
25 ln -s ${file} ./config.toml
26 export CRAB_HOLE_DIR=$(pwd)
28 ${lib.getExe cfg.package} validate-config
33 services.crab-hole = {
34 enable = lib.mkEnableOption "Crab-hole Service";
36 package = lib.mkPackageOption pkgs "crab-hole" { };
38 supplementaryGroups = lib.mkOption {
39 type = lib.types.listOf lib.types.str;
42 description = "Adds additional groups to the crab-hole service. Can be useful to prevent permission issues.";
45 settings = lib.mkOption {
46 description = "Crab-holes config. See big example https://github.com/LuckyTurtleDev/crab-hole/blob/main/example-config.toml";
56 certificate = "dns.example.com.crt";
57 dns_hostname = "dns.example.com";
58 key = "dns.example.com.key";
75 include_subdomains = true;
77 "https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/fakenews-gambling-porn/hosts"
78 "https://s3.amazonaws.com/lists.disconnect.me/simple_tracking.txt"
86 socket_addr = "[2606:4700:4700::1111]:853";
87 tls_dns_name = "1dot1dot1dot1.cloudflare-dns.com";
88 trust_nx_responses = false;
92 socket_addr = "1.1.1.1:853";
93 tls_dns_name = "1dot1dot1dot1.cloudflare-dns.com";
94 trust_nx_responses = false;
103 type = lib.types.submodule {
104 freeformType = settingsFormat.type;
111 type = lib.types.listOf (lib.types.either lib.types.str lib.types.path);
113 description = "List of ${name}. If files are added via url, make sure the service has access to them!";
114 apply = map (v: if builtins.isPath v then "file://${v}" else v);
118 include_subdomains = lib.mkEnableOption "Include subdomains";
119 lists = listOption "blocklists";
120 allow_list = listOption "allowlists";
126 configFile = lib.mkOption {
127 type = lib.types.path;
129 The config file of crab-hole.
131 If files are added via url, make sure the service has access to them.
132 Setting this option will override any configuration applied by the settings option.
138 config = lib.mkIf cfg.enable {
139 # Warning due to DNSSec issue in crab-hole
140 warnings = lib.optional (cfg.settings.upstream.options.validate or false) ''
141 Validate options will ONLY allow DNSSec domains. See https://github.com/LuckyTurtleDev/crab-hole/issues/29
144 services.crab-hole.configFile = lib.mkDefault (
145 checkConfig (settingsFormat.generate "crab-hole.toml" cfg.settings)
147 environment.etc."crab-hole.toml".source = cfg.configFile;
149 systemd.services.crab-hole = {
150 wantedBy = [ "multi-user.target" ];
151 after = [ "network-online.target" ];
152 wants = [ "network-online.target" ];
153 description = "Crab-hole dns server";
154 environment.HOME = "/var/lib/crab-hole";
155 restartTriggers = [ cfg.configFile ];
159 SupplementaryGroups = cfg.supplementaryGroups;
161 StateDirectory = "crab-hole";
162 WorkingDirectory = "/var/lib/crab-hole";
164 ExecStart = lib.getExe cfg.package;
166 AmbientCapabilities = "CAP_NET_BIND_SERVICE";
167 CapabilityBoundingSet = "CAP_NET_BIND_SERVICE";
169 Restart = "on-failure";
176 lib.maintainers.NiklasVousten
178 # Readme from upstream
179 meta.doc = ./crab-hole.md;