@@ -5,6 +5,7 @@ with lib;
55let
66
77 cfg = config.services.syncthing;
8+ defaultUser = "syncthing";
89
910in
1011
@@ -17,6 +18,7 @@ in
1718 services.syncthing = {
1819
1920 enable = mkOption {
21+ type = types.bool;
2022 default = false;
2123 description = ''
2224 Whether to enable the Syncthing, self-hosted open-source alternative
@@ -26,7 +28,8 @@ in
2628 };
2729
2830 user = mkOption {
29− default = "syncthing";
31+ type = types.string;
32+ default = defaultUser;
3033 description = ''
3134 Syncthing will be run under this user (user must exist,
3235 this can be your user name).
@@ -34,8 +37,8 @@ in
3437 };
3538
3639 all_proxy = mkOption {
37− type = types.string;
38− default = "";
40+ type = types.nullOr types.string;
41+ default = null;
3942 example = "socks5://address.com:1234";
4043 description = ''
4144 Overwrites all_proxy environment variable for the syncthing process to
@@ -45,6 +48,7 @@ in
4548 };
4649
4750 dataDir = mkOption {
51+ type = types.path;
4852 default = "/var/lib/syncthing";
4953 description = ''
5054 Path where the settings and keys will exist.
@@ -71,20 +75,33 @@ in
7175
7276 config = mkIf cfg.enable {
7377
78+ users = mkIf (cfg.user == defaultUser) {
79+ extraUsers."${defaultUser}" =
80+ { group = defaultUser;
81+ home = cfg.dataDir;
82+ createHome = true;
83+ uid = config.ids.uids.syncthing;
84+ description = "Syncthing daemon user";
85+ };
86+
87+ extraGroups."${defaultUser}".gid =
88+ config.ids.gids.syncthing;
89+ };
90+
7491 systemd.services.syncthing =
7592 {
7693 description = "Syncthing service";
77− after = [ "network.target" ];
94+ after = [ "network.target" ];
7895 wantedBy = [ "multi-user.target" ];
7996 environment = {
8097 STNORESTART = "yes"; # do not self-restart
8198 STNOUPGRADE = "yes";
82− } //
83− (config.networking.proxy.envVars) //
84− (if cfg.all_proxy != "" then { all_proxy = cfg.all_proxy; } else {});
99+ inherit (cfg) all_proxy;
100+ } // config.networking.proxy.envVars;
85101
86102 serviceConfig = {
87− User = "${cfg.user}";
103+ User = cfg.user;
104+ Group = optionalString (cfg.user == defaultUser) defaultUser;
88105 PermissionsStartOnly = true;
89106 Restart = "on-failure";
90107 ExecStart = "${pkgs.syncthing}/bin/syncthing -no-browser -home=${cfg.dataDir}";