summary refs log tree commit diff
path: root/nixos/modules/services/backup/zrepl.nix
blob: 4356479b6635e18e2e319bdaf5fdb108b37a7dfd (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
{ config, pkgs, lib, ... }:

with lib;
let
  cfg = config.services.zrepl;
  format = pkgs.formats.yaml { };
  configFile = format.generate "zrepl.yml" cfg.settings;
in
{
  meta.maintainers = with maintainers; [ cole-h ];

  options = {
    services.zrepl = {
      enable = mkEnableOption "zrepl";

      settings = mkOption {
        default = { };
        description = ''
          Configuration for zrepl. See <link
          xlink:href="https://zrepl.github.io/configuration.html"/>
          for more information.
        '';
        type = types.submodule {
          freeformType = format.type;
        };
      };
    };
  };

  ### Implementation ###

  config = mkIf cfg.enable {
    environment.systemPackages = [ pkgs.zrepl ];

    # zrepl looks for its config in this location by default. This
    # allows the use of e.g. `zrepl signal wakeup <job>` without having
    # to specify the storepath of the config.
    environment.etc."zrepl/zrepl.yml".source = configFile;

    systemd.packages = [ pkgs.zrepl ];
    systemd.services.zrepl = {
      requires = [ "local-fs.target" ];
      wantedBy = [ "zfs.target" ];
      after = [ "zfs.target" ];

      path = [ config.boot.zfs.package ];
      restartTriggers = [ configFile ];

      serviceConfig = {
        Restart = "on-failure";
      };
    };
  };
}