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