Systemd service derivation creates empty service files

I’ve been having issues with some services (namely nscd and avahi) since reinstalling NixOS to a new drive. The timing coincided with me switching to btrfs (with a separate subvolume for /nix), but I don’t know if this matters for the issue. I’ve been trying to get help on the Nix Discord, but unfortunately there no one was able to help, so I’m hoping it can get some more exposure here.

When trying to use mDNS services I’ve noticed that the domain name resolving doesn’t work. It turned out that a couple of necessary services were marked as masked and not running (namely avahi-daemon.socket and nscd.service). I looked up their configurations and they were empty.

My system is configured using a flake. When using nix-repl to inspect the flake output, the service configuration seems correct (it is enabled, and it has a service file text):

nix-repl> outputs.nixosConfigurations.phalconix.config.systemd.units."nscd.service"
{ aliases = [ ... ]; enable = true; overrideStrategy = "asDropinIfExists"; requiredBy = [ ... ]; text = "[Unit]\n<...>"; unit = «derivation /nix/store/jzfq3bj8f0i6wllpq8ck7ni7b0wc22zh-unit-nscd.service.drv»; wantedBy = [ ... ]; }

The derivation listed above also seems fine:

"buildCommand": "name=nscd.service\nmkdir -p \"$out/$(dirname -- \"$name\")\"\necho -n \"$text\" > \"$out/$name\"\n",
"out": "/nix/store/app76fi5p5dbz488lfjmh10bnn213zsd-unit-nscd.service",
"name": "unit-nscd.service",
"text":"[Unit]\n<...>",

But when building the derivation the output is an empty file:

[nix-shell:~/.dotfiles]$ ls -lah /nix/store/app76fi5p5dbz488lfjmh10bnn213zsd-unit-nscd.service/nscd.service
-r--r--r-- 1 root root 0 Jan  1  1970 /nix/store/app76fi5p5dbz488lfjmh10bnn213zsd-unit-nscd.service/nscd.service

How can it be that the file ends up empty, even though the derivation clearly adds text to it? I tried rerunning nix build --rebuild ... on the derivation, but that didn’t produce any output and left the file empty.

1 Like

It turned out that this issue was caused by setting services.avahi.nssmdns = true;. I need nss-mdns, but enabling it with the Avahi service seemed to cause the issue as everytime I set it to true and rebuilt my system, it mentioned that the nscd service couldn’t be started.

I couldn’t figure out why this happened though, as a look through the nixpkgs repo doesn’t show any mentions of nssmdns that seem related.

What I had to d is set up some of the related settings myself, namely system.nssModules = [pkgs.nssmdns] and setting system.nssDatabases.hosts. The latter wasn’t much of an issue as I had to change the nss hosts database anyways, since the nssmdns setting defaulted to use mdns_minimal, whereas I need mdns4 for resolving .local domains