diff options
author | tv <tv@krebsco.de> | 2019-07-16 22:12:12 +0200 |
---|---|---|
committer | tv <tv@krebsco.de> | 2019-07-16 22:13:26 +0200 |
commit | 79aa2c6a88dedb11f0971b849c12671d1c90a73b (patch) | |
tree | e4e0e45d4cd49ab964efaf17a6ff2f1853419a8f /pkgs/populate | |
parent | 42e8085b95ff9011b13e7240aa608ea8c6e310b3 (diff) |
populate: support backupping target
Diffstat (limited to 'pkgs/populate')
-rw-r--r-- | pkgs/populate/default.nix | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/pkgs/populate/default.nix b/pkgs/populate/default.nix index 23ee020..ad70d2e 100644 --- a/pkgs/populate/default.nix +++ b/pkgs/populate/default.nix @@ -20,6 +20,26 @@ let 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 */ '' nix-build -E ${quote source.text} -o ${quote target.path} >&2 ''; @@ -162,9 +182,11 @@ let in -{ force ? false, source, target }: writeDash "populate.${target.host}" '' +{ backup ? false, force ? false, source, target }: +writeDash "populate.${target.host}" '' set -efu ${check { inherit force target; }} set -x + ${optionalString backup (do-backup { inherit target; })} ${concatStringsSep "\n" (mapAttrsToList (populate target) source)} '' |