at 15.09-beta 1.7 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 7 cfg = config.services.syncthing; 8 9in 10 11{ 12 13 ###### interface 14 15 options = { 16 17 services.syncthing = { 18 19 enable = mkOption { 20 default = false; 21 description = '' 22 Whether to enable the Syncthing, self-hosted open-source alternative 23 to Dropbox and BittorrentSync. Initial interface will be 24 available on http://127.0.0.1:8080/. 25 ''; 26 }; 27 28 user = mkOption { 29 default = "syncthing"; 30 description = '' 31 Syncthing will be run under this user (user must exist, 32 this can be your user name). 33 ''; 34 }; 35 36 dataDir = mkOption { 37 default = "/var/lib/syncthing"; 38 description = '' 39 Path where the `.syncthing` (settings and keys) and `Sync` 40 (your synced files) directories will exist. This can be your home 41 directory. 42 ''; 43 }; 44 45 }; 46 47 }; 48 49 50 ###### implementation 51 52 config = mkIf cfg.enable { 53 54 systemd.services.syncthing = 55 { 56 description = "Syncthing service"; 57 after = [ "network.target" ]; 58 wantedBy = [ "multi-user.target" ]; 59 environment.STNORESTART = "placeholder"; # do not self-restart 60 environment.HOME = "${cfg.dataDir}"; 61 serviceConfig = { 62 User = "${cfg.user}"; 63 PermissionsStartOnly = true; 64 Restart = "always"; 65 ExecStart = "${pkgs.syncthing}/bin/syncthing -home=${cfg.dataDir}/.syncthing"; 66 }; 67 preStart = '' 68 mkdir -p ${cfg.dataDir} 69 chown ${cfg.user} ${cfg.dataDir} 70 ''; 71 72 }; 73 74 environment.systemPackages = [ pkgs.syncthing ]; 75 76 }; 77 78}