Bad systemd service generated by NixOS

The following config:

systemd.services.webServer=rec{
      after=["migration.service"];
      wants=after;
      wantedBy=["multi-user.target"];
      path=[p.manage];
      serviceConfig.ExecStart=''
        manage runserver_plus 8080
      '';
    };
  };

Gives me:

systemctl status webServer
ā— webServer.service
   Loaded: bad-setting (Reason: Unit webServer.service has a bad unit file setting.)
   Active: inactive (dead)

systemctl cat webServer
# /nix/store/4mr9di3q6sw1d4msk523hvmgvlyf5a0h-unit-webServer.service/webServer.service
[Unit]
After=migration.service
Wants=migration.service

[Service]
Environment="LOCALE_ARCHIVE=/nix/store/v1h4wadpfcz906mv6i2aarhj2rqn50am-glibc-locales-2.27/lib/locale/locale-archive"
Environment="PATH=/nix/store/g8nnx741vjxrbds3fl6967rbb4zs1nh9-manage/bin:/nix/store/lignp8sr30qrgl1kp0xvbc7x89syyzp0-coreutils-8.31/bin:/nix/store/w4bcr2ddc1plz1pnijhv5ybirr1jwspn-findutils-4.7.0/bin:/>
Environment="TZDIR=/nix/store/1n1dbnyjrlz8hjry4yff0hji5gr02kji-tzdata-2019c/share/zoneinfo"



ExecStart=manage runserver_plus 8080

What am I doing wrong?

You want systemd.services.<name>.script. serviceConfig.ExecStart is the final, raw value that gets put in the service file, as you have already noticed.

1 Like

You could also set ExecStart to ${p.manage}/bin/manage runserver_plus 8080, instead of using script.

1 Like

Basically systemd requires an absolute path to the executable which will be set for you if you use script (but there really is no reason to wrap this in bash invocation) or by doing the full path as mentioned by @ajs124.