1{ config, pkgs, lib, ... }:
2
3with lib;
4let
5 cfg = config.services.zrepl;
6 format = pkgs.formats.yaml { };
7 configFile = format.generate "zrepl.yml" cfg.settings;
8in
9{
10 meta.maintainers = with maintainers; [ cole-h ];
11
12 options = {
13 services.zrepl = {
14 enable = mkEnableOption "zrepl";
15
16 settings = mkOption {
17 default = { };
18 description = ''
19 Configuration for zrepl. See <link
20 xlink:href="https://zrepl.github.io/configuration.html"/>
21 for more information.
22 '';
23 type = types.submodule {
24 freeformType = format.type;
25 };
26 };
27 };
28 };
29
30 ### Implementation ###
31
32 config = mkIf cfg.enable {
33 environment.systemPackages = [ pkgs.zrepl ];
34
35 # zrepl looks for its config in this location by default. This
36 # allows the use of e.g. `zrepl signal wakeup <job>` without having
37 # to specify the storepath of the config.
38 environment.etc."zrepl/zrepl.yml".source = configFile;
39
40 systemd.packages = [ pkgs.zrepl ];
41 systemd.services.zrepl = {
42 requires = [ "local-fs.target" ];
43 wantedBy = [ "zfs.target" ];
44 after = [ "zfs.target" ];
45
46 path = [ config.boot.zfs.package ];
47 restartTriggers = [ configFile ];
48
49 serviceConfig = {
50 Restart = "on-failure";
51 };
52 };
53 };
54}