2017-07-17 08:10:15 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
{
|
2017-09-26 21:40:31 +00:00
|
|
|
meta.maintainers = [ maintainers.rycee ];
|
|
|
|
|
2017-07-17 08:10:15 +00:00
|
|
|
options = {
|
|
|
|
services.syncthing = {
|
2017-07-18 11:49:02 +00:00
|
|
|
enable = mkEnableOption "Syncthing continuous file synchronization";
|
2018-01-21 20:24:48 +00:00
|
|
|
|
|
|
|
tray = mkOption {
|
2021-05-18 14:43:17 +00: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";
|
|
|
|
defaultText = literalExample "syncthingtray";
|
|
|
|
example = literalExample "qsyncthingtray";
|
|
|
|
description = "Syncthing tray command to use.";
|
|
|
|
};
|
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.syncthingtray-minimal;
|
|
|
|
defaultText = literalExample "pkgs.syncthingtray-minimal";
|
|
|
|
example = literalExample "pkgs.qsyncthingtray";
|
|
|
|
description = "Syncthing tray package to use.";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|
|
|
|
default = { enable = false; };
|
|
|
|
description = "Syncthing tray service configuration.";
|
2018-01-21 20:24:48 +00:00
|
|
|
};
|
2017-07-17 08:10:15 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2018-01-30 19:15:31 +00:00
|
|
|
config = mkMerge [
|
|
|
|
(mkIf config.services.syncthing.enable {
|
2020-03-22 20:13:05 +00:00
|
|
|
home.packages = [ (getOutput "man" pkgs.syncthing) ];
|
|
|
|
|
2018-01-21 20:24:48 +00:00
|
|
|
systemd.user.services = {
|
|
|
|
syncthing = {
|
|
|
|
Unit = {
|
2020-02-01 23:39:17 +00:00
|
|
|
Description =
|
|
|
|
"Syncthing - Open Source Continuous File Synchronization";
|
2018-01-21 20:24:48 +00:00
|
|
|
Documentation = "man:syncthing(1)";
|
|
|
|
After = [ "network.target" ];
|
|
|
|
};
|
2017-07-17 08:10:15 +00:00
|
|
|
|
2018-01-21 20:24:48 +00:00
|
|
|
Service = {
|
2020-02-01 23:39:17 +00:00
|
|
|
ExecStart =
|
|
|
|
"${pkgs.syncthing}/bin/syncthing -no-browser -no-restart -logflags=0";
|
2018-01-21 20:24:48 +00:00
|
|
|
Restart = "on-failure";
|
|
|
|
SuccessExitStatus = [ 3 4 ];
|
|
|
|
RestartForceExitStatus = [ 3 4 ];
|
2021-08-14 11:25:54 +00:00
|
|
|
|
|
|
|
# Sandboxing.
|
|
|
|
LockPersonality = true;
|
|
|
|
MemoryDenyWriteExecute = true;
|
2021-07-19 20:41:51 +00:00
|
|
|
NoNewPrivileges = true;
|
|
|
|
PrivateUsers = true;
|
2021-08-14 11:25:54 +00:00
|
|
|
RestrictNamespaces = true;
|
|
|
|
SystemCallArchitectures = "native";
|
|
|
|
SystemCallFilter = "@system-service";
|
2018-01-21 20:24:48 +00:00
|
|
|
};
|
|
|
|
|
2020-02-01 23:39:17 +00:00
|
|
|
Install = { WantedBy = [ "default.target" ]; };
|
2018-01-21 20:24:48 +00:00
|
|
|
};
|
2017-07-18 11:49:02 +00:00
|
|
|
};
|
2018-01-30 19:15:31 +00:00
|
|
|
})
|
|
|
|
|
2021-05-18 14:43:17 +00:00
|
|
|
(mkIf (isAttrs config.services.syncthing.tray
|
|
|
|
&& config.services.syncthing.tray.enable) {
|
|
|
|
systemd.user.services = {
|
|
|
|
${config.services.syncthing.tray.package.pname} = {
|
|
|
|
Unit = {
|
|
|
|
Description = config.services.syncthing.tray.package.pname;
|
2021-05-22 02:15:12 +00:00
|
|
|
Requires = [ "tray.target" ];
|
|
|
|
After = [ "graphical-session-pre.target" "tray.target" ];
|
2021-05-18 14:43:17 +00:00
|
|
|
PartOf = [ "graphical-session.target" ];
|
|
|
|
};
|
2018-01-21 20:24:48 +00:00
|
|
|
|
2021-05-18 14:43:17 +00:00
|
|
|
Service = {
|
|
|
|
ExecStart =
|
|
|
|
"${config.services.syncthing.tray.package}/bin/${config.services.syncthing.tray.command}";
|
|
|
|
};
|
|
|
|
|
|
|
|
Install = { WantedBy = [ "graphical-session.target" ]; };
|
2018-01-21 20:24:48 +00:00
|
|
|
};
|
2021-05-18 14:43:17 +00:00
|
|
|
};
|
|
|
|
})
|
|
|
|
|
|
|
|
# deprecated
|
|
|
|
(mkIf (isBool config.services.syncthing.tray
|
|
|
|
&& config.services.syncthing.tray) {
|
|
|
|
systemd.user.services = {
|
|
|
|
"syncthingtray" = {
|
|
|
|
Unit = {
|
|
|
|
Description = "syncthingtray";
|
2021-05-22 02:15:12 +00:00
|
|
|
Requires = [ "tray.target" ];
|
|
|
|
After = [ "graphical-session-pre.target" "tray.target" ];
|
2021-05-18 14:43:17 +00:00
|
|
|
PartOf = [ "graphical-session.target" ];
|
|
|
|
};
|
|
|
|
|
|
|
|
Service = {
|
|
|
|
ExecStart = "${pkgs.syncthingtray-minimal}/bin/syncthingtray";
|
|
|
|
};
|
2017-07-17 08:10:15 +00:00
|
|
|
|
2021-05-18 14:43:17 +00:00
|
|
|
Install = { WantedBy = [ "graphical-session.target" ]; };
|
|
|
|
};
|
2018-01-21 20:24:48 +00:00
|
|
|
};
|
2021-05-18 14:43:17 +00: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 19:15:31 +00:00
|
|
|
];
|
2017-07-17 08:10:15 +00:00
|
|
|
}
|