Compare commits
4 Commits
c2a45ec1bb
...
2d87009561
Author | SHA1 | Date |
---|---|---|
Tim Van Baak | 2d87009561 | |
Tim Van Baak | db3df565d5 | |
Tim Van Baak | 92b3d5c56e | |
Tim Van Baak | 451d4da000 |
|
@ -3,8 +3,9 @@
|
|||
with lib;
|
||||
|
||||
let
|
||||
cfg = config.services.syncthing;
|
||||
opt = options.services.syncthing;
|
||||
cfg = config.services.syncthings;
|
||||
enabledInstances = filterAttrs (n: v: v.enable) cfg.instances;
|
||||
opt = options.services.syncthings;
|
||||
defaultUser = "syncthing";
|
||||
defaultGroup = defaultUser;
|
||||
settingsFormat = pkgs.formats.json { };
|
||||
|
@ -145,7 +146,12 @@ let
|
|||
in {
|
||||
###### interface
|
||||
options = {
|
||||
services.syncthing = {
|
||||
services.syncthings = {
|
||||
instances = mkOption {
|
||||
description = mdDoc "Syncthing instance definitions";
|
||||
default = {};
|
||||
type = types.attrsOf (types.submodule {
|
||||
options = {
|
||||
|
||||
enable = mkEnableOption
|
||||
(lib.mdDoc "Syncthing, a self-hosted open-source alternative to Dropbox and Bittorrent Sync");
|
||||
|
@ -491,14 +497,6 @@ in {
|
|||
'';
|
||||
};
|
||||
|
||||
systemService = mkOption {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
description = lib.mdDoc ''
|
||||
Whether to auto-launch Syncthing as a system service.
|
||||
'';
|
||||
};
|
||||
|
||||
user = mkOption {
|
||||
type = types.str;
|
||||
default = defaultUser;
|
||||
|
@ -577,19 +575,23 @@ in {
|
|||
'';
|
||||
};
|
||||
|
||||
openDefaultPorts = mkOption {
|
||||
openPorts = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
example = true;
|
||||
description = lib.mdDoc ''
|
||||
Whether to open the default ports in the firewall: TCP/UDP 22000 for transfers
|
||||
and UDP 21027 for discovery.
|
||||
description = mdDoc "Whether to open the transfer port and discovery port in the firewall.";
|
||||
};
|
||||
|
||||
If multiple users are running Syncthing on this machine, you will need
|
||||
to manually open a set of ports for each instance and leave this disabled.
|
||||
Alternatively, if you are running only a single instance on this machine
|
||||
using the default ports, enable this.
|
||||
'';
|
||||
transferPort = mkOption {
|
||||
type = types.port;
|
||||
example = 22000;
|
||||
description = mdDoc "The TCP/UDP port for transfers.";
|
||||
};
|
||||
|
||||
discoveryPort = mkOption {
|
||||
type = types.port;
|
||||
example = 21027;
|
||||
description = mdDoc "The UDP port for discovery.";
|
||||
};
|
||||
|
||||
package = mkOption {
|
||||
|
@ -601,33 +603,22 @@ in {
|
|||
'';
|
||||
};
|
||||
};
|
||||
});
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
imports = [
|
||||
(mkRemovedOptionModule [ "services" "syncthing" "useInotify" ] ''
|
||||
This option was removed because Syncthing now has the inotify functionality included under the name "fswatcher".
|
||||
It can be enabled on a per-folder basis through the web interface.
|
||||
'')
|
||||
(mkRenamedOptionModule [ "services" "syncthing" "extraOptions" ] [ "services" "syncthing" "settings" ])
|
||||
(mkRenamedOptionModule [ "services" "syncthing" "folders" ] [ "services" "syncthing" "settings" "folders" ])
|
||||
(mkRenamedOptionModule [ "services" "syncthing" "devices" ] [ "services" "syncthing" "settings" "devices" ])
|
||||
(mkRenamedOptionModule [ "services" "syncthing" "options" ] [ "services" "syncthing" "settings" "options" ])
|
||||
] ++ map (o:
|
||||
mkRenamedOptionModule [ "services" "syncthing" "declarative" o ] [ "services" "syncthing" o ]
|
||||
) [ "cert" "key" "devices" "folders" "overrideDevices" "overrideFolders" "extraOptions"];
|
||||
|
||||
###### implementation
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
|
||||
networking.firewall = mkIf cfg.openDefaultPorts {
|
||||
config = mkIf (enabledInstances != {}) {
|
||||
networking.firewall = {
|
||||
allowedTCPPorts = [ 22000 ];
|
||||
allowedUDPPorts = [ 21027 22000 ];
|
||||
};
|
||||
|
||||
systemd.packages = [ pkgs.syncthing ];
|
||||
|
||||
users.users = mkIf (cfg.systemService && cfg.user == defaultUser) {
|
||||
users.users = mkIf (cfg.user == defaultUser) {
|
||||
${defaultUser} =
|
||||
{ group = cfg.group;
|
||||
home = cfg.dataDir;
|
||||
|
@ -637,7 +628,7 @@ in {
|
|||
};
|
||||
};
|
||||
|
||||
users.groups = mkIf (cfg.systemService && cfg.group == defaultGroup) {
|
||||
users.groups = mkIf (cfg.group == defaultGroup) {
|
||||
${defaultGroup}.gid =
|
||||
config.ids.gids.syncthing;
|
||||
};
|
||||
|
@ -645,7 +636,7 @@ in {
|
|||
systemd.services = {
|
||||
# upstream reference:
|
||||
# https://github.com/syncthing/syncthing/blob/main/etc/linux-systemd/system/syncthing%40.service
|
||||
syncthing = mkIf cfg.systemService {
|
||||
syncthing = {
|
||||
description = "Syncthing service";
|
||||
after = [ "network.target" ];
|
||||
environment = {
|
||||
|
|
Loading…
Reference in New Issue