at 17.09-beta 3.8 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 assertions = [ 90 { assertion = cfg.users != []; 91 message = "services.psd.users must contain at least one user"; 92 } 93 ]; 94 95 systemd = { 96 services = { 97 psd = { 98 description = "Profile Sync daemon"; 99 wants = [ "psd-resync.service" "local-fs.target" ]; 100 wantedBy = [ "multi-user.target" ]; 101 preStart = "mkdir -p ${cfg.volatile}"; 102 103 path = with pkgs; [ glibc rsync gawk ]; 104 105 unitConfig = { 106 RequiresMountsFor = [ "/home/" ]; 107 }; 108 109 serviceConfig = { 110 Type = "oneshot"; 111 RemainAfterExit = "yes"; 112 ExecStart = "${pkgs.profile-sync-daemon}/bin/profile-sync-daemon sync"; 113 ExecStop = "${pkgs.profile-sync-daemon}/bin/profile-sync-daemon unsync"; 114 }; 115 }; 116 117 psd-resync = { 118 description = "Timed profile resync"; 119 after = [ "psd.service" ]; 120 wants = [ "psd-resync.timer" ]; 121 partOf = [ "psd.service" ]; 122 123 path = with pkgs; [ glibc rsync gawk ]; 124 125 serviceConfig = { 126 Type = "oneshot"; 127 ExecStart = "${pkgs.profile-sync-daemon}/bin/profile-sync-daemon resync"; 128 }; 129 }; 130 }; 131 132 timers.psd-resync = { 133 description = "Timer for profile sync daemon - ${cfg.resyncTimer}"; 134 partOf = [ "psd-resync.service" "psd.service" ]; 135 136 timerConfig = { 137 OnUnitActiveSec = "${cfg.resyncTimer}"; 138 }; 139 }; 140 }; 141 142 environment.etc."psd.conf".text = configFile; 143 144 }; 145}