1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-12-26 03:39:47 +01:00
home-manager/modules/services/syncthing.nix

153 lines
4.4 KiB
Nix
Raw Normal View History

2017-07-17 10:10:15 +02:00
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.syncthing;
in {
meta.maintainers = [ maintainers.rycee ];
2017-07-17 10:10:15 +02:00
options = {
services.syncthing = {
enable = mkEnableOption "Syncthing continuous file synchronization";
extraOptions = mkOption {
type = types.listOf types.str;
default = [ ];
example = [ "--gui-apikey=apiKey" ];
description = ''
Extra command-line arguments to pass to <command>syncthing</command>.
'';
};
tray = mkOption {
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 = literalExpression "syncthingtray";
example = literalExpression "qsyncthingtray";
description = "Syncthing tray command to use.";
};
package = mkOption {
type = types.package;
default = pkgs.syncthingtray-minimal;
defaultText = literalExpression "pkgs.syncthingtray-minimal";
example = literalExpression "pkgs.qsyncthingtray";
description = "Syncthing tray package to use.";
};
};
});
default = { enable = false; };
description = "Syncthing tray service configuration.";
};
2017-07-17 10:10:15 +02:00
};
};
config = mkMerge [
(mkIf cfg.enable {
2022-09-30 22:27:35 +02:00
assertions = [
(lib.hm.assertions.assertPlatform "services.syncthing" pkgs
lib.platforms.linux)
];
home.packages = [ (getOutput "man" pkgs.syncthing) ];
systemd.user.services = {
syncthing = {
Unit = {
2020-02-02 00:39:17 +01:00
Description =
"Syncthing - Open Source Continuous File Synchronization";
Documentation = "man:syncthing(1)";
After = [ "network.target" ];
};
2017-07-17 10:10:15 +02:00
Service = {
2020-02-02 00:39:17 +01:00
ExecStart =
"${pkgs.syncthing}/bin/syncthing -no-browser -no-restart -logflags=0"
+ optionalString (cfg.extraOptions != [ ])
(" " + escapeShellArgs cfg.extraOptions);
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";
};
2020-02-02 00:39:17 +01:00
Install = { WantedBy = [ "default.target" ]; };
};
};
})
(mkIf (isAttrs cfg.tray && cfg.tray.enable) {
2022-04-24 16:25:54 +02:00
assertions = [
(hm.assertions.assertPlatform "services.syncthing.tray" pkgs
platforms.linux)
];
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" ];
};
Service = {
ExecStart = "${cfg.tray.package}/bin/${cfg.tray.command}";
};
Install = { WantedBy = [ "graphical-session.target" ]; };
};
};
})
# deprecated
(mkIf (isBool cfg.tray && cfg.tray) {
2022-04-24 16:25:54 +02:00
assertions = [
(hm.assertions.assertPlatform "services.syncthing.tray" pkgs
platforms.linux)
];
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
Service = {
ExecStart = "${pkgs.syncthingtray-minimal}/bin/syncthingtray";
};
Install = { WantedBy = [ "graphical-session.target" ]; };
};
};
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."
];
})
];
2017-07-17 10:10:15 +02:00
}