19.09: migrate to upstream syncthing
This commit is contained in:
parent
2046a2dc10
commit
e4ee96e986
8 changed files with 221 additions and 499 deletions
|
@ -1,7 +1,7 @@
|
||||||
{ config, pkgs, lib, ... }:
|
{ config, pkgs, lib, ... }:
|
||||||
{
|
{
|
||||||
|
|
||||||
test.services.syncthing = {
|
services.syncthing = {
|
||||||
enable = true;
|
enable = true;
|
||||||
openDefaultPorts = false;
|
openDefaultPorts = false;
|
||||||
user = "palo";
|
user = "palo";
|
||||||
|
@ -16,20 +16,49 @@
|
||||||
|
|
||||||
# on encrypted drive
|
# on encrypted drive
|
||||||
# ------------------
|
# ------------------
|
||||||
desktop.path = "/home/palo/desktop";
|
desktop = {
|
||||||
finance.path = "/home/palo/finance";
|
enable = true;
|
||||||
|
path = "/home/palo/desktop";
|
||||||
|
};
|
||||||
|
finance = {
|
||||||
|
enable = true;
|
||||||
|
path = "/home/palo/finance";
|
||||||
|
};
|
||||||
|
|
||||||
# no need to be encrypted
|
# no need to be encrypted
|
||||||
# -----------------------
|
# -----------------------
|
||||||
book.path = "/home/palo/books";
|
book = {
|
||||||
fotos-encrypted.path = "/home/palo/private/.fotos.ct";
|
enable = true;
|
||||||
kruck-pepe.path = "/home/palo/pepe-kruck";
|
path = "/home/palo/books";
|
||||||
music-library.path = "/home/palo/music-library";
|
};
|
||||||
music-projects.path = "/home/palo/music-projects";
|
kruck-pepe = {
|
||||||
porani-pepe.path = "/home/palo/pepe-porani";
|
enable = true;
|
||||||
schasch-pepe.path = "/home/palo/pepe-schasch";
|
path = "/home/palo/pepe-kruck";
|
||||||
smartphone-fotos.path = "/home/palo/smartphone-fotos";
|
};
|
||||||
workout-pepe.path = "/home/palo/pepe-workout";
|
music-library = {
|
||||||
|
enable = true;
|
||||||
|
path = "/home/palo/music-library";
|
||||||
|
};
|
||||||
|
music-projects = {
|
||||||
|
enable = true;
|
||||||
|
path = "/home/palo/music-projects";
|
||||||
|
};
|
||||||
|
porani-pepe = {
|
||||||
|
enable = true;
|
||||||
|
path = "/home/palo/pepe-porani";
|
||||||
|
};
|
||||||
|
schasch-pepe = {
|
||||||
|
enable = true;
|
||||||
|
path = "/home/palo/pepe-schasch";
|
||||||
|
};
|
||||||
|
smartphone-fotos = {
|
||||||
|
enable = true;
|
||||||
|
path = "/home/palo/smartphone-fotos";
|
||||||
|
};
|
||||||
|
workout-pepe = {
|
||||||
|
enable = true;
|
||||||
|
path = "/home/palo/pepe-workout";
|
||||||
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{ config, pkgs, lib, ... }:
|
{ config, pkgs, lib, ... }:
|
||||||
{
|
{
|
||||||
|
|
||||||
test.services.syncthing = {
|
services.syncthing = {
|
||||||
enable = true;
|
enable = true;
|
||||||
openDefaultPorts = true;
|
openDefaultPorts = true;
|
||||||
declarative = {
|
declarative = {
|
||||||
|
@ -11,16 +11,37 @@
|
||||||
folders = {
|
folders = {
|
||||||
# on encrypted device
|
# on encrypted device
|
||||||
# -------------------
|
# -------------------
|
||||||
desktop.path = "/var/lib/syncthing/desktop";
|
desktop = {
|
||||||
finance.path = "/var/lib/syncthing/finance";
|
enable = true;
|
||||||
lost-fotos.path = "/var/lib/syncthing/lost-fotos.ct";
|
path = "/var/lib/syncthing/desktop";
|
||||||
|
};
|
||||||
|
finance = {
|
||||||
|
enable = true;
|
||||||
|
path = "/var/lib/syncthing/finance";
|
||||||
|
};
|
||||||
|
lost-fotos = {
|
||||||
|
enable = true;
|
||||||
|
path = "/var/lib/syncthing/lost-fotos.ct";
|
||||||
|
};
|
||||||
|
|
||||||
# on media hard drive (not encrypted)
|
# on media hard drive (not encrypted)
|
||||||
# -----------------------------------
|
# -----------------------------------
|
||||||
movies.path = "/media/movies";
|
movies = {
|
||||||
music-library.path = "/media/music-library";
|
enable = true;
|
||||||
podcasts.path = "/media/podcasts";
|
path = "/media/movies";
|
||||||
series.path = "/media/series";
|
};
|
||||||
|
music-library = {
|
||||||
|
enable = true;
|
||||||
|
path = "/media/music-library";
|
||||||
|
};
|
||||||
|
podcasts = {
|
||||||
|
enable = true;
|
||||||
|
path = "/media/podcasts";
|
||||||
|
};
|
||||||
|
series = {
|
||||||
|
enable = true;
|
||||||
|
path = "/media/series";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{ config, pkgs, lib, ... }:
|
{ config, pkgs, lib, ... }:
|
||||||
{
|
{
|
||||||
|
|
||||||
test.services.syncthing = {
|
services.syncthing = {
|
||||||
enable = true;
|
enable = true;
|
||||||
openDefaultPorts = false;
|
openDefaultPorts = false;
|
||||||
user = "palo";
|
user = "palo";
|
||||||
|
@ -15,16 +15,37 @@
|
||||||
|
|
||||||
# on encrypted drive
|
# on encrypted drive
|
||||||
# ------------------
|
# ------------------
|
||||||
desktop.path = "/home/palo/desktop";
|
desktop = {
|
||||||
finance.path = "/home/palo/finance";
|
enable = true;
|
||||||
lost-fotos.path = "/home/palo/.lost-fotos.ct";
|
path = "/home/palo/desktop";
|
||||||
|
};
|
||||||
|
finance = {
|
||||||
|
enable = true;
|
||||||
|
path = "/home/palo/finance";
|
||||||
|
};
|
||||||
|
lost-fotos = {
|
||||||
|
enable = true;
|
||||||
|
path = "/home/palo/.lost-fotos.ct";
|
||||||
|
};
|
||||||
|
smartphone-fotos = {
|
||||||
|
enable = true;
|
||||||
|
path = "/home/palo/smartphone-fotos";
|
||||||
|
};
|
||||||
|
|
||||||
# no need to be encrypted
|
# no need to be encrypted
|
||||||
# -----------------------
|
# -----------------------
|
||||||
book.path = "/home/palo/books";
|
book = {
|
||||||
fotos-encrypted.path = "/home/palo/private/.fotos.ct";
|
enable = true;
|
||||||
music-library.path = "/home/palo/music-library";
|
path = "/home/palo/books";
|
||||||
music-projects.path = "/home/palo/music-projects";
|
};
|
||||||
|
music-library = {
|
||||||
|
enable = true;
|
||||||
|
path = "/home/palo/music-library";
|
||||||
|
};
|
||||||
|
music-projects = {
|
||||||
|
enable = true;
|
||||||
|
path = "/home/palo/music-projects";
|
||||||
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{ config, pkgs, lib, ... }:
|
{ config, pkgs, lib, ... }:
|
||||||
{
|
{
|
||||||
|
|
||||||
test.services.syncthing = {
|
services.syncthing = {
|
||||||
enable = true;
|
enable = true;
|
||||||
openDefaultPorts = false;
|
openDefaultPorts = false;
|
||||||
dataDir = "/home/syncthing";
|
dataDir = "/home/syncthing";
|
||||||
|
@ -17,20 +17,53 @@
|
||||||
|
|
||||||
# on encrypted hard drive
|
# on encrypted hard drive
|
||||||
# -----------------------
|
# -----------------------
|
||||||
desktop.path = "/home/syncthing/desktop";
|
desktop = {
|
||||||
finance.path = "/home/syncthing/finance";
|
enable = true;
|
||||||
lost-fotos.path = "/home/syncthing/lost-fotos.ct";
|
path = "/home/syncthing/desktop";
|
||||||
music-projects.path = "/home/syncthing/music-projects";
|
};
|
||||||
video-material.path = "/home/syncthing/video-material";
|
finance = {
|
||||||
|
enable = true;
|
||||||
|
path = "/home/syncthing/finance";
|
||||||
|
};
|
||||||
|
lost-fotos = {
|
||||||
|
enable = true;
|
||||||
|
path = "/home/syncthing/lost-fotos.ct";
|
||||||
|
};
|
||||||
|
music-projects = {
|
||||||
|
enable = true;
|
||||||
|
path = "/home/syncthing/music-projects";
|
||||||
|
};
|
||||||
|
video-material = {
|
||||||
|
enable = true;
|
||||||
|
path = "/home/syncthing/video-material";
|
||||||
|
};
|
||||||
|
|
||||||
# on media hard drive (not encrypted)
|
# on media hard drive (not encrypted)
|
||||||
# -----------------------------------
|
# -----------------------------------
|
||||||
music-library-free.path = "/media/syncthing/music-library-free";
|
music-library-free = {
|
||||||
samples.path = "/media/syncthing/samples";
|
enable = true;
|
||||||
movies.path = "/media/syncthing/movies";
|
path = "/media/syncthing/music-library-free";
|
||||||
music-library.path = "/media/syncthing/music-library";
|
};
|
||||||
podcasts.path = "/media/syncthing/podcasts";
|
samples = {
|
||||||
series.path = "/media/syncthing/series";
|
enable = true;
|
||||||
|
path = "/media/syncthing/samples";
|
||||||
|
};
|
||||||
|
movies = {
|
||||||
|
enable = true;
|
||||||
|
path = "/media/syncthing/movies";
|
||||||
|
};
|
||||||
|
music-library = {
|
||||||
|
enable = true;
|
||||||
|
path = "/media/syncthing/music-library";
|
||||||
|
};
|
||||||
|
podcasts = {
|
||||||
|
enable = true;
|
||||||
|
path = "/media/syncthing/podcasts";
|
||||||
|
};
|
||||||
|
series = {
|
||||||
|
enable = true;
|
||||||
|
path = "/media/syncthing/series";
|
||||||
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{ config, pkgs, lib, ... }:
|
{ config, pkgs, lib, ... }:
|
||||||
{
|
{
|
||||||
|
|
||||||
test.services.syncthing = {
|
services.syncthing = {
|
||||||
enable = true;
|
enable = true;
|
||||||
openDefaultPorts = false;
|
openDefaultPorts = false;
|
||||||
user = "palo";
|
user = "palo";
|
||||||
|
@ -16,29 +16,64 @@
|
||||||
|
|
||||||
# on encrypted drive
|
# on encrypted drive
|
||||||
# ------------------
|
# ------------------
|
||||||
desktop.path = "/home/palo/desktop";
|
desktop = {
|
||||||
finance.path = "/home/palo/finance";
|
enable = true;
|
||||||
lost-fotos.path = "/home/palo/.lost-fotos.ct";
|
path = "/home/palo/desktop";
|
||||||
|
};
|
||||||
|
finance = {
|
||||||
|
enable = true;
|
||||||
|
path = "/home/palo/finance";
|
||||||
|
};
|
||||||
|
lost-fotos = {
|
||||||
|
enable = true;
|
||||||
|
path = "/home/palo/.lost-fotos.ct";
|
||||||
|
};
|
||||||
|
|
||||||
# no need to be encrypted
|
# no need to be encrypted
|
||||||
# -----------------------
|
# -----------------------
|
||||||
book.path = "/home/palo/books";
|
book = {
|
||||||
#desktop-encrypted.path = "/home/palo/.desktop.ct";
|
enable = true;
|
||||||
#finance-encrypted.path = "/home/palo/.finance.ct";
|
path = "/home/palo/books";
|
||||||
fotos-encrypted.path = "/home/palo/private/.fotos.ct";
|
};
|
||||||
kruck-workout.path = "/home/palo/workout-kruck";
|
music-library-free = {
|
||||||
music-library-free.path = "/home/palo/music-library-free";
|
enable = true;
|
||||||
music-library.path = "/home/palo/music-library";
|
path = "/home/palo/music-library-free";
|
||||||
music-projects.path = "/home/palo/music-projects";
|
};
|
||||||
porani-workout.path = "/home/palo/workout-porani";
|
music-library = {
|
||||||
samples.path = "/home/palo/samples";
|
enable = true;
|
||||||
schasch-workout.path = "/home/palo/workout-schasch";
|
path = "/home/palo/music-library";
|
||||||
smartphone-fotos.path = "/home/palo/smartphone-fotos";
|
};
|
||||||
smartphone-music.path = "/home/palo/smartphone-music";
|
music-projects = {
|
||||||
video-material.path = "/home/palo/video-material";
|
enable = true;
|
||||||
workout-pepe.path = "/home/palo/workout-pepe";
|
path = "/home/palo/music-projects";
|
||||||
windows-sync.path = "/home/palo/windows-sync";
|
};
|
||||||
|
porani-workout = {
|
||||||
|
enable = true;
|
||||||
|
path = "/home/palo/workout-porani";
|
||||||
|
};
|
||||||
|
samples = {
|
||||||
|
enable = true;
|
||||||
|
path = "/home/palo/samples";
|
||||||
|
};
|
||||||
|
smartphone-fotos = {
|
||||||
|
enable = true;
|
||||||
|
path = "/home/palo/smartphone-fotos";
|
||||||
|
};
|
||||||
|
smartphone-music = {
|
||||||
|
path = "/home/palo/smartphone-music";
|
||||||
|
};
|
||||||
|
video-material = {
|
||||||
|
enable = true;
|
||||||
|
path = "/home/palo/video-material";
|
||||||
|
};
|
||||||
|
workout-pepe = {
|
||||||
|
enable = true;
|
||||||
|
path = "/home/palo/workout-pepe";
|
||||||
|
};
|
||||||
|
windows-sync = {
|
||||||
|
enable = true;
|
||||||
|
path = "/home/palo/windows-sync";
|
||||||
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,8 +2,6 @@
|
||||||
|
|
||||||
imports = [
|
imports = [
|
||||||
|
|
||||||
./later/syncthing.nix
|
|
||||||
|
|
||||||
./services/castget.nix
|
./services/castget.nix
|
||||||
./services/home-assistant.nix
|
./services/home-assistant.nix
|
||||||
./services/lektor.nix
|
./services/lektor.nix
|
||||||
|
|
|
@ -1,434 +0,0 @@
|
||||||
{ config, lib, pkgs, ... }:
|
|
||||||
|
|
||||||
with lib;
|
|
||||||
|
|
||||||
let
|
|
||||||
cfg = config.test.services.syncthing;
|
|
||||||
defaultUser = "syncthing";
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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;
|
|
||||||
}) (filterAttrs (
|
|
||||||
_: value:
|
|
||||||
(value.path != null) && (value.devices != [])
|
|
||||||
) cfg.declarative.folders);
|
|
||||||
|
|
||||||
# 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
|
|
||||||
'';
|
|
||||||
in {
|
|
||||||
###### interface
|
|
||||||
options = {
|
|
||||||
test.services.syncthing = {
|
|
||||||
|
|
||||||
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/.
|
|
||||||
'';
|
|
||||||
|
|
||||||
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.
|
|
||||||
'';
|
|
||||||
example = [
|
|
||||||
{
|
|
||||||
name = "bigbox";
|
|
||||||
id = "7CFNTQM-IMTJBHJ-3UWRDIU-ZGQJFR6-VCXZ3NB-XUH3KZO-N52ITXR-LAIYUAU";
|
|
||||||
addresses = [ "tcp://192.168.0.10:51820" ];
|
|
||||||
}
|
|
||||||
];
|
|
||||||
type = types.attrsOf (types.submodule ({ config, ... }: {
|
|
||||||
options = {
|
|
||||||
|
|
||||||
name = mkOption {
|
|
||||||
type = types.str;
|
|
||||||
default = config._module.args.name;
|
|
||||||
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.
|
|
||||||
'';
|
|
||||||
type = types.attrsOf (types.submodule ({ config, ... }: {
|
|
||||||
options = {
|
|
||||||
|
|
||||||
path = mkOption {
|
|
||||||
type = types.nullOr types.str;
|
|
||||||
default = null;
|
|
||||||
description = ''
|
|
||||||
The path to the folder which should be shared.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
id = mkOption {
|
|
||||||
type = types.str;
|
|
||||||
default = config._module.args.name;
|
|
||||||
description = ''
|
|
||||||
The id of the folder. Must be the same on all devices.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
label = mkOption {
|
|
||||||
type = types.str;
|
|
||||||
default = config._module.args.name;
|
|
||||||
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.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
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.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
};
|
|
||||||
}));
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
guiAddress = mkOption {
|
|
||||||
type = types.str;
|
|
||||||
default = "127.0.0.1:8384";
|
|
||||||
description = ''
|
|
||||||
Address to serve the GUI.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
systemService = mkOption {
|
|
||||||
type = types.bool;
|
|
||||||
default = true;
|
|
||||||
description = "Auto launch Syncthing as a system service.";
|
|
||||||
};
|
|
||||||
|
|
||||||
user = mkOption {
|
|
||||||
type = types.str;
|
|
||||||
default = defaultUser;
|
|
||||||
description = ''
|
|
||||||
Syncthing will be run under this user (user will be created if it doesn't exist.
|
|
||||||
This can be your user name).
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
group = mkOption {
|
|
||||||
type = types.str;
|
|
||||||
default = "nogroup";
|
|
||||||
description = ''
|
|
||||||
Syncthing will be run under this group (group will not be created if it doesn't exist.
|
|
||||||
This can be your user name).
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
all_proxy = mkOption {
|
|
||||||
type = with types; nullOr str;
|
|
||||||
default = null;
|
|
||||||
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.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
dataDir = mkOption {
|
|
||||||
type = types.path;
|
|
||||||
default = "/var/lib/syncthing";
|
|
||||||
description = ''
|
|
||||||
Path where synced directories will exist.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
configDir = mkOption {
|
|
||||||
type = types.path;
|
|
||||||
description = ''
|
|
||||||
Path where the settings and keys will exist.
|
|
||||||
'';
|
|
||||||
default =
|
|
||||||
let
|
|
||||||
nixos = config.system.stateVersion;
|
|
||||||
cond = versionAtLeast nixos "19.03";
|
|
||||||
in cfg.dataDir + (optionalString cond "/.config/syncthing");
|
|
||||||
};
|
|
||||||
|
|
||||||
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.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
package = mkOption {
|
|
||||||
type = types.package;
|
|
||||||
default = pkgs.syncthing;
|
|
||||||
defaultText = "pkgs.syncthing";
|
|
||||||
example = literalExample "pkgs.syncthing";
|
|
||||||
description = ''
|
|
||||||
Syncthing package to use.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
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.
|
|
||||||
'')
|
|
||||||
];
|
|
||||||
|
|
||||||
###### implementation
|
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
|
||||||
|
|
||||||
networking.firewall = mkIf cfg.openDefaultPorts {
|
|
||||||
allowedTCPPorts = [ 22000 ];
|
|
||||||
allowedUDPPorts = [ 21027 ];
|
|
||||||
};
|
|
||||||
|
|
||||||
systemd.packages = [ pkgs.syncthing ];
|
|
||||||
|
|
||||||
users = mkIf (cfg.systemService && cfg.user == defaultUser) {
|
|
||||||
users."${defaultUser}" =
|
|
||||||
{ group = cfg.group;
|
|
||||||
home = cfg.dataDir;
|
|
||||||
createHome = true;
|
|
||||||
uid = config.ids.uids.syncthing;
|
|
||||||
description = "Syncthing daemon user";
|
|
||||||
};
|
|
||||||
|
|
||||||
groups."${defaultUser}".gid =
|
|
||||||
config.ids.gids.syncthing;
|
|
||||||
};
|
|
||||||
|
|
||||||
systemd.services = {
|
|
||||||
syncthing = mkIf cfg.systemService {
|
|
||||||
description = "Syncthing service";
|
|
||||||
after = [ "network.target" ];
|
|
||||||
environment = {
|
|
||||||
STNORESTART = "yes";
|
|
||||||
STNOUPGRADE = "yes";
|
|
||||||
inherit (cfg) all_proxy;
|
|
||||||
} // config.networking.proxy.envVars;
|
|
||||||
wantedBy = [ "multi-user.target" ];
|
|
||||||
serviceConfig = {
|
|
||||||
Restart = "on-failure";
|
|
||||||
SuccessExitStatus = "2 3 4";
|
|
||||||
RestartForceExitStatus="3 4";
|
|
||||||
User = cfg.user;
|
|
||||||
Group = cfg.group;
|
|
||||||
ExecStartPre = mkIf (cfg.declarative.cert != null || cfg.declarative.key != null)
|
|
||||||
"+${pkgs.writers.writeBash "syncthing-copy-keys" ''
|
|
||||||
mkdir -p ${cfg.configDir}
|
|
||||||
chown ${cfg.user}:${cfg.group} ${cfg.configDir}
|
|
||||||
chmod 700 ${cfg.configDir}
|
|
||||||
${optionalString (cfg.declarative.cert != null) ''
|
|
||||||
cp ${toString cfg.declarative.cert} ${cfg.configDir}/cert.pem
|
|
||||||
chown ${cfg.user}:${cfg.group} ${cfg.configDir}/cert.pem
|
|
||||||
chmod 400 ${cfg.configDir}/cert.pem
|
|
||||||
''}
|
|
||||||
${optionalString (cfg.declarative.key != null) ''
|
|
||||||
cp ${toString cfg.declarative.key} ${cfg.configDir}/key.pem
|
|
||||||
chown ${cfg.user}:${cfg.group} ${cfg.configDir}/key.pem
|
|
||||||
chmod 400 ${cfg.configDir}/key.pem
|
|
||||||
''}
|
|
||||||
''}"
|
|
||||||
;
|
|
||||||
ExecStart = ''
|
|
||||||
${cfg.package}/bin/syncthing \
|
|
||||||
-no-browser \
|
|
||||||
-gui-address=${cfg.guiAddress} \
|
|
||||||
-home=${cfg.configDir}
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
};
|
|
||||||
syncthing-init = {
|
|
||||||
after = [ "syncthing.service" ];
|
|
||||||
wantedBy = [ "multi-user.target" ];
|
|
||||||
|
|
||||||
serviceConfig = {
|
|
||||||
User = cfg.user;
|
|
||||||
RemainAfterExit = true;
|
|
||||||
Type = "oneshot";
|
|
||||||
ExecStart = updateConfig;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
syncthing-resume = {
|
|
||||||
wantedBy = [ "suspend.target" ];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -2,7 +2,7 @@
|
||||||
with lib;
|
with lib;
|
||||||
{
|
{
|
||||||
|
|
||||||
test.services.syncthing = {
|
services.syncthing = {
|
||||||
guiAddress = "${config.networking.hostName}.private:8384";
|
guiAddress = "${config.networking.hostName}.private:8384";
|
||||||
declarative = {
|
declarative = {
|
||||||
overrideDevices = true;
|
overrideDevices = true;
|
||||||
|
@ -48,10 +48,12 @@ with lib;
|
||||||
# needs to be on encrypted drives
|
# needs to be on encrypted drives
|
||||||
# -------------------------------
|
# -------------------------------
|
||||||
desktop = {
|
desktop = {
|
||||||
|
enable = lib.mkDefault false;
|
||||||
watch = false;
|
watch = false;
|
||||||
devices = [ "workout" "workhorse" "pepe" "sterni" "porani" ];
|
devices = [ "workout" "workhorse" "pepe" "sterni" "porani" ];
|
||||||
};
|
};
|
||||||
finance = {
|
finance = {
|
||||||
|
enable = lib.mkDefault false;
|
||||||
watch = false;
|
watch = false;
|
||||||
devices = [ "workout" "workhorse" "pepe" "sterni" "porani" ];
|
devices = [ "workout" "workhorse" "pepe" "sterni" "porani" ];
|
||||||
};
|
};
|
||||||
|
@ -59,65 +61,78 @@ with lib;
|
||||||
# no need to be stored on encrypted drives
|
# no need to be stored on encrypted drives
|
||||||
# ----------------------------------------
|
# ----------------------------------------
|
||||||
book = {
|
book = {
|
||||||
|
enable = lib.mkDefault false;
|
||||||
id = "wwbvs-5lfbh";
|
id = "wwbvs-5lfbh";
|
||||||
watch = false;
|
watch = false;
|
||||||
devices = [ "workout" "pepe" "sterni" ];
|
devices = [ "workout" "pepe" "sterni" ];
|
||||||
};
|
};
|
||||||
lost-fotos = {
|
lost-fotos = {
|
||||||
|
enable = lib.mkDefault false;
|
||||||
watch = false;
|
watch = false;
|
||||||
devices = [ "workout" "workhorse" "sterni" "porani" ];
|
devices = [ "workout" "workhorse" "sterni" "porani" ];
|
||||||
};
|
};
|
||||||
movies = {
|
movies = {
|
||||||
|
enable = lib.mkDefault false;
|
||||||
id = "vatmy-c2qf4";
|
id = "vatmy-c2qf4";
|
||||||
watch = false;
|
watch = false;
|
||||||
devices = [ "workhorse" "porani" ];
|
devices = [ "workhorse" "porani" ];
|
||||||
};
|
};
|
||||||
porn = {
|
porn = {
|
||||||
|
enable = lib.mkDefault false;
|
||||||
id = "vatmy-c2qf4";
|
id = "vatmy-c2qf4";
|
||||||
watch = false;
|
watch = false;
|
||||||
devices = [ "workhorse" "porani" ];
|
devices = [ "workhorse" "porani" ];
|
||||||
};
|
};
|
||||||
music-library = {
|
music-library = {
|
||||||
|
enable = lib.mkDefault false;
|
||||||
id = "gytmq-r2zrx";
|
id = "gytmq-r2zrx";
|
||||||
watch = false;
|
watch = false;
|
||||||
devices = [ "porani" "workout" "workhorse" "pepe" "sterni" ];
|
devices = [ "porani" "workout" "workhorse" "pepe" "sterni" ];
|
||||||
};
|
};
|
||||||
music-library-free = {
|
music-library-free = {
|
||||||
|
enable = lib.mkDefault false;
|
||||||
id = "mu9mn-zgvsw";
|
id = "mu9mn-zgvsw";
|
||||||
watch = false;
|
watch = false;
|
||||||
devices = [ "workout" "workhorse" "mors" ];
|
devices = [ "workout" "workhorse" "mors" ];
|
||||||
};
|
};
|
||||||
music-projects = {
|
music-projects = {
|
||||||
|
enable = lib.mkDefault false;
|
||||||
id = "acfhu-r4t4f";
|
id = "acfhu-r4t4f";
|
||||||
watch = false;
|
watch = false;
|
||||||
devices = [ "workout" "workhorse" "pepe" "sterni" ];
|
devices = [ "workout" "workhorse" "pepe" "sterni" ];
|
||||||
};
|
};
|
||||||
podcasts = {
|
podcasts = {
|
||||||
|
enable = lib.mkDefault false;
|
||||||
id = "yvzmx-hcomd";
|
id = "yvzmx-hcomd";
|
||||||
watch = false;
|
watch = false;
|
||||||
devices = [ "workhorse" "porani" ];
|
devices = [ "workhorse" "porani" ];
|
||||||
};
|
};
|
||||||
samples = {
|
samples = {
|
||||||
|
enable = lib.mkDefault false;
|
||||||
id = "pcgkj-tjucd";
|
id = "pcgkj-tjucd";
|
||||||
watch = false;
|
watch = false;
|
||||||
devices = [ "workout" "workhorse" "sterni" ];
|
devices = [ "workout" "workhorse" "sterni" ];
|
||||||
};
|
};
|
||||||
series = {
|
series = {
|
||||||
|
enable = lib.mkDefault false;
|
||||||
id = "all-series";
|
id = "all-series";
|
||||||
watch = false;
|
watch = false;
|
||||||
devices = [ "workhorse" "porani" ];
|
devices = [ "workhorse" "porani" ];
|
||||||
};
|
};
|
||||||
smartphone-music = {
|
smartphone-music = {
|
||||||
|
enable = lib.mkDefault false;
|
||||||
id = "0vjze-xvs8n";
|
id = "0vjze-xvs8n";
|
||||||
watch = false;
|
watch = false;
|
||||||
devices = [ "workout" "smartphone" ];
|
devices = [ "workout" "smartphone" ];
|
||||||
};
|
};
|
||||||
smartphone-fotos = {
|
smartphone-fotos = {
|
||||||
|
enable = lib.mkDefault false;
|
||||||
id = "e5823_jtbr-photos";
|
id = "e5823_jtbr-photos";
|
||||||
watch = false;
|
watch = false;
|
||||||
devices = [ "sterni" "workout" "pepe" "smartphone" ];
|
devices = [ "sterni" "workout" "pepe" "smartphone" ];
|
||||||
};
|
};
|
||||||
video-material = {
|
video-material = {
|
||||||
|
enable = lib.mkDefault false;
|
||||||
id = "wgkun-fec5h";
|
id = "wgkun-fec5h";
|
||||||
watch = false;
|
watch = false;
|
||||||
devices = [ "workout" "workhorse" ];
|
devices = [ "workout" "workhorse" ];
|
||||||
|
@ -125,19 +140,23 @@ with lib;
|
||||||
|
|
||||||
# one on one
|
# one on one
|
||||||
porani-workout = {
|
porani-workout = {
|
||||||
|
enable = lib.mkDefault false;
|
||||||
devices = [ "porani" "workout" ];
|
devices = [ "porani" "workout" ];
|
||||||
watch = false;
|
watch = false;
|
||||||
};
|
};
|
||||||
porani-pepe = {
|
porani-pepe = {
|
||||||
|
enable = lib.mkDefault false;
|
||||||
devices = [ "porani" "pepe" ];
|
devices = [ "porani" "pepe" ];
|
||||||
watch = false;
|
watch = false;
|
||||||
};
|
};
|
||||||
windows-sync = {
|
windows-sync = {
|
||||||
|
enable = lib.mkDefault false;
|
||||||
id = "hcity-p5ikc";
|
id = "hcity-p5ikc";
|
||||||
watch = false;
|
watch = false;
|
||||||
devices = [ "bumba" "workout" ];
|
devices = [ "bumba" "workout" ];
|
||||||
};
|
};
|
||||||
workout-pepe = {
|
workout-pepe = {
|
||||||
|
enable = lib.mkDefault false;
|
||||||
devices = [ "pepe" "workout" ];
|
devices = [ "pepe" "workout" ];
|
||||||
watch = false;
|
watch = false;
|
||||||
};
|
};
|
||||||
|
@ -150,7 +169,7 @@ with lib;
|
||||||
# convenience script to know which folder needs to be configured
|
# convenience script to know which folder needs to be configured
|
||||||
environment.systemPackages =
|
environment.systemPackages =
|
||||||
let
|
let
|
||||||
folders = config.test.services.syncthing.declarative.folders;
|
folders = config.services.syncthing.declarative.folders;
|
||||||
computers = unique (flatten (mapAttrsToList (_: value: value.devices) folders));
|
computers = unique (flatten (mapAttrsToList (_: value: value.devices) folders));
|
||||||
isComputerInDeviceList = computer: deviceList: (unique deviceList) == (unique (deviceList ++ [ computer ]));
|
isComputerInDeviceList = computer: deviceList: (unique deviceList) == (unique (deviceList ++ [ computer ]));
|
||||||
getFolderNames = computer: naturalSort (builtins.attrNames (filterAttrs (_: folder: isComputerInDeviceList computer folder.devices) folders));
|
getFolderNames = computer: naturalSort (builtins.attrNames (filterAttrs (_: folder: isComputerInDeviceList computer folder.devices) folders));
|
||||||
|
|
Loading…
Reference in a new issue