1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6 cfg = config.services.blocky;
7
8 format = pkgs.formats.yaml { };
9 configFile = format.generate "config.yaml" cfg.settings;
10in
11{
12 options.services.blocky = {
13 enable = mkEnableOption (lib.mdDoc "blocky, a fast and lightweight DNS proxy as ad-blocker for local network with many features");
14
15 settings = mkOption {
16 type = format.type;
17 default = { };
18 description = lib.mdDoc ''
19 Blocky configuration. Refer to
20 <https://0xerr0r.github.io/blocky/configuration/>
21 for details on supported values.
22 '';
23 };
24 };
25
26 config = mkIf cfg.enable {
27 systemd.services.blocky = {
28 description = "A DNS proxy and ad-blocker for the local network";
29 wantedBy = [ "multi-user.target" ];
30
31 serviceConfig = {
32 DynamicUser = true;
33 ExecStart = "${pkgs.blocky}/bin/blocky --config ${configFile}";
34 Restart = "on-failure";
35
36 AmbientCapabilities = [ "CAP_NET_BIND_SERVICE" ];
37 CapabilityBoundingSet = [ "CAP_NET_BIND_SERVICE" ];
38 };
39 };
40 };
41}