Permanently disable systemd services

Hi All!

I’m just started to learn to configure and use NixOS, so maybe I’m still missing some basic concepts and I can’t figure out how to permanently disable systemd services using the configuration file.

I’ve tried this:

systemd.services = {
    ModemManager = {
      enable = false;
      restartIfChanged = false;
    };
  };

After a nixos-rebuild switch it’s fine: the ModemManager.service is shut down. However after a reboot it’s up and running again. Is it possible to preserve the disabled state after a reboot?
I’ve looked around in the manual and also here in discourse but to no avail.

Thanks in advance!
Cheers!

Interesting. I’d say this deserves an issue on Nixpkgs bugtracker.

You may disable NM using another option:
https://nixos.org/nixos/options.html#networking.networkmanager.enable

networking.networkmanager.enable = lib.mkForce false;

(The lib.mkForce says explicit and loud to override any other settings for this option)

Thanks for your answer!
The service I was asking for is ModemManager, which doesn’t seem to have an option (according to the page, you linked).
A more general question could be: how to make systemctl disable permanent?

Oh, sorry, it was ModemManager.

Have you tried (lower-case, not CamelCase) unit name

systemd.services.modem-manager.enable = false;

?

I’ve tried it, but in this case, it won’t even stop it on rebuild switch…
Using my original setup, this is the systemctl status output for ModemManager after reboot:

● ModemManager.service - Modem Manager
   Loaded: loaded (/nix/store/cd96xz87sp2lvipn6lm22yc5rihy63b2-ModemManager-1.6.8/etc/systemd/system/ModemManager.service; masked; vendor preset: enabled)
   Active: active (running) since Thu 2018-05-24 18:51:32 CEST; 2h 20min ago
 Main PID: 1175 (ModemManager)
    Tasks: 3 (limit: 4915)
   CGroup: /system.slice/ModemManager.service
           └─1175 /nix/store/cd96xz87sp2lvipn6lm22yc5rihy63b2-ModemManager-1.6.8/sbin/ModemManager

máj 24 18:51:31 nixos systemd[1]: Starting Modem Manager...
máj 24 18:51:32 nixos ModemManager[1175]: <info>  ModemManager (version 1.6.8) starting in system bus...
máj 24 18:51:32 nixos systemd[1]: Started Modem Manager.
máj 24 18:51:34 nixos ModemManager[1175]: <info>  Couldn't check support for device at '/sys/devices/pci0000:00/0000:00:1c.1/0000:03:00.0': not supported by any plugin
máj 24 18:51:34 nixos ModemManager[1175]: <info>  Couldn't check support for device at '/sys/devices/pci0000:00/0000:00:1c.3/0000:04:00.0': not supported by any plugin
máj 24 20:57:07 nixos ModemManager[1175]: <info>  Couldn't check support for device at '/sys/devices/pci0000:00/0000:00:1c.1/0000:03:00.0': not supported by any plugin
máj 24 20:57:07 nixos ModemManager[1175]: <info>  Couldn't check support for device at '/sys/devices/pci0000:00/0000:00:1c.3/0000:04:00.0': not supported by any plugin

So, it says it is masked. What I do not understand is that, as far as I know, this means that systemd won’t start it even if another service depends on it…

Edit: this is the output after nixos-rebuild switch:
● ModemManager.service
Loaded: masked (/dev/null; bad)
Active: inactive (dead)

máj 25 07:21:32 nixos systemd[1]: Starting Modem Manager...
máj 25 07:21:33 nixos ModemManager[1047]: <info>  ModemManager (version 1.6.8) starting in system bus...
máj 25 07:21:33 nixos systemd[1]: Started Modem Manager.
máj 25 07:21:35 nixos ModemManager[1047]: <info>  Couldn't check support for device at '/sys/devices/pci0000:00/0000:00:1c.1/0000:03:00.0': not supported by any plugin
máj 25 07:21:35 nixos ModemManager[1047]: <info>  Couldn't check support for device at '/sys/devices/pci0000:00/0000:00:1c.3/0000:04:00.0': not supported by any plugin
máj 25 07:22:44 nixos ModemManager[1047]: <info>  Caught signal, shutting down...
máj 25 07:22:44 nixos systemd[1]: Stopping Modem Manager...
máj 25 07:22:44 nixos ModemManager[1047]: <info>  ModemManager is shut down
máj 25 07:22:44 nixos systemd[1]: Stopped Modem Manager.

Yeah, I confirm this too. Reported at Can't disable NixOS service modem-manager · Issue #41055 · NixOS/nixpkgs · GitHub

NixOS disables units by symlinking them to /dev/null on activation. I don’t understand why it isn’t symlinked to /dev/null after reboot…

Maybe you can find more insights here

Thanks for reporting it, I added some more information to my previous post!

Breaking news, it’s indeed a bug in Nixpkgs/NixOS

I’ve pointed there to a workaround, but I can’t think now of a proper solution.