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