at 17.09-beta 2.2 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 cfg = config.services.rsnapshot; 7 cfgfile = pkgs.writeText "rsnapshot.conf" '' 8 config_version 1.2 9 cmd_cp ${pkgs.coreutils}/bin/cp 10 cmd_rm ${pkgs.coreutils}/bin/rm 11 cmd_rsync ${pkgs.rsync}/bin/rsync 12 cmd_ssh ${pkgs.openssh}/bin/ssh 13 cmd_logger ${pkgs.inetutils}/bin/logger 14 cmd_du ${pkgs.coreutils}/bin/du 15 cmd_rsnapshot_diff ${pkgs.rsnapshot}/bin/rsnapshot-diff 16 lockfile /run/rsnapshot.pid 17 link_dest 1 18 19 ${cfg.extraConfig} 20 ''; 21in 22{ 23 options = { 24 services.rsnapshot = { 25 enable = mkEnableOption "rsnapshot backups"; 26 enableManualRsnapshot = mkOption { 27 description = "Whether to enable manual usage of the rsnapshot command with this module."; 28 default = true; 29 type = types.bool; 30 }; 31 32 extraConfig = mkOption { 33 default = ""; 34 example = '' 35 retains hourly 24 36 retain daily 365 37 backup /home/ localhost/ 38 ''; 39 type = types.lines; 40 description = '' 41 rsnapshot configuration option in addition to the defaults from 42 rsnapshot and this module. 43 44 Note that tabs are required to separate option arguments, and 45 directory names require trailing slashes. 46 47 The "extra" in the option name might be a little misleading right 48 now, as it is required to get a functional configuration. 49 ''; 50 }; 51 52 cronIntervals = mkOption { 53 default = {}; 54 example = { hourly = "0 * * * *"; daily = "50 21 * * *"; }; 55 type = types.attrsOf types.string; 56 description = '' 57 Periodicity at which intervals should be run by cron. 58 Note that the intervals also have to exist in configuration 59 as retain options. 60 ''; 61 }; 62 }; 63 }; 64 65 config = mkIf cfg.enable (mkMerge [ 66 { 67 services.cron.systemCronJobs = 68 mapAttrsToList (interval: time: "${time} root ${pkgs.rsnapshot}/bin/rsnapshot -c ${cfgfile} ${interval}") cfg.cronIntervals; 69 } 70 (mkIf cfg.enableManualRsnapshot { 71 environment.systemPackages = [ pkgs.rsnapshot ]; 72 environment.etc."rsnapshot.conf".source = cfgfile; 73 }) 74 ]); 75}