Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The new tarballBuilder trap fails when trying to remove /var/empty. #337

Closed
terlar opened this issue Nov 14, 2023 · 3 comments
Closed

The new tarballBuilder trap fails when trying to remove /var/empty. #337

terlar opened this issue Nov 14, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@terlar
Copy link
Contributor

terlar commented Nov 14, 2023

Bug description

I recently tried migrating over to the new tarballBuilder. However when I try to execute the script I get the following error:

rm: cannot remove '/tmp/nixos-wsl-tarball.H3cpgOr2Np/var/empty': Operation not permitted

Apparently that folder is marked as immutable, even preventing root from removing it, however it can be solved by:

chattr -i /tmp/nixos-wsl-tarball.H3cpgOr2Np/var/empty

To Reproduce

Steps to reproduce the behavior:

sudo nix run --print-build-logs github:nix-community/NixOS-WSL#nixosConfigurations.modern.config.system.build.tarballBuilder

Expected behavior
Not failing on the trap after script execution.

Logs

Include relevant console logs

...
installing the boot loader...
setting up /etc...
setting up /bin...
setting up /bin/login...
setting up /sbin/init shim...
installation finished!
[NixOS-WSL] Adding channel...
setting up /etc...
setting up /bin...
setting up /bin/login...
setting up /sbin/init shim...
[NixOS-WSL] Adding default config...
[NixOS-WSL] Compressing...
rm: cannot remove '/tmp/nixos-wsl-tarball.xXcwgyysE7/var/empty': Operation not permitted

@terlar terlar added the bug Something isn't working label Nov 14, 2023
@terlar
Copy link
Contributor Author

terlar commented Nov 15, 2023

I got it working like this:

diff --git a/modules/build-tarball.nix b/modules/build-tarball.nix
index 8341f7f..4cdd3e5 100644
--- a/modules/build-tarball.nix
+++ b/modules/build-tarball.nix
@@ -64,7 +64,7 @@ in

         root=$(mktemp -p "''${TMPDIR:-/tmp}" -d nixos-wsl-tarball.XXXXXXXXXX)
         # FIXME: fails in CI for some reason, but we don't really care because it's CI
-        trap 'rm -rf "$root" || true' INT TERM EXIT
+        trap 'chattr -Rf -i "$root" || true && rm -rf "$root" || true' INT TERM EXIT

         chmod o+rx "$root"

or

diff --git a/modules/build-tarball.nix b/modules/build-tarball.nix
index 8341f7f..3d787ab 100644
--- a/modules/build-tarball.nix
+++ b/modules/build-tarball.nix
@@ -64,7 +64,7 @@ in

         root=$(mktemp -p "''${TMPDIR:-/tmp}" -d nixos-wsl-tarball.XXXXXXXXXX)
         # FIXME: fails in CI for some reason, but we don't really care because it's CI
-        trap 'rm -rf "$root" || true' INT TERM EXIT
+        trap 'chattr -i "$root/var/empty" || true && rm -rf "$root" || true' INT TERM EXIT

         chmod o+rx "$root"

@nzbr
Copy link
Member

nzbr commented Nov 20, 2023

Can you make this, as well as #338 into a PR?

@terlar
Copy link
Contributor Author

terlar commented Nov 21, 2023

Sure, I will do

terlar added a commit to terlar/NixOS-WSL that referenced this issue Nov 22, 2023
@nzbr nzbr closed this as completed in 8f30089 Nov 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants