I want to user systemd user-services on NixOS. I could manually do this, by creating a service-configuration in ~/.config/systemd/user/
and enabling/starting it with systemctl --user enable
/ systemctl --user start
. This works fine.
But NixOS also has the systemd.user.services
options, so I thought I could define systemd user services declaratively. But unfortunately, this does not work, since systemd.user.services.wantedBy
seems to be ignored.
Example:
-
in configuration.nix:
systemd.user.services.log_test = { enable = true; description = "Just a test."; script="/home/user/test.sh"; serviceConfig = { WorkingDirectory="/home/user/"; Restart="always"; PrivateTmp="true"; NoNewPrivileges="true"; }; wantedBy = [ "default.target" ]; };
-
systemctl --user cat log_test
results in:[Unit] AssertPathExists=/home/user/test.sh Description=Just a test. [Service] Environment="LOCALE_ARCHIVE=..." Environment="PATH=..." Environment="TZDIR=..." ExecStart=/nix/store/x76dwav1l70f9n6b4vip2v4ika0lg6l9-unit-script/bin/log_test-start NoNewPrivileges=true PrivateTmp=true Restart=always WorkingDirectory=/home/user/
-
and
systemctl --user enable log_test
tells me:The unit files have no installation config (WantedBy, RequiredBy, Also, Alias settings in the [Install] section, and DefaultInstance for template units).
This means they are not meant to be enabled using systemctl.
Possible reasons for having this kind of units are:
…
So, is this a bug – or is systemd.user.services meant to be used in a different way?