1
1
Fork 0

Compare commits

..

No commits in common. "2d8700956173cf9f514e95ffdd2b54cf15850e64" and "c2a45ec1bb2b74ab9e7e1faa94ba1ad469857c30" have entirely different histories.

1 changed files with 454 additions and 445 deletions

View File

@ -3,9 +3,8 @@
with lib; with lib;
let let
cfg = config.services.syncthings; cfg = config.services.syncthing;
enabledInstances = filterAttrs (n: v: v.enable) cfg.instances; opt = options.services.syncthing;
opt = options.services.syncthings;
defaultUser = "syncthing"; defaultUser = "syncthing";
defaultGroup = defaultUser; defaultGroup = defaultUser;
settingsFormat = pkgs.formats.json { }; settingsFormat = pkgs.formats.json { };
@ -146,12 +145,7 @@ let
in { in {
###### interface ###### interface
options = { options = {
services.syncthings = { services.syncthing = {
instances = mkOption {
description = mdDoc "Syncthing instance definitions";
default = {};
type = types.attrsOf (types.submodule {
options = {
enable = mkEnableOption enable = mkEnableOption
(lib.mdDoc "Syncthing, a self-hosted open-source alternative to Dropbox and Bittorrent Sync"); (lib.mdDoc "Syncthing, a self-hosted open-source alternative to Dropbox and Bittorrent Sync");
@ -497,6 +491,14 @@ in {
''; '';
}; };
systemService = mkOption {
type = types.bool;
default = true;
description = lib.mdDoc ''
Whether to auto-launch Syncthing as a system service.
'';
};
user = mkOption { user = mkOption {
type = types.str; type = types.str;
default = defaultUser; default = defaultUser;
@ -575,23 +577,19 @@ in {
''; '';
}; };
openPorts = mkOption { openDefaultPorts = mkOption {
type = types.bool; type = types.bool;
default = false; default = false;
example = true; example = true;
description = mdDoc "Whether to open the transfer port and discovery port in the firewall."; description = lib.mdDoc ''
}; Whether to open the default ports in the firewall: TCP/UDP 22000 for transfers
and UDP 21027 for discovery.
transferPort = mkOption { If multiple users are running Syncthing on this machine, you will need
type = types.port; to manually open a set of ports for each instance and leave this disabled.
example = 22000; Alternatively, if you are running only a single instance on this machine
description = mdDoc "The TCP/UDP port for transfers."; using the default ports, enable this.
}; '';
discoveryPort = mkOption {
type = types.port;
example = 21027;
description = mdDoc "The UDP port for discovery.";
}; };
package = mkOption { package = mkOption {
@ -603,22 +601,33 @@ 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 ###### implementation
config = mkIf (enabledInstances != {}) { config = mkIf cfg.enable {
networking.firewall = {
networking.firewall = mkIf cfg.openDefaultPorts {
allowedTCPPorts = [ 22000 ]; allowedTCPPorts = [ 22000 ];
allowedUDPPorts = [ 21027 22000 ]; allowedUDPPorts = [ 21027 22000 ];
}; };
systemd.packages = [ pkgs.syncthing ]; systemd.packages = [ pkgs.syncthing ];
users.users = mkIf (cfg.user == defaultUser) { users.users = mkIf (cfg.systemService && cfg.user == defaultUser) {
${defaultUser} = ${defaultUser} =
{ group = cfg.group; { group = cfg.group;
home = cfg.dataDir; home = cfg.dataDir;
@ -628,7 +637,7 @@ in {
}; };
}; };
users.groups = mkIf (cfg.group == defaultGroup) { users.groups = mkIf (cfg.systemService && cfg.group == defaultGroup) {
${defaultGroup}.gid = ${defaultGroup}.gid =
config.ids.gids.syncthing; config.ids.gids.syncthing;
}; };
@ -636,7 +645,7 @@ in {
systemd.services = { systemd.services = {
# upstream reference: # upstream reference:
# https://github.com/syncthing/syncthing/blob/main/etc/linux-systemd/system/syncthing%40.service # https://github.com/syncthing/syncthing/blob/main/etc/linux-systemd/system/syncthing%40.service
syncthing = { syncthing = mkIf cfg.systemService {
description = "Syncthing service"; description = "Syncthing service";
after = [ "network.target" ]; after = [ "network.target" ];
environment = { environment = {