{ config, pkgs, local-nur, ... }: 

let
  watchProfile = {
    auto = true;
    batch = true;
    repeat = "watch";

    clientHostName = config.networking.hostName;
  };
in {
  imports = with local-nur.modules; [ files unison ];

  environment.files.sync = {
    root = "/var/sync";
    directories =
      let unisonPerms = {
        mode = "02770";
        user = "unison";
        group = "unison";
      }; in {
      "." = unisonPerms;
      static = unisonPerms;
    };
  };

  services.unison = {
    enable = true;
    
    profiles.static = watchProfile // {
      root = [ /var/sync/static ssh://unison@tilpner.com//var/sync/static ];
    };
  };
}