fork/home-manager
git clone https://git.julia.blue/fork/home-manager
4fa1ba72
master
1{ config , lib , pkgs , ...} : 2 3with lib ; 4 5let 6 7cfg = config . services . dropbox ; 8baseDir = ".dropbox-hm" ; 9dropboxCmd = " ${ pkgs . dropbox-cli } /bin/dropbox" ; 10homeBaseDir = " ${ config . home . homeDirectory } / ${ baseDir } " ; 11 12in { 13meta . maintainers = [ maintainers . eyjhb ]; 14 15options = { 16services . dropbox = { 17enable = mkEnableOption "Dropbox daemon" ; 18 19path = mkOption { 20type = types . path ; 21default = " ${ config . home . homeDirectory } /Dropbox" ; 22defaultText = 23literalExpression ''"''${config.home.homeDirectory}/Dropbox"'' ; 24apply = toString ; # Prevent copies to Nix store. 25description = "Where to put the Dropbox directory." ; 26}; 27}; 28}; 29 30config = mkIf cfg . enable { 31assertions = [ 32( lib . hm . assertions . assertPlatform "services.dropbox" pkgs 33lib . platforms . linux ) 34]; 35 36home . packages = [ pkgs . dropbox-cli ]; 37 38systemd . user . services . dropbox = { 39Unit = { Description = "dropbox" ; }; 40 41Install = { WantedBy = [ "default.target" ]; }; 42 43Service = { 44Environment = [ "HOME= ${ homeBaseDir } " "DISPLAY=" ]; 45 46Type = "forking" ; 47PIDFile = " ${ homeBaseDir } /.dropbox/dropbox.pid" ; 48 49Restart = "on-failure" ; 50PrivateTmp = true ; 51ProtectSystem = "full" ; 52Nice = 10 ; 53 54ExecReload = " ${ pkgs . coreutils } /bin/kill -HUP $MAINPID" ; 55ExecStop = " ${ dropboxCmd } stop" ; 56ExecStart = toString ( pkgs . writeShellScript "dropbox-start" '' 57# ensure we have the dirs we need 58$ DRY_RUN_CMD ${ pkgs . coreutils } /bin/mkdir $ VERBOSE_ARG -p \ 59${ homeBaseDir } /{.dropbox,.dropbox-dist,Dropbox} 60 61# symlink them as needed 62if [[ ! -d ${ config . home . homeDirectory } /.dropbox ]]; then 63$ DRY_RUN_CMD ${ pkgs . coreutils } /bin/ln $ VERBOSE_ARG -s \ 64${ homeBaseDir } /.dropbox ${ config . home . homeDirectory } /.dropbox 65fi 66 67if [[ ! -d ${ escapeShellArg cfg . path } ]] ; then 68$ DRY_RUN_CMD ${ pkgs . coreutils } /bin/ln $ VERBOSE_ARG -s \ 69${ homeBaseDir } /Dropbox ${ escapeShellArg cfg . path } 70fi 71 72# get the dropbox bins if needed 73if [[ ! -f $ HOME /.dropbox-dist/VERSION ]]; then 74${ pkgs . coreutils } /bin/yes | ${ dropboxCmd } update 75fi 76 77${ dropboxCmd } start 78'' ); 79}; 80}; 81}; 82}