From c90d5eb2988995e8e7bd387a5d1899d935882680 Mon Sep 17 00:00:00 2001 From: Alexei Robyn Date: Wed, 11 May 2016 20:52:49 +1000 Subject: [PATCH 1/3] rsnapshot module: Avoid package rebuild, pass config file explicitly. --- nixos/modules/services/backup/rsnapshot.nix | 48 ++++++++------------- 1 file changed, 17 insertions(+), 31 deletions(-) diff --git a/nixos/modules/services/backup/rsnapshot.nix b/nixos/modules/services/backup/rsnapshot.nix index 96657cf17fc5..05dc83372bef 100644 --- a/nixos/modules/services/backup/rsnapshot.nix +++ b/nixos/modules/services/backup/rsnapshot.nix @@ -2,7 +2,19 @@ with lib; -let cfg = config.services.rsnapshot; +let + cfg = config.services.rsnapshot; + cfgfile = pkgs.writeText "rsnapshot.conf" '' + config_version 1.2 + cmd_cp ${pkgs.coreutils}/bin/cp + cmd_rsync ${pkgs.rsync}/bin/rsync + cmd_ssh ${pkgs.openssh}/bin/ssh + cmd_logger ${pkgs.inetutils}/bin/logger + cmd_du ${pkgs.coreutils}/bin/du + lockfile /run/rsnapshot.pid + + ${cfg.extraConfig} + ''; in { options = { @@ -39,37 +51,11 @@ in as retain options. ''; }; - - package = mkOption { - type = types.package; - default = pkgs.rsnapshot; - defaultText = "pkgs.rsnapshot"; - example = literalExample "pkgs.rsnapshotGit"; - description = '' - RSnapshot package to use. - ''; - }; }; }; - config = mkIf cfg.enable (let - myRsnapshot = cfg.package.override { configFile = rsnapshotCfg; }; - rsnapshotCfg = with pkgs; writeText "gen-rsnapshot.conf" ('' - config_version 1.2 - cmd_cp ${coreutils}/bin/cp - cmd_rsync ${rsync}/bin/rsync - cmd_ssh ${openssh}/bin/ssh - cmd_logger ${inetutils}/bin/logger - cmd_du ${coreutils}/bin/du - lockfile /run/rsnapshot.pid - - ${cfg.extraConfig} - ''); - in { - environment.systemPackages = [ myRsnapshot ]; - - services.cron.systemCronJobs = - mapAttrsToList (interval: time: "${time} root ${myRsnapshot}/bin/rsnapshot ${interval}") cfg.cronIntervals; - } - ); + config = mkIf cfg.enable { + services.cron.systemCronJobs = + mapAttrsToList (interval: time: "${time} root ${pkgs.rsnapshot}/bin/rsnapshot -c ${cfgfile} ${interval}") cfg.cronIntervals; + }; } From 3f35d670de2285293ed14c2623e86c27868da6b8 Mon Sep 17 00:00:00 2001 From: Alexei Robyn Date: Thu, 12 May 2016 09:19:16 +1000 Subject: [PATCH 2/3] rsnapshot: Remove unnecessary argument, refactor one-line patch to flags. --- pkgs/tools/backup/rsnapshot/default.nix | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/pkgs/tools/backup/rsnapshot/default.nix b/pkgs/tools/backup/rsnapshot/default.nix index f46a2c20de42..e4ecb4becdef 100644 --- a/pkgs/tools/backup/rsnapshot/default.nix +++ b/pkgs/tools/backup/rsnapshot/default.nix @@ -1,20 +1,5 @@ -{ fetchurl, stdenv, writeText, perl, openssh, rsync, logger, - configFile ? "/etc/rsnapshot.conf" }: +{ fetchurl, stdenv, writeText, perl, openssh, rsync, logger }: -let patch = writeText "rsnapshot-config.patch" '' ---- rsnapshot-program.pl 2013-10-05 20:31:08.715991442 +0200 -+++ rsnapshot-program.pl 2013-10-05 20:31:42.496193633 +0200 -@@ -383,7 +383,7 @@ - } - - # set global variable -- $config_file = $default_config_file; -+ $config_file = '${configFile}'; - } - - # accepts no args -''; -in stdenv.mkDerivation rec { name = "rsnapshot-1.4.1"; @@ -25,10 +10,12 @@ stdenv.mkDerivation rec { propagatedBuildInputs = [perl openssh rsync logger]; + configureFlags = [ "--sysconfdir=/etc --prefix=/" ]; + makeFlags = [ "DESTDIR=$(out)" ]; + patchPhase = '' substituteInPlace "Makefile.in" --replace \ "/usr/bin/pod2man" "${perl}/bin/pod2man" - patch -p0 <${patch} ''; meta = with stdenv.lib; { From 1e2ec5817c6f5642df34285fd2c74f100064c485 Mon Sep 17 00:00:00 2001 From: Alexei Robyn Date: Wed, 11 May 2016 21:21:56 +1000 Subject: [PATCH 3/3] rsnapshot module: Enable manual rsnapshot usage with module config. --- nixos/modules/services/backup/rsnapshot.nix | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/nixos/modules/services/backup/rsnapshot.nix b/nixos/modules/services/backup/rsnapshot.nix index 05dc83372bef..ce628a720363 100644 --- a/nixos/modules/services/backup/rsnapshot.nix +++ b/nixos/modules/services/backup/rsnapshot.nix @@ -20,6 +20,12 @@ in options = { services.rsnapshot = { enable = mkEnableOption "rsnapshot backups"; + enableManualRsnapshot = mkOption { + description = "Whether to enable manual usage of the rsnapshot command with this module."; + default = true; + example = false; + type = types.bool; + }; extraConfig = mkOption { default = ""; @@ -54,8 +60,14 @@ in }; }; - config = mkIf cfg.enable { - services.cron.systemCronJobs = - mapAttrsToList (interval: time: "${time} root ${pkgs.rsnapshot}/bin/rsnapshot -c ${cfgfile} ${interval}") cfg.cronIntervals; - }; + config = mkIf cfg.enable (mkMerge [ + { + services.cron.systemCronJobs = + mapAttrsToList (interval: time: "${time} root ${pkgs.rsnapshot}/bin/rsnapshot -c ${cfgfile} ${interval}") cfg.cronIntervals; + } + (mkIf cfg.enableManualRsnapshot { + environment.systemPackages = [ pkgs.rsnapshot ]; + environment.etc."rsnapshot.conf".source = cfgfile; + }) + ]); }