2017-07-17 10:10:15 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
2022-01-27 00:30:39 +01:00
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.services.syncthing;
|
|
|
|
|
|
|
|
in {
|
2017-09-26 23:40:31 +02:00
|
|
|
meta.maintainers = [ maintainers.rycee ];
|
|
|
|
|
2017-07-17 10:10:15 +02:00
|
|
|
options = {
|
|
|
|
services.syncthing = {
|
2017-07-18 13:49:02 +02:00
|
|
|
enable = mkEnableOption "Syncthing continuous file synchronization";
|
2018-01-21 21:24:48 +01:00
|
|
|
|
2022-01-27 00:29:00 +01:00
|
|
|
extraOptions = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [ ];
|
|
|
|
example = [ "--gui-apikey=apiKey" ];
|
|
|
|
description = ''
|
|
|
|
Extra command-line arguments to pass to <command>syncthing</command>.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-01-21 21:24:48 +01:00
|
|
|
tray = mkOption {
|
2021-05-18 16:43:17 +02:00
|
|
|
type = with types;
|
|
|
|
either bool (submodule {
|
|
|
|
options = {
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = "Whether to enable a syncthing tray service.";
|
|
|
|
};
|
|
|
|
|
|
|
|
command = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "syncthingtray";
|
2021-10-09 11:14:08 +02:00
|
|
|
defaultText = literalExpression "syncthingtray";
|
|
|
|
example = literalExpression "qsyncthingtray";
|
2021-05-18 16:43:17 +02:00
|
|
|
description = "Syncthing tray command to use.";
|
|
|
|
};
|
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.syncthingtray-minimal;
|
2021-10-09 11:14:08 +02:00
|
|
|
defaultText = literalExpression "pkgs.syncthingtray-minimal";
|
|
|
|
example = literalExpression "pkgs.qsyncthingtray";
|
2021-05-18 16:43:17 +02:00
|
|
|
description = "Syncthing tray package to use.";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|
|
|
|
default = { enable = false; };
|
|
|
|
description = "Syncthing tray service configuration.";
|
2018-01-21 21:24:48 +01:00
|
|
|
};
|
2017-07-17 10:10:15 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2018-01-30 20:15:31 +01:00
|
|
|
config = mkMerge [
|
2022-01-27 00:30:39 +01:00
|
|
|
(mkIf cfg.enable {
|
2022-09-30 22:27:35 +02:00
|
|
|
assertions = [
|
|
|
|
(lib.hm.assertions.assertPlatform "services.syncthing" pkgs
|
|
|
|
lib.platforms.linux)
|
|
|
|
];
|
|
|
|
|
2020-03-22 21:13:05 +01:00
|
|
|
home.packages = [ (getOutput "man" pkgs.syncthing) ];
|
|
|
|
|
2018-01-21 21:24:48 +01:00
|
|
|
systemd.user.services = {
|
|
|
|
syncthing = {
|
|
|
|
Unit = {
|
2020-02-02 00:39:17 +01:00
|
|
|
Description =
|
|
|
|
"Syncthing - Open Source Continuous File Synchronization";
|
2018-01-21 21:24:48 +01:00
|
|
|
Documentation = "man:syncthing(1)";
|
|
|
|
After = [ "network.target" ];
|
|
|
|
};
|
2017-07-17 10:10:15 +02:00
|
|
|
|
2018-01-21 21:24:48 +01:00
|
|
|
Service = {
|
2020-02-02 00:39:17 +01:00
|
|
|
ExecStart =
|
2022-01-27 00:29:00 +01:00
|
|
|
"${pkgs.syncthing}/bin/syncthing -no-browser -no-restart -logflags=0"
|
2022-01-27 00:30:39 +01:00
|
|
|
+ optionalString (cfg.extraOptions != [ ])
|
|
|
|
(" " + escapeShellArgs cfg.extraOptions);
|
2018-01-21 21:24:48 +01:00
|
|
|
Restart = "on-failure";
|
|
|
|
SuccessExitStatus = [ 3 4 ];
|
|
|
|
RestartForceExitStatus = [ 3 4 ];
|
2021-08-14 13:25:54 +02:00
|
|
|
|
|
|
|
# Sandboxing.
|
|
|
|
LockPersonality = true;
|
|
|
|
MemoryDenyWriteExecute = true;
|
2021-07-19 22:41:51 +02:00
|
|
|
NoNewPrivileges = true;
|
|
|
|
PrivateUsers = true;
|
2021-08-14 13:25:54 +02:00
|
|
|
RestrictNamespaces = true;
|
|
|
|
SystemCallArchitectures = "native";
|
|
|
|
SystemCallFilter = "@system-service";
|
2018-01-21 21:24:48 +01:00
|
|
|
};
|
|
|
|
|
2020-02-02 00:39:17 +01:00
|
|
|
Install = { WantedBy = [ "default.target" ]; };
|
2018-01-21 21:24:48 +01:00
|
|
|
};
|
2017-07-18 13:49:02 +02:00
|
|
|
};
|
2018-01-30 20:15:31 +01:00
|
|
|
})
|
|
|
|
|
2022-01-27 00:30:39 +01:00
|
|
|
(mkIf (isAttrs cfg.tray && cfg.tray.enable) {
|
|
|
|
systemd.user.services = {
|
|
|
|
${cfg.tray.package.pname} = {
|
|
|
|
Unit = {
|
|
|
|
Description = cfg.tray.package.pname;
|
|
|
|
Requires = [ "tray.target" ];
|
|
|
|
After = [ "graphical-session-pre.target" "tray.target" ];
|
|
|
|
PartOf = [ "graphical-session.target" ];
|
|
|
|
};
|
2021-05-18 16:43:17 +02:00
|
|
|
|
2022-01-27 00:30:39 +01:00
|
|
|
Service = {
|
|
|
|
ExecStart = "${cfg.tray.package}/bin/${cfg.tray.command}";
|
2018-01-21 21:24:48 +01:00
|
|
|
};
|
2022-01-27 00:30:39 +01:00
|
|
|
|
|
|
|
Install = { WantedBy = [ "graphical-session.target" ]; };
|
2021-05-18 16:43:17 +02:00
|
|
|
};
|
2022-01-27 00:30:39 +01:00
|
|
|
};
|
|
|
|
})
|
2021-05-18 16:43:17 +02:00
|
|
|
|
|
|
|
# deprecated
|
2022-01-27 00:30:39 +01:00
|
|
|
(mkIf (isBool cfg.tray && cfg.tray) {
|
|
|
|
systemd.user.services = {
|
|
|
|
"syncthingtray" = {
|
|
|
|
Unit = {
|
|
|
|
Description = "syncthingtray";
|
|
|
|
Requires = [ "tray.target" ];
|
|
|
|
After = [ "graphical-session-pre.target" "tray.target" ];
|
|
|
|
PartOf = [ "graphical-session.target" ];
|
|
|
|
};
|
2017-07-17 10:10:15 +02:00
|
|
|
|
2022-01-27 00:30:39 +01:00
|
|
|
Service = {
|
|
|
|
ExecStart = "${pkgs.syncthingtray-minimal}/bin/syncthingtray";
|
2021-05-18 16:43:17 +02:00
|
|
|
};
|
2022-01-27 00:30:39 +01:00
|
|
|
|
|
|
|
Install = { WantedBy = [ "graphical-session.target" ]; };
|
2018-01-21 21:24:48 +01:00
|
|
|
};
|
2022-01-27 00:30:39 +01:00
|
|
|
};
|
|
|
|
warnings = [
|
|
|
|
"Specifying 'services.syncthing.tray' as a boolean is deprecated, set 'services.syncthing.tray.enable' instead. See https://github.com/nix-community/home-manager/pull/1257."
|
|
|
|
];
|
|
|
|
})
|
2018-01-30 20:15:31 +01:00
|
|
|
];
|
2017-07-17 10:10:15 +02:00
|
|
|
}
|