Systemd module failes with

here’s what i got in configuration.nix

systemd.services.syncthingSession = {

    wantedBy = [ "multi-user.target" ];
    after = [ "network.target" ];
    description = "syncthing"

    serviceConfig = { 
        Type = "notify";
        NotifyAccess = "all";
        User = "user";
        ExecStart = ''${pkgs.syncthing}/bin/syncthing -no-browser'';
        ExecStop = ''${pkgs.syncthing}/bin/syncthing -terminate'';
        };
    };

error when i rebuild:

× syncthingSession.service - start syncthing instance.
     Loaded: loaded (/etc/systemd/system/syncthingSession.service; enabled; preset: enabled)
     Active: failed (Result: timeout) since Fri 2024-06-07 15:55:50 EDT; 77ms ago
    Process: 20012 ExecStart=/nix/store/npav1bljfakbpyham1zj7d5g724nqi9f-syncthing-1.27.7/bin/syncthing -no-browser (code=exited, status=0/SUCCESS)
   Main PID: 20012 (code=exited, status=0/SUCCESS)
         IP: 52.9K in, 84.8K out
        CPU: 1.533s

Jun 07 15:55:40 began-fruit systemd[1]: syncthingSession.service: start operation timed out. Terminating.
Jun 07 15:55:40 began-fruit syncthing[20012]: [monitor] 2024/06/07 15:55:40 INFO: Signal 15 received; exiting
Jun 07 15:55:40 began-fruit syncthing[20012]: [34EQC] 2024/06/07 15:55:40 INFO: Relay listener (dynamic+https://relays.syncthing.net/endpoint) shutting down
Jun 07 15:55:40 began-fruit syncthing[20012]: [34EQC] 2024/06/07 15:55:40 INFO: QUIC listener ([::]:22000) shutting down
Jun 07 15:55:40 began-fruit syncthing[20012]: [34EQC] 2024/06/07 15:55:40 INFO: TCP listener ([::]:22000) shutting down
Jun 07 15:55:50 began-fruit syncthing[20012]: [34EQC] 2024/06/07 15:55:50 INFO: Exiting
Jun 07 15:55:50 began-fruit syncthing[20012]: [34EQC] 2024/06/07 15:55:50 INFO: Lost secondary connection to QA7JHY6 at 192.168.50.11:36996-51.81.93.224:22069/relay-client/TLS1.3-TLS_AES_128_GCM_SHA256/WAN-P50-5UMQ43VDMGP004JHH0S69MAP8U: Syncthing is being stopped (0 remain)
Jun 07 15:55:50 began-fruit systemd[1]: syncthingSession.service: Failed with result 'timeout'.
Jun 07 15:55:50 began-fruit systemd[1]: Failed to start start syncthing instance..
Jun 07 15:55:50 began-fruit systemd[1]: syncthingSession.service: Consumed 1.533s CPU time, received 52.9K IP traffic, sent 84.8K IP traffic.
warning: error(s) occurred while switching to the new configuration

looking at the logs, it looks like /bin/syncthing isn’t the correct path.

May 28 11:27:55 began-fruit systemd[1]: Starting start syncthing instance....
May 28 11:27:55 began-fruit (yncthing)[6254]: syncthingSession.service: Failed to locate executable /nix/store/mav0q76y52x65hhjdl02xpz84yr3dw8w>
May 28 11:27:55 began-fruit (yncthing)[6254]: syncthingSession.service: Failed at step EXEC spawning /nix/store/mav0q76y52x65hhjdl02xpz84yr3dw8>
May 28 11:27:55 began-fruit systemd[1]: syncthingSession.service: Main process exited, code=exited, status=203/EXEC
May 28 11:27:55 began-fruit systemd[1]: syncthingSession.service: Failed with result 'exit-code'.
May 28 11:27:55 began-fruit systemd[1]: Failed to start start syncthing instance..
May 28 11:32:54 began-fruit systemd[1]: Starting start syncthing instance...

should i be plugging in a path to /nix/store?

Is there a particular reason you’re trying to write the service yourself?

Because as I understand from the Wiki, a syncthing service already exists and can be enabled like this, for example:

services = {
    syncthing = {
        enable = true;
        user = "myusername";
        dataDir = "/home/myusername/Documents";    # Default folder for new synced folders
        configDir = "/home/myusername/Documents/.config/syncthing";   # Folder for Syncthing's settings and keys
    };
};

It also seems pretty extensible as it has a lot of options available.

well that solves that lol. thank you! but say i wanted to write it myself, what was wrong with my block above?

1 Like

Well, aside from the missing semicolon at the end of description, I don’t think there is anything particularly wrong as I ran it and it did find the executable, but it gave me another error:

syncthingSession.service: Failed to determine user credentials: No such process

That’s why I think that syncthing might just be a bit complex service that it requires a lot of things to be set up.

If you’re interested to know how it works and how you can hack it or write your own, I suggest you read its service module.

i will do that, thank you! you have helped a lot

1 Like