fork/home-manager
git clone https://git.julia.blue/fork/home-manager
75790441
master
1{ config , lib , pkgs , ...} : 2 3with lib ; 4 5let 6 7cfg = config . services . syncthing ; 8 9defaultSyncthingArgs = [ 10" ${ pkgs . syncthing } /bin/syncthing" 11"-no-browser" 12"-no-restart" 13"-logflags=0" 14]; 15 16syncthingArgs = defaultSyncthingArgs ++ cfg . extraOptions ; 17 18in { 19meta . maintainers = [ maintainers . rycee ]; 20 21options = { 22services . syncthing = { 23enable = mkEnableOption "Syncthing continuous file synchronization" ; 24 25extraOptions = mkOption { 26type = types . listOf types . str ; 27default = [ ]; 28example = [ "--gui-apikey=apiKey" ]; 29description = '' 30Extra command-line arguments to pass to {command}`syncthing`. 31'' ; 32}; 33 34tray = mkOption { 35type = with types ; 36either bool ( submodule { 37options = { 38enable = mkOption { 39type = types . bool ; 40default = false ; 41description = "Whether to enable a syncthing tray service." ; 42}; 43 44command = mkOption { 45type = types . str ; 46default = "syncthingtray" ; 47defaultText = literalExpression "syncthingtray" ; 48example = literalExpression "qsyncthingtray" ; 49description = "Syncthing tray command to use." ; 50}; 51 52package = mkOption { 53type = types . package ; 54default = pkgs . syncthingtray-minimal ; 55defaultText = literalExpression "pkgs.syncthingtray-minimal" ; 56example = literalExpression "pkgs.qsyncthingtray" ; 57description = "Syncthing tray package to use." ; 58}; 59}; 60}); 61default = { enable = false ; }; 62description = "Syncthing tray service configuration." ; 63}; 64}; 65}; 66 67config = mkMerge [ 68( mkIf cfg . enable { 69home . packages = [ ( getOutput "man" pkgs . syncthing ) ]; 70 71systemd . user . services = { 72syncthing = { 73Unit = { 74Description = 75"Syncthing - Open Source Continuous File Synchronization" ; 76Documentation = "man:syncthing(1)" ; 77After = [ "network.target" ]; 78}; 79 80Service = { 81ExecStart = escapeShellArgs syncthingArgs ; 82Restart = "on-failure" ; 83SuccessExitStatus = [ 3 4 ]; 84RestartForceExitStatus = [ 3 4 ]; 85 86# Sandboxing. 87LockPersonality = true ; 88MemoryDenyWriteExecute = true ; 89NoNewPrivileges = true ; 90PrivateUsers = true ; 91RestrictNamespaces = true ; 92SystemCallArchitectures = "native" ; 93SystemCallFilter = "@system-service" ; 94}; 95 96Install = { WantedBy = [ "default.target" ]; }; 97}; 98}; 99 100launchd . agents . syncthing = { 101enable = true ; 102config = { 103ProgramArguments = syncthingArgs ; 104KeepAlive = { 105Crashed = true ; 106SuccessfulExit = false ; 107}; 108ProcessType = "Background" ; 109}; 110}; 111}) 112 113( mkIf ( isAttrs cfg . tray && cfg . tray . enable ) { 114assertions = [ 115( hm . assertions . assertPlatform "services.syncthing.tray" pkgs 116platforms . linux ) 117]; 118 119systemd . user . services = { 120${ cfg . tray . package . pname } = { 121Unit = { 122Description = cfg . tray . package . pname ; 123Requires = [ "tray.target" ]; 124After = [ "graphical-session-pre.target" "tray.target" ]; 125PartOf = [ "graphical-session.target" ]; 126}; 127 128Service = { 129ExecStart = " ${ cfg . tray . package } /bin/ ${ cfg . tray . command } " ; 130}; 131 132Install = { WantedBy = [ "graphical-session.target" ]; }; 133}; 134}; 135}) 136 137# deprecated 138( mkIf ( isBool cfg . tray && cfg . tray ) { 139assertions = [ 140( hm . assertions . assertPlatform "services.syncthing.tray" pkgs 141platforms . linux ) 142]; 143 144systemd . user . services = { 145"syncthingtray" = { 146Unit = { 147Description = "syncthingtray" ; 148Requires = [ "tray.target" ]; 149After = [ "graphical-session-pre.target" "tray.target" ]; 150PartOf = [ "graphical-session.target" ]; 151}; 152 153Service = { 154ExecStart = " ${ pkgs . syncthingtray-minimal } /bin/syncthingtray" ; 155}; 156 157Install = { WantedBy = [ "graphical-session.target" ]; }; 158}; 159}; 160warnings = [ 161"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." 162]; 163}) 164]; 165}