Open BentonEdmondson opened 6 months ago
nix-appimage uses unprivileged user namespaces itself -- it works by copying all required nix store files into the AppImage, then "mounting" them at /nix/store. I don't see any other way of doing that without user namespaces.
I'm guessing that you're getting these errors because Linux doesn't allow nested user namespaces? If that's the case I'm leaning towards marking this as WONTFIX, sorry :(
No, nesting user namespaces is possible:
$ unshare -c unshare -U echo hi
hi
I looked at it more closely and I found the problem. The man page says you can't create a user namespace within a chroot:
EPERM (since Linux 3.9) CLONE_NEWUSER was specified in flags and the caller is in a chroot environment (i.e., the caller's root directory does not match the root directory of the mount namespace in which it resides).
You chroot right here: https://github.com/ralismark/nix-appimage/blob/17dd6001ec228ea0b8505d6904fc5796d3de5012/apprun.c#L188-L198
When I remove those lines the problem seems to be completely fixed. What is the reason for the chroot?
i need chroot in order to mount the bundled /nix/store. on systems without nix, I'm pretty sure i need there to already be a /nix directory in order to mount, and since i can't make that directory, i need to make a copy of / with the extra directory and chroot
Is it possible to use the mountroot
as a lowerdir
in an overlayfs instead of chrooting to it? This would allow "creating" (overlaying) a /nix
directory even though the mountpoint doesn't exist.
On nix systems the existing nix store will be merged and take precedence (as the upperdir). I don't know if this could be a problem. Maybe the AppImage's nix store needs to be made content-addressed so potential collisions are irrelevant?
@caspervk I had a look at replacing the current "recreate /" method with using overlayfs, which would likely be much nicer. I'm pretty sure overlayfs only ever modifies upperdir
, so you'd be looking to overlay / on top of the bundled nix/store. I had a play around with trying to get this to work but there are some major problems:
I've started looking at mergerfs/unionfs-fuse/etc. I think ideally the solution would involve using a FUSE merging filesystem, then chrooting into it, which would avoid needing user namespaces entirely. Unfortunately, I don't really have the time to fully investigate this, so if anyone wants to look into it, here's my progress so far:
mergerfs -o cache.files=partial,dropcacheonclose=true,category.create=mfs underlay=RO:/ mountpoint
(where underlay is a directory with our bundled nix/store). However, "mergerfs is designed and intended to be run as root and may exibit incorrect behavior if run otherwise", which basically means this won't work.
My native
unshare
works:But the AppImage doesn't:
I believe this is the reason Steam, Chromium, and Electron apps don't work:
This article suggests that this is not a fundamental limitation of the AppImage format; assuming unprivileged user namespaces are enabled in the kernel, Electron AppImages can be run without disabling their sandbox.