2014-04-14 15:26:48 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
2014-04-03 17:54:10 +01:00
|
|
|
|
2014-04-14 15:26:48 +01:00
|
|
|
with lib;
|
2014-04-03 17:54:10 +01:00
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.syncthing;
|
2016-04-01 00:26:52 +01:00
|
|
|
defaultUser = "syncthing";
|
2019-04-21 22:05:07 +01:00
|
|
|
|
|
|
|
devices = mapAttrsToList (name: device: {
|
|
|
|
deviceID = device.id;
|
|
|
|
inherit (device) name addresses introducer;
|
|
|
|
}) cfg.declarative.devices;
|
|
|
|
|
|
|
|
folders = mapAttrsToList ( _: folder: {
|
|
|
|
inherit (folder) path id label type;
|
|
|
|
devices = map (device: { deviceId = cfg.declarative.devices.${device}.id; }) folder.devices;
|
|
|
|
rescanIntervalS = folder.rescanInterval;
|
|
|
|
fsWatcherEnabled = folder.watch;
|
|
|
|
fsWatcherDelayS = folder.watchDelay;
|
|
|
|
ignorePerms = folder.ignorePerms;
|
2019-11-14 15:51:38 +00:00
|
|
|
versioning = folder.versioning;
|
2019-05-21 21:24:36 +01:00
|
|
|
}) (filterAttrs (
|
|
|
|
_: folder:
|
|
|
|
folder.enable
|
|
|
|
) cfg.declarative.folders);
|
2019-04-21 22:05:07 +01:00
|
|
|
|
|
|
|
# get the api key by parsing the config.xml
|
|
|
|
getApiKey = pkgs.writers.writeDash "getAPIKey" ''
|
|
|
|
${pkgs.libxml2}/bin/xmllint \
|
|
|
|
--xpath 'string(configuration/gui/apikey)'\
|
|
|
|
${cfg.configDir}/config.xml
|
|
|
|
'';
|
|
|
|
|
|
|
|
updateConfig = pkgs.writers.writeDash "merge-syncthing-config" ''
|
|
|
|
set -efu
|
|
|
|
# wait for syncthing port to open
|
|
|
|
until ${pkgs.curl}/bin/curl -Ss ${cfg.guiAddress} -o /dev/null; do
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
|
|
|
|
API_KEY=$(${getApiKey})
|
|
|
|
OLD_CFG=$(${pkgs.curl}/bin/curl -Ss \
|
|
|
|
-H "X-API-Key: $API_KEY" \
|
|
|
|
${cfg.guiAddress}/rest/system/config)
|
|
|
|
|
|
|
|
# generate the new config by merging with the nixos config options
|
|
|
|
NEW_CFG=$(echo "$OLD_CFG" | ${pkgs.jq}/bin/jq -s '.[] as $in | $in * {
|
|
|
|
"devices": (${builtins.toJSON devices}${optionalString (! cfg.declarative.overrideDevices) " + $in.devices"}),
|
|
|
|
"folders": (${builtins.toJSON folders}${optionalString (! cfg.declarative.overrideFolders) " + $in.folders"})
|
|
|
|
}')
|
|
|
|
|
|
|
|
# POST the new config to syncthing
|
|
|
|
echo "$NEW_CFG" | ${pkgs.curl}/bin/curl -Ss \
|
|
|
|
-H "X-API-Key: $API_KEY" \
|
|
|
|
${cfg.guiAddress}/rest/system/config -d @-
|
|
|
|
|
|
|
|
# restart syncthing after sending the new config
|
|
|
|
${pkgs.curl}/bin/curl -Ss \
|
|
|
|
-H "X-API-Key: $API_KEY" \
|
|
|
|
-X POST \
|
|
|
|
${cfg.guiAddress}/rest/system/restart
|
|
|
|
'';
|
2016-09-26 08:40:21 +01:00
|
|
|
in {
|
2014-04-03 17:54:10 +01:00
|
|
|
###### interface
|
|
|
|
options = {
|
|
|
|
services.syncthing = {
|
|
|
|
|
2016-04-14 15:44:02 +01:00
|
|
|
enable = mkEnableOption ''
|
|
|
|
Syncthing - the self-hosted open-source alternative
|
|
|
|
to Dropbox and Bittorrent Sync. Initial interface will be
|
|
|
|
available on http://127.0.0.1:8384/.
|
|
|
|
'';
|
2014-04-03 17:54:10 +01:00
|
|
|
|
2019-04-21 22:05:07 +01:00
|
|
|
declarative = {
|
|
|
|
cert = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
Path to users cert.pem file, will be copied into the syncthing's
|
|
|
|
<literal>configDir</literal>
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
key = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
Path to users key.pem file, will be copied into the syncthing's
|
|
|
|
<literal>configDir</literal>
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
overrideDevices = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Whether to delete the devices which are not configured via the
|
|
|
|
<literal>declarative.devices</literal> option.
|
|
|
|
If set to false, devices added via the webinterface will
|
|
|
|
persist but will have to be deleted manually.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
devices = mkOption {
|
|
|
|
default = {};
|
|
|
|
description = ''
|
|
|
|
Peers/devices which syncthing should communicate with.
|
|
|
|
'';
|
2019-05-26 08:20:12 +01:00
|
|
|
example = {
|
|
|
|
bigbox = {
|
2019-04-21 22:05:07 +01:00
|
|
|
id = "7CFNTQM-IMTJBHJ-3UWRDIU-ZGQJFR6-VCXZ3NB-XUH3KZO-N52ITXR-LAIYUAU";
|
|
|
|
addresses = [ "tcp://192.168.0.10:51820" ];
|
2019-05-26 08:20:12 +01:00
|
|
|
};
|
|
|
|
};
|
2019-12-05 05:49:23 +00:00
|
|
|
type = types.attrsOf (types.submodule ({ name, ... }: {
|
2019-04-21 22:05:07 +01:00
|
|
|
options = {
|
|
|
|
|
|
|
|
name = mkOption {
|
|
|
|
type = types.str;
|
2019-12-05 05:49:23 +00:00
|
|
|
default = name;
|
2019-04-21 22:05:07 +01:00
|
|
|
description = ''
|
|
|
|
Name of the device
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
addresses = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [];
|
|
|
|
description = ''
|
|
|
|
The addresses used to connect to the device.
|
|
|
|
If this is let empty, dynamic configuration is attempted
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
id = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
description = ''
|
|
|
|
The id of the other peer, this is mandatory. It's documented at
|
|
|
|
https://docs.syncthing.net/dev/device-ids.html
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
introducer = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
If the device should act as an introducer and be allowed
|
|
|
|
to add folders on this computer.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
}));
|
|
|
|
};
|
|
|
|
|
|
|
|
overrideFolders = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Whether to delete the folders which are not configured via the
|
|
|
|
<literal>declarative.folders</literal> option.
|
|
|
|
If set to false, folders added via the webinterface will persist
|
|
|
|
but will have to be deleted manually.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
folders = mkOption {
|
|
|
|
default = {};
|
|
|
|
description = ''
|
|
|
|
folders which should be shared by syncthing.
|
|
|
|
'';
|
2020-04-02 06:39:04 +01:00
|
|
|
example = literalExample ''
|
|
|
|
{
|
|
|
|
"/home/user/sync" = {
|
|
|
|
id = "syncme";
|
|
|
|
devices = [ "bigbox" ];
|
|
|
|
};
|
|
|
|
}
|
|
|
|
'';
|
2019-12-05 05:49:23 +00:00
|
|
|
type = types.attrsOf (types.submodule ({ name, ... }: {
|
2019-04-21 22:05:07 +01:00
|
|
|
options = {
|
|
|
|
|
2019-05-21 21:24:36 +01:00
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
share this folder.
|
|
|
|
This option is useful when you want to define all folders
|
|
|
|
in one place, but not every machine should share all folders.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2019-04-21 22:05:07 +01:00
|
|
|
path = mkOption {
|
|
|
|
type = types.str;
|
2019-12-05 05:49:23 +00:00
|
|
|
default = name;
|
2019-04-21 22:05:07 +01:00
|
|
|
description = ''
|
|
|
|
The path to the folder which should be shared.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
id = mkOption {
|
|
|
|
type = types.str;
|
2019-12-05 05:49:23 +00:00
|
|
|
default = name;
|
2019-04-21 22:05:07 +01:00
|
|
|
description = ''
|
|
|
|
The id of the folder. Must be the same on all devices.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
label = mkOption {
|
|
|
|
type = types.str;
|
2019-12-05 05:49:23 +00:00
|
|
|
default = name;
|
2019-04-21 22:05:07 +01:00
|
|
|
description = ''
|
|
|
|
The label of the folder.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
devices = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [];
|
|
|
|
description = ''
|
|
|
|
The devices this folder should be shared with. Must be defined
|
|
|
|
in the <literal>declarative.devices</literal> attribute.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2019-11-14 15:51:38 +00:00
|
|
|
versioning = mkOption {
|
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
How to keep changed/deleted files with syncthing.
|
|
|
|
There are 4 different types of versioning with different parameters.
|
|
|
|
See https://docs.syncthing.net/users/versioning.html
|
|
|
|
'';
|
|
|
|
example = [
|
|
|
|
{
|
|
|
|
versioning = {
|
|
|
|
type = "simple";
|
|
|
|
params.keep = "10";
|
|
|
|
};
|
|
|
|
}
|
|
|
|
{
|
|
|
|
versioning = {
|
|
|
|
type = "trashcan";
|
|
|
|
params.cleanoutDays = "1000";
|
|
|
|
};
|
|
|
|
}
|
|
|
|
{
|
|
|
|
versioning = {
|
|
|
|
type = "staggered";
|
|
|
|
params = {
|
|
|
|
cleanInterval = "3600";
|
|
|
|
maxAge = "31536000";
|
|
|
|
versionsPath = "/syncthing/backup";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
{
|
|
|
|
versioning = {
|
|
|
|
type = "external";
|
|
|
|
params.versionsPath = pkgs.writers.writeBash "backup" ''
|
|
|
|
folderpath="$1"
|
|
|
|
filepath="$2"
|
|
|
|
rm -rf "$folderpath/$filepath"
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
}
|
|
|
|
];
|
|
|
|
type = with types; nullOr (submodule {
|
|
|
|
options = {
|
|
|
|
type = mkOption {
|
|
|
|
type = enum [ "external" "simple" "staggered" "trashcan" ];
|
|
|
|
description = ''
|
|
|
|
Type of versioning.
|
|
|
|
See https://docs.syncthing.net/users/versioning.html
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
params = mkOption {
|
|
|
|
type = attrsOf (either str path);
|
|
|
|
description = ''
|
|
|
|
Parameters for versioning. Structure depends on versioning.type.
|
|
|
|
See https://docs.syncthing.net/users/versioning.html
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-04-21 22:05:07 +01:00
|
|
|
rescanInterval = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 3600;
|
|
|
|
description = ''
|
|
|
|
How often the folders should be rescaned for changes.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
type = mkOption {
|
|
|
|
type = types.enum [ "sendreceive" "sendonly" "receiveonly" ];
|
|
|
|
default = "sendreceive";
|
|
|
|
description = ''
|
|
|
|
Whether to send only changes from this folder, only receive them
|
|
|
|
or propagate both.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
watch = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Whether the folder should be watched for changes by inotify.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
watchDelay = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 10;
|
|
|
|
description = ''
|
|
|
|
The delay after an inotify event is triggered.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
ignorePerms = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Whether to propagate permission changes.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
}));
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2018-10-09 21:13:58 +01:00
|
|
|
guiAddress = mkOption {
|
2018-10-14 05:46:36 +01:00
|
|
|
type = types.str;
|
2018-10-09 21:13:58 +01:00
|
|
|
default = "127.0.0.1:8384";
|
|
|
|
description = ''
|
|
|
|
Address to serve the GUI.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2016-04-14 09:42:04 +01:00
|
|
|
systemService = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = "Auto launch Syncthing as a system service.";
|
|
|
|
};
|
|
|
|
|
2014-04-03 17:54:10 +01:00
|
|
|
user = mkOption {
|
2018-10-14 05:46:36 +01:00
|
|
|
type = types.str;
|
2016-04-01 00:26:52 +01:00
|
|
|
default = defaultUser;
|
2014-04-03 17:54:10 +01:00
|
|
|
description = ''
|
2016-04-14 09:42:04 +01:00
|
|
|
Syncthing will be run under this user (user will be created if it doesn't exist.
|
|
|
|
This can be your user name).
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
group = mkOption {
|
2018-10-14 05:46:36 +01:00
|
|
|
type = types.str;
|
2019-07-10 14:29:25 +01:00
|
|
|
default = defaultUser;
|
2016-04-14 09:42:04 +01:00
|
|
|
description = ''
|
|
|
|
Syncthing will be run under this group (group will not be created if it doesn't exist.
|
|
|
|
This can be your user name).
|
2014-04-03 17:54:10 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2015-12-15 12:07:40 +00:00
|
|
|
all_proxy = mkOption {
|
2018-10-14 05:46:36 +01:00
|
|
|
type = with types; nullOr str;
|
2016-04-01 00:26:52 +01:00
|
|
|
default = null;
|
2015-12-15 12:07:40 +00:00
|
|
|
example = "socks5://address.com:1234";
|
|
|
|
description = ''
|
|
|
|
Overwrites all_proxy environment variable for the syncthing process to
|
|
|
|
the given value. This is normaly used to let relay client connect
|
|
|
|
through SOCKS5 proxy server.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2014-04-03 17:54:10 +01:00
|
|
|
dataDir = mkOption {
|
2016-04-01 00:26:52 +01:00
|
|
|
type = types.path;
|
2014-04-03 17:54:10 +01:00
|
|
|
default = "/var/lib/syncthing";
|
2018-10-08 22:24:36 +01:00
|
|
|
description = ''
|
|
|
|
Path where synced directories will exist.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
configDir = mkOption {
|
|
|
|
type = types.path;
|
2014-04-03 17:54:10 +01:00
|
|
|
description = ''
|
2015-08-27 15:01:10 +01:00
|
|
|
Path where the settings and keys will exist.
|
2014-04-03 17:54:10 +01:00
|
|
|
'';
|
2018-10-08 22:24:36 +01:00
|
|
|
default =
|
|
|
|
let
|
|
|
|
nixos = config.system.stateVersion;
|
|
|
|
cond = versionAtLeast nixos "19.03";
|
|
|
|
in cfg.dataDir + (optionalString cond "/.config/syncthing");
|
2014-04-03 17:54:10 +01:00
|
|
|
};
|
|
|
|
|
2016-09-26 08:40:21 +01:00
|
|
|
openDefaultPorts = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
example = literalExample "true";
|
|
|
|
description = ''
|
|
|
|
Open the default ports in the firewall:
|
|
|
|
- TCP 22000 for transfers
|
|
|
|
- UDP 21027 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 are running only a single instance on this machine using the default ports, enable this.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2015-11-28 19:17:49 +00:00
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.syncthing;
|
2016-01-17 18:34:55 +00:00
|
|
|
defaultText = "pkgs.syncthing";
|
2015-11-28 19:17:49 +00:00
|
|
|
example = literalExample "pkgs.syncthing";
|
|
|
|
description = ''
|
|
|
|
Syncthing package to use.
|
|
|
|
'';
|
|
|
|
};
|
2014-04-03 17:54:10 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2018-02-23 18:59:06 +00:00
|
|
|
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 webinterface.
|
|
|
|
'')
|
|
|
|
];
|
2014-04-03 17:54:10 +01:00
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
2014-04-04 09:46:19 +01:00
|
|
|
config = mkIf cfg.enable {
|
2014-04-03 17:54:10 +01:00
|
|
|
|
2016-09-26 08:40:21 +01:00
|
|
|
networking.firewall = mkIf cfg.openDefaultPorts {
|
|
|
|
allowedTCPPorts = [ 22000 ];
|
|
|
|
allowedUDPPorts = [ 21027 ];
|
|
|
|
};
|
|
|
|
|
2018-02-23 18:59:06 +00:00
|
|
|
systemd.packages = [ pkgs.syncthing ];
|
2016-09-26 08:40:21 +01:00
|
|
|
|
2019-07-29 19:56:12 +01:00
|
|
|
users.users = mkIf (cfg.systemService && cfg.user == defaultUser) {
|
2019-08-13 22:52:01 +01:00
|
|
|
${defaultUser} =
|
2016-04-14 09:42:04 +01:00
|
|
|
{ group = cfg.group;
|
2016-04-01 00:26:52 +01:00
|
|
|
home = cfg.dataDir;
|
|
|
|
createHome = true;
|
|
|
|
uid = config.ids.uids.syncthing;
|
|
|
|
description = "Syncthing daemon user";
|
|
|
|
};
|
2019-07-29 19:56:12 +01:00
|
|
|
};
|
2016-04-01 00:26:52 +01:00
|
|
|
|
2019-07-29 19:56:12 +01:00
|
|
|
users.groups = mkIf (cfg.systemService && cfg.group == defaultUser) {
|
2019-08-13 22:52:01 +01:00
|
|
|
${defaultUser}.gid =
|
2016-04-01 00:26:52 +01:00
|
|
|
config.ids.gids.syncthing;
|
|
|
|
};
|
|
|
|
|
2016-08-06 16:20:18 +01:00
|
|
|
systemd.services = {
|
2016-09-26 08:40:21 +01:00
|
|
|
syncthing = mkIf cfg.systemService {
|
|
|
|
description = "Syncthing service";
|
|
|
|
after = [ "network.target" ];
|
|
|
|
environment = {
|
|
|
|
STNORESTART = "yes";
|
|
|
|
STNOUPGRADE = "yes";
|
|
|
|
inherit (cfg) all_proxy;
|
|
|
|
} // config.networking.proxy.envVars;
|
2016-04-14 09:42:04 +01:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
2016-09-26 08:40:21 +01:00
|
|
|
serviceConfig = {
|
|
|
|
Restart = "on-failure";
|
|
|
|
SuccessExitStatus = "2 3 4";
|
|
|
|
RestartForceExitStatus="3 4";
|
2016-04-14 09:42:04 +01:00
|
|
|
User = cfg.user;
|
2016-09-26 08:40:21 +01:00
|
|
|
Group = cfg.group;
|
2019-04-21 22:05:07 +01:00
|
|
|
ExecStartPre = mkIf (cfg.declarative.cert != null || cfg.declarative.key != null)
|
|
|
|
"+${pkgs.writers.writeBash "syncthing-copy-keys" ''
|
2019-07-10 14:29:25 +01:00
|
|
|
install -dm700 -o ${cfg.user} -g ${cfg.group} ${cfg.configDir}
|
2019-04-21 22:05:07 +01:00
|
|
|
${optionalString (cfg.declarative.cert != null) ''
|
2019-07-10 14:29:25 +01:00
|
|
|
install -Dm400 -o ${cfg.user} -g ${cfg.group} ${toString cfg.declarative.cert} ${cfg.configDir}/cert.pem
|
2019-04-21 22:05:07 +01:00
|
|
|
''}
|
|
|
|
${optionalString (cfg.declarative.key != null) ''
|
2019-07-10 14:29:25 +01:00
|
|
|
install -Dm400 -o ${cfg.user} -g ${cfg.group} ${toString cfg.declarative.key} ${cfg.configDir}/key.pem
|
2019-04-21 22:05:07 +01:00
|
|
|
''}
|
|
|
|
''}"
|
|
|
|
;
|
2018-10-09 21:13:58 +01:00
|
|
|
ExecStart = ''
|
|
|
|
${cfg.package}/bin/syncthing \
|
|
|
|
-no-browser \
|
|
|
|
-gui-address=${cfg.guiAddress} \
|
2018-10-08 22:24:36 +01:00
|
|
|
-home=${cfg.configDir}
|
2018-10-09 21:13:58 +01:00
|
|
|
'';
|
2020-01-20 20:15:47 +00:00
|
|
|
MemoryDenyWriteExecute = true;
|
|
|
|
NoNewPrivileges = true;
|
|
|
|
PrivateDevices = true;
|
|
|
|
PrivateMounts = true;
|
|
|
|
PrivateTmp = true;
|
|
|
|
PrivateUsers = true;
|
|
|
|
ProtectControlGroups = true;
|
|
|
|
ProtectHostname = true;
|
|
|
|
ProtectKernelModules = true;
|
|
|
|
ProtectKernelTunables = true;
|
|
|
|
RestrictNamespaces = true;
|
|
|
|
RestrictRealtime = true;
|
|
|
|
RestrictSUIDSGID = true;
|
|
|
|
CapabilityBoundingSet = [
|
|
|
|
"~CAP_SYS_PTRACE" "~CAP_SYS_ADMIN"
|
|
|
|
"~CAP_SETGID" "~CAP_SETUID" "~CAP_SETPCAP"
|
|
|
|
"~CAP_SYS_TIME" "~CAP_KILL"
|
|
|
|
];
|
2014-04-03 17:54:10 +01:00
|
|
|
};
|
2016-09-26 08:40:21 +01:00
|
|
|
};
|
2019-05-28 14:38:10 +01:00
|
|
|
syncthing-init = mkIf (
|
|
|
|
cfg.declarative.devices != {} || cfg.declarative.folders != {}
|
|
|
|
) {
|
2019-04-21 22:05:07 +01:00
|
|
|
after = [ "syncthing.service" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
User = cfg.user;
|
|
|
|
RemainAfterExit = true;
|
|
|
|
Type = "oneshot";
|
|
|
|
ExecStart = updateConfig;
|
|
|
|
};
|
|
|
|
};
|
2014-04-03 17:54:10 +01:00
|
|
|
|
2016-09-26 08:40:21 +01:00
|
|
|
syncthing-resume = {
|
|
|
|
wantedBy = [ "suspend.target" ];
|
2016-04-14 09:42:04 +01:00
|
|
|
};
|
2016-08-06 16:20:18 +01:00
|
|
|
};
|
2014-04-03 17:54:10 +01:00
|
|
|
};
|
|
|
|
}
|