at 16.09-beta 3.6 kB view raw
1{ config, pkgs, lib, ... }: 2 3with lib; 4 5let 6 cfg = config.services.psd; 7 8 configFile = '' 9 ${optionalString (cfg.users != [ ]) '' 10 USERS="${concatStringsSep " " cfg.users}" 11 ''} 12 13 ${optionalString (cfg.browsers != [ ]) '' 14 BROWSERS="${concatStringsSep " " cfg.browsers}" 15 ''} 16 17 ${optionalString (cfg.volatile != "") "VOLATILE=${cfg.volatile}"} 18 ${optionalString (cfg.daemonFile != "") "DAEMON_FILE=${cfg.daemonFile}"} 19 ''; 20 21in { 22 23 options.services.psd = with types; { 24 enable = mkOption { 25 type = bool; 26 default = false; 27 description = '' 28 Whether to enable the Profile Sync daemon. 29 ''; 30 }; 31 32 users = mkOption { 33 type = listOf str; 34 default = [ ]; 35 example = [ "demo" ]; 36 description = '' 37 A list of users whose browser profiles should be sync'd to tmpfs. 38 ''; 39 }; 40 41 browsers = mkOption { 42 type = listOf str; 43 default = [ ]; 44 example = [ "chromium" "firefox" ]; 45 description = '' 46 A list of browsers to sync. Available choices are: 47 48 chromium chromium-dev conkeror.mozdev.org epiphany firefox 49 firefox-trunk google-chrome google-chrome-beta google-chrome-unstable 50 heftig-aurora icecat luakit midori opera opera-developer opera-beta 51 qupzilla palemoon rekonq seamonkey 52 53 An empty list will enable all browsers. 54 ''; 55 }; 56 57 resyncTimer = mkOption { 58 type = str; 59 default = "1h"; 60 example = "1h 30min"; 61 description = '' 62 The amount of time to wait before syncing browser profiles back to the 63 disk. 64 65 Takes a systemd.unit time span. The time unit defaults to seconds if 66 omitted. 67 ''; 68 }; 69 70 volatile = mkOption { 71 type = str; 72 default = "/run/psd-profiles"; 73 description = '' 74 The directory where browser profiles should reside(this should be 75 mounted as a tmpfs). Do not include a trailing backslash. 76 ''; 77 }; 78 79 daemonFile = mkOption { 80 type = str; 81 default = "/run/psd"; 82 description = '' 83 Where the pid and backup configuration files will be stored. 84 ''; 85 }; 86 }; 87 88 config = mkIf cfg.enable { 89 systemd = { 90 services = { 91 psd = { 92 description = "Profile Sync daemon"; 93 wants = [ "psd-resync.service" "local-fs.target" ]; 94 wantedBy = [ "multi-user.target" ]; 95 preStart = "mkdir -p ${cfg.volatile}"; 96 97 path = with pkgs; [ glibc rsync gawk ]; 98 99 unitConfig = { 100 RequiresMountsFor = [ "/home/" ]; 101 }; 102 103 serviceConfig = { 104 Type = "oneshot"; 105 RemainAfterExit = "yes"; 106 ExecStart = "${pkgs.profile-sync-daemon}/bin/profile-sync-daemon sync"; 107 ExecStop = "${pkgs.profile-sync-daemon}/bin/profile-sync-daemon unsync"; 108 }; 109 }; 110 111 psd-resync = { 112 description = "Timed profile resync"; 113 after = [ "psd.service" ]; 114 wants = [ "psd-resync.timer" ]; 115 partOf = [ "psd.service" ]; 116 117 path = with pkgs; [ glibc rsync gawk ]; 118 119 serviceConfig = { 120 Type = "oneshot"; 121 ExecStart = "${pkgs.profile-sync-daemon}/bin/profile-sync-daemon resync"; 122 }; 123 }; 124 }; 125 126 timers.psd-resync = { 127 description = "Timer for profile sync daemon - ${cfg.resyncTimer}"; 128 partOf = [ "psd-resync.service" "psd.service" ]; 129 130 timerConfig = { 131 OnUnitActiveSec = "${cfg.resyncTimer}"; 132 }; 133 }; 134 }; 135 136 environment.etc."psd.conf".text = configFile; 137 138 }; 139}