2021-02-14 06:22:34 +00:00
|
|
|
{ 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 = {
|
2022-08-28 19:18:44 +00:00
|
|
|
enable = mkEnableOption (lib.mdDoc "zrepl");
|
2021-02-14 06:22:34 +00:00
|
|
|
|
2022-07-10 18:32:27 +00:00
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.zrepl;
|
|
|
|
defaultText = literalExpression "pkgs.zrepl";
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Which package to use for zrepl";
|
2022-07-10 18:32:27 +00:00
|
|
|
};
|
|
|
|
|
2021-02-14 06:22:34 +00:00
|
|
|
settings = mkOption {
|
|
|
|
default = { };
|
2022-08-03 20:46:41 +00:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
Configuration for zrepl. See <https://zrepl.github.io/configuration.html>
|
2021-02-14 06:22:34 +00:00
|
|
|
for more information.
|
|
|
|
'';
|
|
|
|
type = types.submodule {
|
|
|
|
freeformType = format.type;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
### Implementation ###
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2022-07-10 18:32:27 +00:00
|
|
|
environment.systemPackages = [ cfg.package ];
|
2021-02-14 06:22:34 +00:00
|
|
|
|
|
|
|
# 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;
|
|
|
|
|
2022-07-10 18:32:27 +00:00
|
|
|
systemd.packages = [ cfg.package ];
|
2022-03-29 18:44:07 +00:00
|
|
|
|
|
|
|
# Note that pkgs.zrepl copies and adapts the upstream systemd unit, and
|
|
|
|
# the fields defined here only override certain fields from that unit.
|
2021-02-14 06:22:34 +00:00
|
|
|
systemd.services.zrepl = {
|
|
|
|
requires = [ "local-fs.target" ];
|
|
|
|
wantedBy = [ "zfs.target" ];
|
|
|
|
after = [ "zfs.target" ];
|
|
|
|
|
|
|
|
path = [ config.boot.zfs.package ];
|
|
|
|
restartTriggers = [ configFile ];
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
Restart = "on-failure";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|