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