about summary refs log tree commit diff stats
path: root/modules/by-name/un/unison/module.nix
blob: baf92b02e5636e6df4b57c04c2c82791e53c066f (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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
{
  lib,
  config,
  pkgs,
  sysLib,
  ...
}: let
  cfg = config.soispha.services.unison;

  script = import ./shellScript.nix {inherit sysLib lib pkgs cfg;};
in {
  options.soispha.services.unison = let
    homePath = lib.types.strMatching "^~.*";
  in {
    enable = lib.mkEnableOption "a unison home sync script";

    dataDir = lib.mkOption {
      type = lib.types.path;
      description = ''
        This directory is used by unison to store it's data.
      '';
    };

    foreign = {
      address = lib.mkOption {
        type = lib.types.str;
        description = ''
          The address to contact via ssh, when syncing.
        '';
      };
      userName = lib.mkOption {
        type = lib.types.str;
        description = ''
          The user name to try to login with at the foreign host.
        '';
      };
    };

    userSourceDir = lib.mkOption {
      description = ''
        The directory to replace the `~` in the relative user paths with.
        If using `impermanence`, this should be the path to the persistent home directory.
      '';
    };

    pathsToIgnore = lib.mkOption {
      type = lib.types.listOf homePath;
      default = [];
      description = ''
        A list of the paths that should not be synced.
        Beware that this applies not only to this path, but also to all paths under it.
      '';
    };
    pathsToSync = lib.mkOption {
      type = lib.types.listOf homePath;
      default = [];
      description = ''
        A list of the paths that should be synced.
        Beware that this applies not only to this path, but also to all paths under it.
      '';
    };

    unisonOptions = lib.mkOption {
      internal = true;
      default = {
        sshcmd = "ssh";
        ui = "text";
        auto = "true";
        # This is a trap, thanks to the HM links
        # TODO: Auto-ignore all `home.file` paths <2024-10-24>
        links = "false";

        backupdir = "${cfg.dataDir}/backups";
        backuploc = "central";
      };
      type = lib.types.attrsOf lib.types.str;
      description = "The options passed to every unison call.";
    };
  };

  config = lib.mkIf cfg.enable {
    home-manager.users.soispha = {
      home.sessionVariables = {
        UNISON = cfg.dataDir;
      };
      home.packages = [
        pkgs.unison
        script
      ];
    };
  };
}