Merge pull request #14683 from peterhoeg/st_systemd
syncthing service: support running from systemd --user instance
This commit is contained in:
commit
59ac68d05e
|
@ -7,6 +7,21 @@ let
|
||||||
cfg = config.services.syncthing;
|
cfg = config.services.syncthing;
|
||||||
defaultUser = "syncthing";
|
defaultUser = "syncthing";
|
||||||
|
|
||||||
|
header = {
|
||||||
|
description = "Syncthing service";
|
||||||
|
environment = {
|
||||||
|
STNORESTART = "yes";
|
||||||
|
STNOUPGRADE = "yes";
|
||||||
|
inherit (cfg) all_proxy;
|
||||||
|
} // config.networking.proxy.envVars;
|
||||||
|
};
|
||||||
|
|
||||||
|
service = {
|
||||||
|
Restart = "on-failure";
|
||||||
|
SuccessExitStatus = "2 3 4";
|
||||||
|
RestartForceExitStatus="3 4";
|
||||||
|
};
|
||||||
|
|
||||||
in
|
in
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -17,22 +32,35 @@ in
|
||||||
|
|
||||||
services.syncthing = {
|
services.syncthing = {
|
||||||
|
|
||||||
enable = mkOption {
|
enable = mkEnableOption {
|
||||||
type = types.bool;
|
|
||||||
default = false;
|
|
||||||
description = ''
|
description = ''
|
||||||
Whether to enable the Syncthing, self-hosted open-source alternative
|
Whether to enable Syncthing - the self-hosted open-source alternative
|
||||||
to Dropbox and BittorrentSync. Initial interface will be
|
to Dropbox and Bittorrent Sync. Initial interface will be
|
||||||
available on http://127.0.0.1:8384/.
|
available on http://127.0.0.1:8384/.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
systemService = mkOption {
|
||||||
|
type = types.bool;
|
||||||
|
default = true;
|
||||||
|
description = "Auto launch Syncthing as a system service.";
|
||||||
|
};
|
||||||
|
|
||||||
user = mkOption {
|
user = mkOption {
|
||||||
type = types.string;
|
type = types.string;
|
||||||
default = defaultUser;
|
default = defaultUser;
|
||||||
description = ''
|
description = ''
|
||||||
Syncthing will be run under this user (user must exist,
|
Syncthing will be run under this user (user will be created if it doesn't exist.
|
||||||
this can be your user name).
|
This can be your user name).
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
group = mkOption {
|
||||||
|
type = types.string;
|
||||||
|
default = "nogroup";
|
||||||
|
description = ''
|
||||||
|
Syncthing will be run under this group (group will not be created if it doesn't exist.
|
||||||
|
This can be your user name).
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -64,10 +92,7 @@ in
|
||||||
Syncthing package to use.
|
Syncthing package to use.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -77,7 +102,7 @@ in
|
||||||
|
|
||||||
users = mkIf (cfg.user == defaultUser) {
|
users = mkIf (cfg.user == defaultUser) {
|
||||||
extraUsers."${defaultUser}" =
|
extraUsers."${defaultUser}" =
|
||||||
{ group = defaultUser;
|
{ group = cfg.group;
|
||||||
home = cfg.dataDir;
|
home = cfg.dataDir;
|
||||||
createHome = true;
|
createHome = true;
|
||||||
uid = config.ids.uids.syncthing;
|
uid = config.ids.uids.syncthing;
|
||||||
|
@ -101,17 +126,30 @@ in
|
||||||
|
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
User = cfg.user;
|
User = cfg.user;
|
||||||
Group = optionalString (cfg.user == defaultUser) defaultUser;
|
Group = cfg.group;
|
||||||
PermissionsStartOnly = true;
|
};
|
||||||
Restart = "on-failure";
|
|
||||||
ExecStart = "${pkgs.syncthing}/bin/syncthing -no-browser -home=${cfg.dataDir}";
|
|
||||||
SuccessExitStatus = "2 3 4";
|
|
||||||
RestartForceExitStatus="3 4";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
environment.systemPackages = [ cfg.package ];
|
environment.systemPackages = [ cfg.package ];
|
||||||
|
|
||||||
};
|
systemd.services = mkIf cfg.systemService {
|
||||||
|
syncthing = header // {
|
||||||
|
after = [ "network.target" ];
|
||||||
|
wantedBy = [ "multi-user.target" ];
|
||||||
|
serviceConfig = service // {
|
||||||
|
User = cfg.user;
|
||||||
|
Group = cfg.group;
|
||||||
|
PermissionsStartOnly = true;
|
||||||
|
ExecStart = "${pkgs.syncthing}/bin/syncthing -no-browser -home=${cfg.dataDir}";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
systemd.user.services = {
|
||||||
|
syncthing = header // {
|
||||||
|
serviceConfig = service // {
|
||||||
|
ExecStart = "${pkgs.syncthing}/bin/syncthing -no-browser";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue