Merge pull request #10988 from Shados/improve-rsnapshot-service
rsnapshot service: Avoid package rebuild, create+use /etc/rsnapshot.conf
This commit is contained in:
commit
1aff127b56
@ -2,12 +2,30 @@
|
||||
|
||||
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 = {
|
||||
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 = "";
|
||||
@ -39,37 +57,17 @@ 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 ];
|
||||
|
||||
config = mkIf cfg.enable (mkMerge [
|
||||
{
|
||||
services.cron.systemCronJobs =
|
||||
mapAttrsToList (interval: time: "${time} root ${myRsnapshot}/bin/rsnapshot ${interval}") cfg.cronIntervals;
|
||||
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;
|
||||
})
|
||||
]);
|
||||
}
|
||||
|
@ -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; {
|
||||
|
Loading…
Reference in New Issue
Block a user