Compare commits
No commits in common. "2d8700956173cf9f514e95ffdd2b54cf15850e64" and "c2a45ec1bb2b74ab9e7e1faa94ba1ad469857c30" have entirely different histories.
2d87009561
...
c2a45ec1bb
|
@ -3,9 +3,8 @@
|
|||
with lib;
|
||||
|
||||
let
|
||||
cfg = config.services.syncthings;
|
||||
enabledInstances = filterAttrs (n: v: v.enable) cfg.instances;
|
||||
opt = options.services.syncthings;
|
||||
cfg = config.services.syncthing;
|
||||
opt = options.services.syncthing;
|
||||
defaultUser = "syncthing";
|
||||
defaultGroup = defaultUser;
|
||||
settingsFormat = pkgs.formats.json { };
|
||||
|
@ -146,12 +145,7 @@ let
|
|||
in {
|
||||
###### interface
|
||||
options = {
|
||||
services.syncthings = {
|
||||
instances = mkOption {
|
||||
description = mdDoc "Syncthing instance definitions";
|
||||
default = {};
|
||||
type = types.attrsOf (types.submodule {
|
||||
options = {
|
||||
services.syncthing = {
|
||||
|
||||
enable = mkEnableOption
|
||||
(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 {
|
||||
type = types.str;
|
||||
default = defaultUser;
|
||||
|
@ -575,23 +577,19 @@ in {
|
|||
'';
|
||||
};
|
||||
|
||||
openPorts = mkOption {
|
||||
openDefaultPorts = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
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 {
|
||||
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.";
|
||||
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.
|
||||
'';
|
||||
};
|
||||
|
||||
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
|
||||
|
||||
config = mkIf (enabledInstances != {}) {
|
||||
networking.firewall = {
|
||||
config = mkIf cfg.enable {
|
||||
|
||||
networking.firewall = mkIf cfg.openDefaultPorts {
|
||||
allowedTCPPorts = [ 22000 ];
|
||||
allowedUDPPorts = [ 21027 22000 ];
|
||||
};
|
||||
|
||||
systemd.packages = [ pkgs.syncthing ];
|
||||
|
||||
users.users = mkIf (cfg.user == defaultUser) {
|
||||
users.users = mkIf (cfg.systemService && cfg.user == defaultUser) {
|
||||
${defaultUser} =
|
||||
{ group = cfg.group;
|
||||
home = cfg.dataDir;
|
||||
|
@ -628,7 +637,7 @@ in {
|
|||
};
|
||||
};
|
||||
|
||||
users.groups = mkIf (cfg.group == defaultGroup) {
|
||||
users.groups = mkIf (cfg.systemService && cfg.group == defaultGroup) {
|
||||
${defaultGroup}.gid =
|
||||
config.ids.gids.syncthing;
|
||||
};
|
||||
|
@ -636,7 +645,7 @@ in {
|
|||
systemd.services = {
|
||||
# upstream reference:
|
||||
# https://github.com/syncthing/syncthing/blob/main/etc/linux-systemd/system/syncthing%40.service
|
||||
syncthing = {
|
||||
syncthing = mkIf cfg.systemService {
|
||||
description = "Syncthing service";
|
||||
after = [ "network.target" ];
|
||||
environment = {
|
||||
|
|
Loading…
Reference in New Issue