X-Git-Url: https://git.immae.eu/?p=perso%2FImmae%2FConfig%2FNix%2FNUR.git;a=blobdiff_plain;f=modules%2Fsecrets.nix;h=808b15c5bdeb886347a8f9c34f69891495e0999f;hp=b282e56e207d17f12b2ef46bfc6da5321d909eb7;hb=06782a203fa0ed5ab29a03c96294f138209211da;hpb=a3eb56c4fc73da93d42c9298cc94aafffca0bd37 diff --git a/modules/secrets.nix b/modules/secrets.nix index b282e56e..808b15c5 100644 --- a/modules/secrets.nix +++ b/modules/secrets.nix @@ -39,11 +39,15 @@ if [ -f /run/keys/secrets.tar ]; then if [ ! -f ${location}/currentSecrets ] || ! sha512sum -c --status "${location}/currentSecrets"; then echo "rebuilding secrets" - rm -rf ${location} - install -m0750 -o root -g keys -d ${location} - ${pkgs.gnutar}/bin/tar --strip-components 1 -C ${location} -xf /run/keys/secrets.tar - sha512sum /run/keys/secrets.tar > ${location}/currentSecrets - find ${location} -type d -exec chown root:keys {} \; -exec chmod o-rx {} \; + TMP=$(${pkgs.coreutils}/bin/mktemp -d) + if [ -n "$TMP" ]; then + install -m0750 -o root -g keys -d $TMP + ${pkgs.gnutar}/bin/tar --strip-components 1 -C $TMP -xf /run/keys/secrets.tar + sha512sum /run/keys/secrets.tar > $TMP/currentSecrets + find $TMP -type d -exec chown root:keys {} \; -exec chmod o-rx {} \; + ${pkgs.rsync}/bin/rsync -O -c -av --delete $TMP/ ${location} + rm -rf $TMP + fi fi fi '';