scripts: Use trap to clean up temp directory

This commit is contained in:
SebastianStork 2026-02-05 22:55:20 +01:00
parent 2c76d23692
commit ec0d5b839e
Signed by: SebastianStork
SSH key fingerprint: SHA256:tRrGdjYOwgHxpSc/wTOZQZEjxcb15P0tyXRsbAfd+2Q
2 changed files with 8 additions and 4 deletions

View file

@ -17,6 +17,7 @@ pkgs.writeShellApplication {
host="$1" host="$1"
destination="$2" destination="$2"
root="$(mktemp --directory)" root="$(mktemp --directory)"
trap 'rm -rf "$root"' EXIT
impermanence="$(nix eval ".#nixosConfigurations.$host.config.custom.persistence.enable")" impermanence="$(nix eval ".#nixosConfigurations.$host.config.custom.persistence.enable")"
if [ "$impermanence" = true ]; then if [ "$impermanence" = true ]; then
@ -51,7 +52,5 @@ pkgs.writeShellApplication {
--extra-files "$root" \ --extra-files "$root" \
--flake ".#$host" \ --flake ".#$host" \
--target-host "$destination" --target-host "$destination"
rm -rf "$root"
''; '';
} }

View file

@ -1,4 +1,9 @@
{ self', pkgs, lib, ... }: {
self',
pkgs,
lib,
...
}:
pkgs.writeShellApplication { pkgs.writeShellApplication {
name = "nebula-regen-all-host-certs"; name = "nebula-regen-all-host-certs";