Systemd services

I’m new to NixOS coming from Fedora. I have lived in a systemd world for a while (being a Red Hat Sys Admin for a little while also). I just finished moving from Fedora on my laptop to NixOS to discover that resolvectl doesn’t work. I proceeded to add systemd package to my configuration.nix file in which the Nix site states that numerous systemd programs, resolvectl, is included. However, when I ran the rebuild I found that I still couldn’t run resolvectl from command line, even after a reboot.
How do I get all the systemd services from the systemd packages/units to run at boot?
I looked in the NxOS Options also and found plenty of systemd.user listings. Is there something from this list that I need to add to my configuration.nix file to get all the systemd services to run at boot?

NixOS doesn’t actually use Networkd to manage networking by default. I use networkd, so for example in my configuration file I have:

networking.useNetworkd = true;
systemd.network.enable = true;

Then the additional networkd configuration I needed below those.

With NixOS you’re likely going to find that if the package you want is a service or needs something like a unit or obvious additional configuration, there’s probably going to be a module/option you can enable to set that up.

Hopefully that helps :slight_smile:

1 Like

Thanks for the reply.
I added those two lines and got an error in the systemd-networkd-wait-online.service starting.
Did you get the same error?
This service is enabled. After reboot it does look as if it started.

That’s incredibly likely to happen as by default that service waits for all netdevs to go online. If you have a wifi/lan card and are using only one of the two it will always fail.

I believe this is default networkd behavior, and other distros just tape over that. NixOS tends to stick to upstream behavior to a fault.

You probably want to flip this option to true: https://search.nixos.org/options?channel=23.05&show=systemd.network.wait-online.anyInterface&from=0&size=50&sort=relevance&type=packages&query=systemd.network

2 Likes

Oh, yes, definitely, since it is a laptop I am configuring this.

I’m pretty sure the networkd default is to configure no interfaces, so systemd-networkd-wait-online should finish immediately. However, if you configure NixOS with networking.useDHCP = true;, then NixOS configures networkd in such a way that all ethernet and wireless interfaces will be configured by networkd, which can have this effect. You can use networking.interfaces.<interface name>.useDHCP instead to have it only configure certain interfaces, or you can use the anyInterface option linked before to have it wait for just any interface, or you can just disable wait-online if you don’t actually want boot to rely on networking being online.

Yep. Setting that to false made the error go away.

systemd.network.wait-online.enable = false;

Hmm, what is the intended behavior if you do want networkd to manage all interfaces by setting networking.useNetworkd, though? Shouldn’t networking.useNetworkd also toggle anyInterface to avoid this presumably common situation?

The whole concept of network-online.target (implemented via systemd-networkd-wait-online.service for networkd) is a tad wonky and I’m not sure it should be enabled by default for any networking backend. anyInterface is a bandaid for when you do want systemd-networkd-wait-online to work in wonky situations, but really the crux of the issue is just network-online.target.

The intended behavior is being able to use systemd networking tools, like resolvectl, timedatectl, and other systemd tools listed in the systemd package ( coredumpctl bootctl resolvectl systemd-umount systemd-cat halt systemd-escape systemd-repart resolvconf systemd-ac-power reboot machinectl systemd-mount systemd-path systemd-id128 systemd-detect-virt systemd-ask-password systemd-tty-ask-password-agent systemd-socket-activate journalctl systemd-cgls systemd-resolve systemd-cgtop udevadm systemd-machine-id-setup systemd-run systemd-tmpfiles systemd-sysext systemd-stdio-bridge shutdown poweroff userdbctl oomctl loginctl init homectl systemd-analyze timedatectl systemd-inhibit systemd-hwdb systemd-delta systemd-notify networkctl hostnamectl systemd-nspawn systemd-dissect systemd-creds portablectl systemctl busctl systemd-cryptenroll localectl).

Just an F.Y.I. Networking still seems to be working just fine with these in my configuration.nix file:

   networking.useNetworkd = true;
   systemd.network.enable = true;
   systemd.network.wait-online.enable = false;

So, it looks as if these settings I have implemented have disabled the wi-fi. After re-install of NixOS (with wired plugged in) and placing my config I had created previously back onto my laptop the wi-fi adapter isn’t seen. I’m pretty sure wireless working the first time I installed NixOS on the laptop.
Any ideas on how I can get wireless work?
With those systemd/network settings in place, did I mess something up so that wi-fi adapter isn’t being detected?

The story gets weirder.
Luckily, I had created a Clonezilla image of my laptop just after the first initial install of NixOS. I restored that image in which I discovered that wireless is working; it also has the same configuration.nix file in the previous install where wireless disappeared. I am truly baffled as to how my wireless interface disappeared.

Unlucky boot with flaky hardware? Wouldn’t be the first time I see a wireless adapter misbehave a little. Did you grab a dmesg?

Unfortunately, no.
I guess my assumption those systemd and network entries caused the issue were not true.
For now that I have it working, I will also copy off the hardware-configuration.nix file in the event it happens again to do a compare.
We’ll just call this thread a success since I was able to get the systemd services running.

Luckily, I had created a Clonezilla image of my laptop just after the first initial install of NixOS.

You really don’t have to image the machine. As long as you don’t garbage collect that initial generation, you can always go back.

And that adds to the oddity. I had gone back to the initial and wi-fi still wasn’t working. :person_shrugging:

I suggest nix-diff to help find out what changed

Okay, yeah. I’ll try that out if it happens again. Thanks.

nix-diff command not found.

nix-shell -p nix-diff