about summary refs log tree commit diff
path: root/modules/psd.nix
blob: 5bb9dc3fe6fbd101433ac0d87f63e2ddcf8933f9 (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
{
  config,
  lib,
  pkgs,
  ...
}:
with lib;
let
  cfg = config.nixfiles.modules.psd;
in
{
  options.nixfiles.modules.psd.enable = mkEnableOption "Profile Sync Daemon";

  config = mkIf cfg.enable {
    hm = {
      home.packages = with pkgs; [ profile-sync-daemon ];

      xdg.configFile."psd/psd.conf".text = ''
        USE_OVERLAYFS="yes"
        USE_BACKUPS="no"
      '';
    };

    systemd.user = {
      services =
        let
          exe = getExe' pkgs.profile-sync-daemon "profile-sync-daemon";
        in
        {
          psd = {
            unitConfig = {
              Description = "Profile-sync-daemon";
              Wants = [ "psd-resync.service" ];
              RequiresMountsFor = "/home/";
              After = [ "local-fs.target" ];
            };
            serviceConfig = {
              RemainAfterExit = true;
              ExecStart = "${exe} startup";
              ExecStop = "${exe} unsync";
            };
            wantedBy = [ "graphical.target" ];
          };

          psd-resync = {
            unitConfig = {
              Description = "Profile-sync-daemon resync";
              After = [ "psd.service" ];
              Wants = [ "psd-resync.timer" ];
              BindsTo = [ "psd.service" ];
            };
            serviceConfig.ExecStart = "${exe} resync";
            wantedBy = [ "graphical.target" ];
          };
        };

      timers.psd-resync = {
        unitConfig = {
          Description = "Profile-sync-daemon resync timer";
          BindsTo = [ "psd.service" ];
        };
        timerConfig.OnUnitActiveSec = "1h";
      };
    };
  };
}

Consider giving Nix/NixOS a try! <3