Stuck on systemd service for simple executable

In bit of a learning process here and I have gotten stuck on launching a standalone executable as a systemd service.

running the application from terminal works as expected:

./application

As I want this application to run as a service I copied it to /opt/application/aplication with the hope to set up a systemd service like this:

[Unit]
Description=A self-hosted app
After=network-up.target

[Service]
ExecStart=/opt/application/application

[Install]
WantedBy=multi-user.target

This is where I learned that systemd services in NixOS are set up in the config file, so I have ended up with this:

  # Application (Firewall rule in firewall section)
  systemd.services.application = {
    enable = true;
    description = "A self-hosted app";
    unitConfig = {
      Type = "simple";
    };
    serviceConfig = {
      ExecStart = "${application}/opt/application";
      Restart = "always";
    };
    wantedBy = [ "multi-user.target" ];
  }

but doing ‘nixos-rebuild switch’ it throws me a error longer than what can go in here, from what I understand my problem is somewhere here:

    serviceConfig = {
      ExecStart = "${application}/opt/application";

Can anyone help me with this?

What’s the error exactly? The config looks fine to me.

1 Like

I don’t see a semicolon after the entire block. Was that missed when pasting or is it not in your config?

doesn’t that belong in serviceConfig? :thinking:

Yeah, that’s not right. I don’t think it causes a build error, though.

1 Like