8

I installed the Nix package manager on XUbuntu 20.04. It added a nix-daemon service. I would like to start the nix-daemon service on boot. If I type the following commands the service runs and works fine until I halt the machine, but after a reboot the service is not running, and I need to run these commands again.

It seems that systemd disables the service or forgets that it was enabled. How can I tell systemd to enable the service and leave it enabled?

$ sudo systemctl status nix-daemon
Unit nix-daemon.service could not be found.
$ sudo systemctl enable nix-daemon
$ sudo systemctl status nix-daemon
● nix-daemon.service - Nix Daemon
     Loaded: loaded (/nix/store/4vz8sh9ngx34ivi0bw5hlycxdhvy5hvz-nix-2.3.7/lib/systemd/system/nix-daemon.service; enabled; vendor preset: enabled)
    Drop-In: /etc/systemd/system/nix-daemon.service.d
             └─override.conf
     Active: inactive (dead)
TriggeredBy: ● nix-daemon.socket
$ sudo service nix-daemon start
● nix-daemon.service - Nix Daemon
     Loaded: loaded (/nix/store/4vz8sh9ngx34ivi0bw5hlycxdhvy5hvz-nix-2.3.7/lib/systemd/system/nix-daemon.service; enabled; vendor preset: enabled)
    Drop-In: /etc/systemd/system/nix-daemon.service.d
             └─override.conf
     Active: active (running) since Fri 2021-04-16 04:35:15 BST; 2s ago
TriggeredBy: ● nix-daemon.socket
   Main PID: 55329 (nix-daemon)
      Tasks: 5 (limit: 9091)
     Memory: 13.8M
     CGroup: /system.slice/nix-daemon.service
             └─55329 nix-daemon --daemon

Apr 16 04:35:15 wayfire systemd[1]: Started Nix Daemon.
Apr 16 04:35:15 wayfire nix-daemon[55329]: warning: unknown setting 'experimental-features'
Apr 16 04:35:15 wayfire nix-daemon[55329]: warning: unknown setting 'keep-derivarions'

EDIT:

Contents of the /etc/systemd/system/nix-daemon.service that was created by the installer (I didn't modify it):

[Unit]
Description=Nix Daemon
RequiresMountsFor=/nix/store
RequiresMountsFor=/nix/var
ConditionPathIsReadWrite=/nix/var/nix/daemon-socket

[Service]
ExecStart=@/nix/store/4vz8sh9ngx34ivi0bw5hlycxdhvy5hvz-nix-2.3.7/bin/nix-daemon nix-daemon --daemon
KillMode=process

[Install]
WantedBy=multi-user.target

There is no /etc/default/nix file.

$ systemctl get-default
graphical.target
1
  • RIght after you type: "sudo systemctl enable nix-daemon" you then need to type " "sudo systemctl start nix-daemon" - using "service nix-daemon start" calls "systemctl start nix-daemon". Post your nix-daemon.service file and the /etc/default/nix if one exists. Apr 16, 2021 at 5:42

2 Answers 2

3

There are a bunch of reasons why a service would not load at boot despite running systemctl enable thename.service. In my case, /etc/systemd/system/nix-daemon.service had been created by the installer (I guess?), and was a symlink to /nix/var/nix/profiles/default/lib/systemd/system/nix-daemon.service. My /nix is a separate partition, and systemd was trying to read the .service file before mounting the partition (and therefore failed to recognize the service). journalctl | grep nix-daemon allowed me to troubleshoot the issue.

2

Let me give you one way to do it. First type:

systemctl get-default

You will probably get graphical.target. Then add the following lines to your service file

[Install]
WantedBy=graphical.target

to tell systemd, which target starts your service. If your default target is different, use it instead of graphical.target (e.g. multi-user.target,...). Then reload systemd with

sudo systemctl daemon-reload

to make sure the changes in your service file are reloaded. After that the service should start with the reboot.

2
  • Thanks! Is adding WantedBy=the-correct.target something that replaces sudo systemctl enable some-service, or is it something that should be done before or after sudo systemctl enable some-service? Apr 17, 2021 at 15:40
  • You need to add [Install] WantedBy=..., then use systemctl daemon-reload && systemctl enable ...
    – Stewart
    Apr 17, 2021 at 17:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .