nix-community / nix-user-chroot

Install & Run nix without root permissions [maintainer=@Mic92]
MIT License
280 stars 25 forks source link

coreutils: fails to build from source under nix-user-chroot #101

Closed skeuchel closed 1 year ago

skeuchel commented 1 year ago

Currently compiling pkgs.coreutils from source fails the df-symlink.sh test. The relevant output in the build log is

FAIL: tests/df/df-symlink
=========================

--- exp 2022-12-12 13:10:42.252000000 +0000
+++ out 2022-12-12 13:10:42.256000000 +0000
@@ -1,2 +1,2 @@
 Filesystem     Mounted on
-/dev/vda1      /opt
+/dev/vda1      /tmp
110 90 254:1 /opt /opt rw,relatime master:1 - ext4 /dev/vda1 rw,errors=remount-ro
[...]
218 90 254:1 /home/steve/.nix /nix rw,relatime master:1 - ext4 /dev/vda1 rw,errors=remount-ro
FAIL tests/df/df-symlink.sh (exit status: 1)

I believe the second test in the file is failing, which essentially compares the output of the following two commands

steve@deb:~$ df --out=source,target /tmp
Filesystem     Mounted on
/dev/vda1      /tmp
steve@deb:~$ df --out=source,target /dev/vda1
Filesystem     Mounted on
/dev/vda1      /opt

Even though the system only has one proper filesystem (/dev/vda1 mounted on /), nix-user-chroot is creating multiple new mountpoints for the chroot which confuses df. The restriction of the "test to systems with a 1:1 mapping between source and target" doesn't appear to work as intended. I believe this can be resolved by simply not creating the chrooted mountpoints for /tmp, /opt, /home etc. when there is no particular filesystem for them in the host env.

Reproduce

Filesystem     Mounted on
udev           /dev
tmpfs          /run
/dev/vda1      /
tmpfs          /dev/shm
tmpfs          /run/lock
tmpfs          /run/user/1000

Output of `df --out=source,target` under `nix-user-chroot` ``` Filesystem Mounted on /dev/vda1 /opt udev /dev tmpfs /dev/shm tmpfs /run tmpfs /run/lock tmpfs /run/user/1000 ```
Contents of /proc/mounts without nix-user-chroot ``` sysfs /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0 proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0 udev /dev devtmpfs rw,nosuid,relatime,size=4056728k,nr_inodes=1014182,mode=755 0 0 devpts /dev/pts devpts rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000 0 0 tmpfs /run tmpfs rw,nosuid,nodev,noexec,relatime,size=814708k,mode=755 0 0 /dev/vda1 / ext4 rw,relatime,errors=remount-ro 0 0 securityfs /sys/kernel/security securityfs rw,nosuid,nodev,noexec,relatime 0 0 tmpfs /dev/shm tmpfs rw,nosuid,nodev 0 0 tmpfs /run/lock tmpfs rw,nosuid,nodev,noexec,relatime,size=5120k 0 0 cgroup2 /sys/fs/cgroup cgroup2 rw,nosuid,nodev,noexec,relatime,nsdelegate,memory_recursiveprot 0 0 pstore /sys/fs/pstore pstore rw,nosuid,nodev,noexec,relatime 0 0 none /sys/fs/bpf bpf rw,nosuid,nodev,noexec,relatime,mode=700 0 0 systemd-1 /proc/sys/fs/binfmt_misc autofs rw,relatime,fd=30,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=10650 0 0 hugetlbfs /dev/hugepages hugetlbfs rw,relatime,pagesize=2M 0 0 mqueue /dev/mqueue mqueue rw,nosuid,nodev,noexec,relatime 0 0 debugfs /sys/kernel/debug debugfs rw,nosuid,nodev,noexec,relatime 0 0 tracefs /sys/kernel/tracing tracefs rw,nosuid,nodev,noexec,relatime 0 0 configfs /sys/kernel/config configfs rw,nosuid,nodev,noexec,relatime 0 0 fusectl /sys/fs/fuse/connections fusectl rw,nosuid,nodev,noexec,relatime 0 0 tmpfs /run/user/1000 tmpfs rw,nosuid,nodev,relatime,size=814704k,nr_inodes=203676,mode=700,uid=1000,gid=1000 0 0 ```
Contents of /proc/mounts with nix-user-chroot ``` /dev/vda1 /opt ext4 rw,relatime,errors=remount-ro 0 0 /dev/vda1 /etc ext4 rw,relatime,errors=remount-ro 0 0 /dev/vda1 /media ext4 rw,relatime,errors=remount-ro 0 0 /dev/vda1 /var ext4 rw,relatime,errors=remount-ro 0 0 /dev/vda1 /mnt ext4 rw,relatime,errors=remount-ro 0 0 /dev/vda1 /home ext4 rw,relatime,errors=remount-ro 0 0 udev /dev devtmpfs rw,nosuid,relatime,size=4056728k,nr_inodes=1014182,mode=755 0 0 devpts /dev/pts devpts rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000 0 0 tmpfs /dev/shm tmpfs rw,nosuid,nodev 0 0 hugetlbfs /dev/hugepages hugetlbfs rw,relatime,pagesize=2M 0 0 mqueue /dev/mqueue mqueue rw,nosuid,nodev,noexec,relatime 0 0 sysfs /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0 securityfs /sys/kernel/security securityfs rw,nosuid,nodev,noexec,relatime 0 0 cgroup2 /sys/fs/cgroup cgroup2 rw,nosuid,nodev,noexec,relatime,nsdelegate,memory_recursiveprot 0 0 pstore /sys/fs/pstore pstore rw,nosuid,nodev,noexec,relatime 0 0 none /sys/fs/bpf bpf rw,nosuid,nodev,noexec,relatime,mode=700 0 0 debugfs /sys/kernel/debug debugfs rw,nosuid,nodev,noexec,relatime 0 0 tracefs /sys/kernel/tracing tracefs rw,nosuid,nodev,noexec,relatime 0 0 configfs /sys/kernel/config configfs rw,nosuid,nodev,noexec,relatime 0 0 fusectl /sys/fs/fuse/connections fusectl rw,nosuid,nodev,noexec,relatime 0 0 /dev/vda1 /tmp ext4 rw,relatime,errors=remount-ro 0 0 /dev/vda1 /tmp/nix-chroot.eDJknc/opt ext4 rw,relatime,errors=remount-ro 0 0 /dev/vda1 /tmp/nix-chroot.eDJknc/etc ext4 rw,relatime,errors=remount-ro 0 0 /dev/vda1 /tmp/nix-chroot.eDJknc/media ext4 rw,relatime,errors=remount-ro 0 0 /dev/vda1 /tmp/nix-chroot.eDJknc/var ext4 rw,relatime,errors=remount-ro 0 0 /dev/vda1 /tmp/nix-chroot.eDJknc/mnt ext4 rw,relatime,errors=remount-ro 0 0 /dev/vda1 /tmp/nix-chroot.eDJknc/home ext4 rw,relatime,errors=remount-ro 0 0 udev /tmp/nix-chroot.eDJknc/dev devtmpfs rw,nosuid,relatime,size=4056728k,nr_inodes=1014182,mode=755 0 0 devpts /tmp/nix-chroot.eDJknc/dev/pts devpts rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000 0 0 tmpfs /tmp/nix-chroot.eDJknc/dev/shm tmpfs rw,nosuid,nodev 0 0 hugetlbfs /tmp/nix-chroot.eDJknc/dev/hugepages hugetlbfs rw,relatime,pagesize=2M 0 0 mqueue /tmp/nix-chroot.eDJknc/dev/mqueue mqueue rw,nosuid,nodev,noexec,relatime 0 0 sysfs /tmp/nix-chroot.eDJknc/sys sysfs rw,nosuid,nodev,noexec,relatime 0 0 securityfs /tmp/nix-chroot.eDJknc/sys/kernel/security securityfs rw,nosuid,nodev,noexec,relatime 0 0 cgroup2 /tmp/nix-chroot.eDJknc/sys/fs/cgroup cgroup2 rw,nosuid,nodev,noexec,relatime,nsdelegate,memory_recursiveprot 0 0 pstore /tmp/nix-chroot.eDJknc/sys/fs/pstore pstore rw,nosuid,nodev,noexec,relatime 0 0 none /tmp/nix-chroot.eDJknc/sys/fs/bpf bpf rw,nosuid,nodev,noexec,relatime,mode=700 0 0 debugfs /tmp/nix-chroot.eDJknc/sys/kernel/debug debugfs rw,nosuid,nodev,noexec,relatime 0 0 tracefs /tmp/nix-chroot.eDJknc/sys/kernel/tracing tracefs rw,nosuid,nodev,noexec,relatime 0 0 configfs /tmp/nix-chroot.eDJknc/sys/kernel/config configfs rw,nosuid,nodev,noexec,relatime 0 0 fusectl /tmp/nix-chroot.eDJknc/sys/fs/fuse/connections fusectl rw,nosuid,nodev,noexec,relatime 0 0 /dev/vda1 /lost+found ext4 rw,relatime,errors=remount-ro 0 0 proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0 systemd-1 /proc/sys/fs/binfmt_misc autofs rw,relatime,fd=30,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=10650 0 0 /dev/vda1 /root ext4 rw,relatime,errors=remount-ro 0 0 /dev/vda1 /srv ext4 rw,relatime,errors=remount-ro 0 0 tmpfs /run tmpfs rw,nosuid,nodev,noexec,relatime,size=814708k,mode=755 0 0 tmpfs /run/lock tmpfs rw,nosuid,nodev,noexec,relatime,size=5120k 0 0 tmpfs /run/user/1000 tmpfs rw,nosuid,nodev,relatime,size=814704k,nr_inodes=203676,mode=700,uid=1000,gid=1000 0 0 /dev/vda1 /usr ext4 rw,relatime,errors=remount-ro 0 0 /dev/vda1 /boot ext4 rw,relatime,errors=remount-ro 0 0 /dev/vda1 /nix ext4 rw,relatime,errors=remount-ro 0 0 ```
Mic92 commented 1 year ago

Yes. Usernamespaces break assumptions of coreutils test. This is a linux kernel limitation that we have to live with unfortunately.