2017-07-17 08:10:15 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
2022-01-26 23:30:39 +00:00
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.services.syncthing;
|
|
|
|
|
2023-02-08 16:59:38 +00:00
|
|
|
defaultSyncthingArgs = [
|
|
|
|
"${pkgs.syncthing}/bin/syncthing"
|
|
|
|
"-no-browser"
|
|
|
|
"-no-restart"
|
|
|
|
"-logflags=0"
|
|
|
|
];
|
|
|
|
|
|
|
|
syncthingArgs = defaultSyncthingArgs ++ cfg.extraOptions;
|
|
|
|
|
2022-01-26 23:30:39 +00:00
|
|
|
in {
|
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
|
|
|
|
2022-01-26 23:29:00 +00: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 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";
|
2021-10-09 09:14:08 +00:00
|
|
|
defaultText = literalExpression "syncthingtray";
|
|
|
|
example = literalExpression "qsyncthingtray";
|
2021-05-18 14:43:17 +00:00
|
|
|
description = "Syncthing tray command to use.";
|
|
|
|
};
|
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.syncthingtray-minimal;
|
2021-10-09 09:14:08 +00:00
|
|
|
defaultText = literalExpression "pkgs.syncthingtray-minimal";
|
|
|
|
example = literalExpression "pkgs.qsyncthingtray";
|
2021-05-18 14:43:17 +00:00
|
|
|
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 [
|
2022-01-26 23:30:39 +00:00
|
|
|
(mkIf cfg.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 = {
|
2023-02-08 16:59:38 +00:00
|
|
|
ExecStart = escapeShellArgs syncthingArgs;
|
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
|
|
|
};
|
2023-02-08 16:59:38 +00:00
|
|
|
|
|
|
|
launchd.agents.syncthing = {
|
|
|
|
enable = true;
|
|
|
|
config = {
|
|
|
|
ProgramArguments = syncthingArgs;
|
|
|
|
KeepAlive = {
|
|
|
|
Crashed = true;
|
|
|
|
SuccessfulExit = false;
|
|
|
|
};
|
|
|
|
ProcessType = "Background";
|
|
|
|
};
|
|
|
|
};
|
2018-01-30 19:15:31 +00:00
|
|
|
})
|
|
|
|
|
2022-01-26 23:30:39 +00:00
|
|
|
(mkIf (isAttrs cfg.tray && cfg.tray.enable) {
|
2022-04-24 14:25:54 +00:00
|
|
|
assertions = [
|
|
|
|
(hm.assertions.assertPlatform "services.syncthing.tray" pkgs
|
|
|
|
platforms.linux)
|
|
|
|
];
|
|
|
|
|
2022-01-26 23:30:39 +00:00
|
|
|
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 14:43:17 +00:00
|
|
|
|
2022-01-26 23:30:39 +00:00
|
|
|
Service = {
|
|
|
|
ExecStart = "${cfg.tray.package}/bin/${cfg.tray.command}";
|
2018-01-21 20:24:48 +00:00
|
|
|
};
|
2022-01-26 23:30:39 +00:00
|
|
|
|
|
|
|
Install = { WantedBy = [ "graphical-session.target" ]; };
|
2021-05-18 14:43:17 +00:00
|
|
|
};
|
2022-01-26 23:30:39 +00:00
|
|
|
};
|
|
|
|
})
|
2021-05-18 14:43:17 +00:00
|
|
|
|
|
|
|
# deprecated
|
2022-01-26 23:30:39 +00:00
|
|
|
(mkIf (isBool cfg.tray && cfg.tray) {
|
2022-04-24 14:25:54 +00:00
|
|
|
assertions = [
|
|
|
|
(hm.assertions.assertPlatform "services.syncthing.tray" pkgs
|
|
|
|
platforms.linux)
|
|
|
|
];
|
|
|
|
|
2022-01-26 23:30:39 +00:00
|
|
|
systemd.user.services = {
|
|
|
|
"syncthingtray" = {
|
|
|
|
Unit = {
|
|
|
|
Description = "syncthingtray";
|
|
|
|
Requires = [ "tray.target" ];
|
|
|
|
After = [ "graphical-session-pre.target" "tray.target" ];
|
|
|
|
PartOf = [ "graphical-session.target" ];
|
|
|
|
};
|
2017-07-17 08:10:15 +00:00
|
|
|
|
2022-01-26 23:30:39 +00:00
|
|
|
Service = {
|
|
|
|
ExecStart = "${pkgs.syncthingtray-minimal}/bin/syncthingtray";
|
2021-05-18 14:43:17 +00:00
|
|
|
};
|
2022-01-26 23:30:39 +00:00
|
|
|
|
|
|
|
Install = { WantedBy = [ "graphical-session.target" ]; };
|
2018-01-21 20:24:48 +00:00
|
|
|
};
|
2022-01-26 23:30:39 +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
|
|
|
}
|