1 { config, lib, pkgs, ... }:
3 cfg = config.services.coredns;
4 configFile = pkgs.writeText "Corefile" cfg.config;
6 options.services.coredns = {
7 enable = lib.mkEnableOption "Coredns dns server";
9 config = lib.mkOption {
16 type = lib.types.lines;
18 Verbatim Corefile to use.
19 See <https://coredns.io/manual/toc/#configuration> for details.
23 package = lib.mkPackageOption pkgs "coredns" { };
25 extraArgs = lib.mkOption {
27 example = [ "-dns.port=53" ];
28 type = lib.types.listOf lib.types.str;
29 description = "Extra arguments to pass to coredns.";
33 config = lib.mkIf cfg.enable {
34 systemd.services.coredns = {
35 description = "Coredns dns server";
36 after = [ "network.target" ];
37 wantedBy = [ "multi-user.target" ];
39 PermissionsStartOnly = true;
41 LimitNOFILE = 1048576;
42 CapabilityBoundingSet = "cap_net_bind_service";
43 AmbientCapabilities = "cap_net_bind_service";
44 NoNewPrivileges = true;
46 ExecStart = "${lib.getBin cfg.package}/bin/coredns -conf=${configFile} ${lib.escapeShellArgs cfg.extraArgs}";
47 ExecReload = "${pkgs.coreutils}/bin/kill -SIGUSR1 $MAINPID";
48 Restart = "on-failure";