aboutsummaryrefslogtreecommitdiff
path: root/modules/zrepl.nix
blob: 5bcc17b638bd31c29dbfe4d30a35f62964f8a68e (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
{ config, lib, pkgs, ... }:
let
  cfg = config.services.zrepl;
in
{
  options = {
    services.zrepl = {
      enable = lib.mkEnableOption "Enable the zrepl daemon";

      config = lib.mkOption {
        type = lib.types.lines;
        default = "";
        description = "Configuration";
      };
    };
  };

  config = lib.mkIf cfg.enable {
    secrets.keys = {
      "zrepl/zrepl.yml" = {
        permissions = "0400";
        text = cfg.config;
        user = config.systemd.services.zrepl.serviceConfig.User or "root";
        group = config.systemd.services.zrepl.serviceConfig.Group or "root";
      };
    };
    services.filesWatcher.zrepl = {
      restart = true;
      paths = [ config.secrets.fullPaths."zrepl/zrepl.yml" ];
    };
    systemd.services.zrepl = {
      description = "zrepl daemon";
      wantedBy = [ "multi-user.target" ];
      path = [ pkgs.zfs pkgs.openssh ];
      serviceConfig = {
        ExecStart =
          let configFile = config.secrets.fullPaths."zrepl/zrepl.yml";
          in "${pkgs.zrepl}/bin/zrepl daemon --config ${configFile}";
        Type = "simple";
        RuntimeDirectory= "zrepl";
        RuntimeDirectoryMode= "0700";
      };
    };
  };
}