dnsmasq: create state dir for dhcp leases file

ref #11718

Changed files
+10 -6
nixos
modules
services
networking
+10 -6
nixos/modules/services/networking/dnsmasq.nix
···
let
cfg = config.services.dnsmasq;
dnsmasq = pkgs.dnsmasq;
+
stateDir = "/var/lib/dnsmasq";
dnsmasqConf = pkgs.writeText "dnsmasq.conf" ''
+
dhcp-leasefile=${stateDir}/dnsmasq.leases
${optionalString cfg.resolveLocalQueries ''
conf-file=/etc/dnsmasq-conf.conf
resolv-file=/etc/dnsmasq-resolv.conf
···
services.dbus.packages = [ dnsmasq ];
-
users.extraUsers = singleton
-
{ name = "dnsmasq";
-
uid = config.ids.uids.dnsmasq;
-
description = "Dnsmasq daemon user";
-
home = "/var/empty";
-
};
+
users.extraUsers = singleton {
+
name = "dnsmasq";
+
uid = config.ids.uids.dnsmasq;
+
description = "Dnsmasq daemon user";
+
};
systemd.services.dnsmasq = {
description = "Dnsmasq Daemon";
···
wantedBy = [ "multi-user.target" ];
path = [ dnsmasq ];
preStart = ''
+
mkdir -m 755 -p ${stateDir}
+
touch ${stateDir}/dnsmasq.leases
+
chown -R dnsmasq ${stateDir}
touch /etc/dnsmasq-{conf,resolv}.conf
dnsmasq --test
'';