at master 2.4 kB view raw
1{ 2 config, 3 pkgs, 4 lib, 5 ... 6}: 7let 8 cfg = config.services.psd; 9in 10{ 11 options.services.psd = with lib.types; { 12 enable = lib.mkOption { 13 type = bool; 14 default = false; 15 description = '' 16 Whether to enable the Profile Sync daemon. 17 ''; 18 }; 19 resyncTimer = lib.mkOption { 20 type = str; 21 default = "1h"; 22 example = "1h 30min"; 23 description = '' 24 The amount of time to wait before syncing browser profiles back to the 25 disk. 26 27 Takes a systemd.unit time span. The time unit defaults to seconds if 28 omitted. 29 ''; 30 }; 31 }; 32 33 config = lib.mkIf cfg.enable { 34 systemd = { 35 user = { 36 services = { 37 psd = { 38 enable = true; 39 description = "Profile Sync daemon"; 40 wants = [ "psd-resync.service" ]; 41 wantedBy = [ "default.target" ]; 42 path = with pkgs; [ 43 rsync 44 kmod 45 gawk 46 net-tools 47 util-linux 48 profile-sync-daemon 49 ]; 50 unitConfig = { 51 RequiresMountsFor = [ "/home/" ]; 52 }; 53 serviceConfig = { 54 Type = "oneshot"; 55 RemainAfterExit = "yes"; 56 ExecStart = "${pkgs.profile-sync-daemon}/bin/profile-sync-daemon sync"; 57 ExecStop = "${pkgs.profile-sync-daemon}/bin/profile-sync-daemon unsync"; 58 }; 59 }; 60 61 psd-resync = { 62 enable = true; 63 description = "Timed profile resync"; 64 after = [ "psd.service" ]; 65 wants = [ "psd-resync.timer" ]; 66 partOf = [ "psd.service" ]; 67 wantedBy = [ "default.target" ]; 68 path = with pkgs; [ 69 rsync 70 kmod 71 gawk 72 net-tools 73 util-linux 74 profile-sync-daemon 75 ]; 76 serviceConfig = { 77 Type = "oneshot"; 78 ExecStart = "${pkgs.profile-sync-daemon}/bin/profile-sync-daemon resync"; 79 }; 80 }; 81 }; 82 83 timers.psd-resync = { 84 description = "Timer for profile sync daemon - ${cfg.resyncTimer}"; 85 partOf = [ 86 "psd-resync.service" 87 "psd.service" 88 ]; 89 90 timerConfig = { 91 OnUnitActiveSec = "${cfg.resyncTimer}"; 92 }; 93 }; 94 }; 95 }; 96 }; 97}