summary refs log tree commit diff
path: root/nixos/modules/services/desktops/profile-sync-daemon.nix
blob: 6206295272fc5b810185e97bd92fc72aabbed009 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
{ config, pkgs, lib, ... }:

with lib;

let
  cfg = config.services.psd;
in {
  options.services.psd = with types; {
    enable = mkOption {
      type = bool;
      default = false;
      description = ''
        Whether to enable the Profile Sync daemon.
      '';
    };
    resyncTimer = mkOption {
      type = str;
      default = "1h";
      example = "1h 30min";
      description = ''
        The amount of time to wait before syncing browser profiles back to the
        disk.

        Takes a systemd.unit time span. The time unit defaults to seconds if
        omitted.
      '';
    };
  };

  config = mkIf cfg.enable {
    systemd = {
      user = {
        services = {
          psd = {
            enable = true;
            description = "Profile Sync daemon";
            wants = [ "psd-resync.service" ];
            wantedBy = [ "default.target" ];
            path = with pkgs; [ rsync kmod gawk nettools util-linux profile-sync-daemon ];
            unitConfig = {
              RequiresMountsFor = [ "/home/" ];
            };
            serviceConfig = {
              Type = "oneshot";
              RemainAfterExit = "yes";
              ExecStart = "${pkgs.profile-sync-daemon}/bin/profile-sync-daemon sync";
              ExecStop = "${pkgs.profile-sync-daemon}/bin/profile-sync-daemon unsync";
            };
          };

          psd-resync = {
            enable = true;
            description = "Timed profile resync";
            after = [ "psd.service" ];
            wants = [ "psd-resync.timer" ];
            partOf = [ "psd.service" ];
            wantedBy = [ "default.target" ];
            path = with pkgs; [ rsync kmod gawk nettools util-linux profile-sync-daemon ];
            serviceConfig = {
              Type = "oneshot";
              ExecStart = "${pkgs.profile-sync-daemon}/bin/profile-sync-daemon resync";
            };
          };
        };

        timers.psd-resync = {
          description = "Timer for profile sync daemon - ${cfg.resyncTimer}";
          partOf = [ "psd-resync.service" "psd.service" ];

          timerConfig = {
            OnUnitActiveSec = "${cfg.resyncTimer}";
          };
        };
      };
    };
  };
}