1
0
Fork 0
mirror of https://cgit.krebsco.de/krops synced 2024-11-23 03:29:48 +01:00

populate: support backupping target

This commit is contained in:
tv 2019-07-16 22:12:12 +02:00
parent 42e8085b95
commit 79aa2c6a88

View file

@ -20,6 +20,26 @@ let
fi fi
''; '';
do-backup = { target }: let
sentinelFile = "${target.path}/.populate";
in
shell' target /* sh */ ''
if ! test -d ${quote sentinelFile}; then
>&2 printf 'error" sentinel file is not a directory: %s\n' ${quote (
optionalString (!isLocalTarget target) "${target.host}:" +
sentinelFile
)}
exit 1
fi
rsync >&2 \
-aAXF \
--delete \
--exclude /.populate \
--link-dest=${quote target.path} \
${target.path}/ \
${target.path}/.populate/backup/
'';
pop.derivation = target: source: shell' target /* sh */ '' pop.derivation = target: source: shell' target /* sh */ ''
nix-build -E ${quote source.text} -o ${quote target.path} >&2 nix-build -E ${quote source.text} -o ${quote target.path} >&2
''; '';
@ -162,9 +182,11 @@ let
in in
{ force ? false, source, target }: writeDash "populate.${target.host}" '' { backup ? false, force ? false, source, target }:
writeDash "populate.${target.host}" ''
set -efu set -efu
${check { inherit force target; }} ${check { inherit force target; }}
set -x set -x
${optionalString backup (do-backup { inherit target; })}
${concatStringsSep "\n" (mapAttrsToList (populate target) source)} ${concatStringsSep "\n" (mapAttrsToList (populate target) source)}
'' ''