1 { config, lib, pkgs, ... }:
3 cfg = config.services.rsnapshot;
4 cfgfile = pkgs.writeText "rsnapshot.conf" ''
6 cmd_cp ${pkgs.coreutils}/bin/cp
7 cmd_rm ${pkgs.coreutils}/bin/rm
8 cmd_rsync ${pkgs.rsync}/bin/rsync
9 cmd_ssh ${pkgs.openssh}/bin/ssh
10 cmd_logger ${pkgs.inetutils}/bin/logger
11 cmd_du ${pkgs.coreutils}/bin/du
12 cmd_rsnapshot_diff ${pkgs.rsnapshot}/bin/rsnapshot-diff
13 lockfile /run/rsnapshot.pid
21 services.rsnapshot = {
22 enable = lib.mkEnableOption "rsnapshot backups";
23 enableManualRsnapshot = lib.mkOption {
24 description = "Whether to enable manual usage of the rsnapshot command with this module.";
26 type = lib.types.bool;
29 extraConfig = lib.mkOption {
34 backup /home/ localhost/
36 type = lib.types.lines;
38 rsnapshot configuration option in addition to the defaults from
39 rsnapshot and this module.
41 Note that tabs are required to separate option arguments, and
42 directory names require trailing slashes.
44 The "extra" in the option name might be a little misleading right
45 now, as it is required to get a functional configuration.
49 cronIntervals = lib.mkOption {
51 example = { hourly = "0 * * * *"; daily = "50 21 * * *"; };
52 type = lib.types.attrsOf lib.types.str;
54 Periodicity at which intervals should be run by cron.
55 Note that the intervals also have to exist in configuration
62 config = lib.mkIf cfg.enable (lib.mkMerge [
64 services.cron.systemCronJobs =
65 lib.mapAttrsToList (interval: time: "${time} root ${pkgs.rsnapshot}/bin/rsnapshot -c ${cfgfile} ${interval}") cfg.cronIntervals;
67 (lib.mkIf cfg.enableManualRsnapshot {
68 environment.systemPackages = [ pkgs.rsnapshot ];
69 environment.etc."rsnapshot.conf".source = cfgfile;