On one of my NixOS machines, I stopped being able to run nix-shell
without root for some reason. I’ve tried a few things I’ve found googling and searching on the forums here, but nothing has worked so far. The other NixOS machine I don’t have this issue.
Issue
If I try to use nix-shell -p somePackage
and somePackage isn’t in the store yet, it fails with "error opening lock file … Read-only filesystem.
If I then go sudo nix-shell -p somePackage
it runs fine.
Then after having made a shell with sudo, I’m able then able to open nix-shells with somePackage without needing root.
Example
cat@beppo ~> nix-shell -p xcaddy
error:
… while calling the 'derivationStrict' builtin
at /builtin/derivation.nix:9:12: (source not available)
… while evaluating derivation 'shell'
whose name attribute is located at /nix/store/27gmaqdprq2g8xrgk9jkp691qykb9c4s-nixos-24.05/nixos/pkgs/stdenv/generic/make-deriva
tion.nix:331:7
… while evaluating attribute 'buildInputs' of derivation 'shell'
at /nix/store/27gmaqdprq2g8xrgk9jkp691qykb9c4s-nixos-24.05/nixos/pkgs/stdenv/generic/make-derivation.nix:378:7:
377| depsHostHost = elemAt (elemAt dependencies 1) 0;
378| buildInputs = elemAt (elemAt dependencies 1) 1;
| ^
379| depsTargetTarget = elemAt (elemAt dependencies 2) 0;
(stack trace truncated; use '--show-trace' to show the full trace)
error: opening lock file '/nix/store/dpshf2nsmygnd54df7ncq47c7rmrbjf7-inject_version_info.diff.lock': Read-only file system
Then with root:
cat@beppo ~> sudo nix-shell -p xcaddy
this path will be fetched (1.11 MiB download, 3.41 MiB unpacked):
/nix/store/8grfa8lbq1lf0wxnhaxgfqmmcddhh6jy-xcaddy-0.4.2
copying path '/nix/store/8grfa8lbq1lf0wxnhaxgfqmmcddhh6jy-xcaddy-0.4.2' from 'https://cache.nixos.org'...
[nix-shell:/home/cat]# which xcaddy
/nix/store/8grfa8lbq1lf0wxnhaxgfqmmcddhh6jy-xcaddy-0.4.2/bin/xcaddy
Now again without root, but successfully:
cat@beppo ~> nix-shell -p xcaddy
[nix-shell:~]$ which xcaddy
/nix/store/8grfa8lbq1lf0wxnhaxgfqmmcddhh6jy-xcaddy-0.4.2/bin/xcaddy
Additional context
system info:
cat@beppo ~> nix-shell -p nix-info --run "nix-info -m"
- system: `"x86_64-linux"`
- host os: `Linux 6.9.3, NixOS, 24.05 (Uakari), 24.05.984.0b8e7a1ae5a9`
- multi-user?: `no`
- sandbox: `yes`
- version: `nix-env (Nix) 2.18.2`
- channels(root): `"nixos-24.05"`
- nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`
mount info:
cat@beppo ~> sudo findmnt -A -R &| tee mounts.txt
TARGET SOURCE FSTYPE OPTIONS
/ /dev/sdc:/dev/sda:/dev/sdb:/dev/sdd:/dev/sde:/dev/nvme1n1:/dev/nvme2n1:/dev/nvme0n1p2 bcachefs rw,noatime,metadata_replicas=2,data_replicas=2,compression=lz4,foreground_target=ssd,background_target=hdd,promote_target=ssd,nojournal_transaction_names
├─/dev devtmpfs devtmpfs rw,nosuid,size=6587852k,nr_inodes=16463976,mode=755
│ ├─/dev/pts devpts devpts rw,nosuid,noexec,relatime,gid=3,mode=620,ptmxmode=666
│ ├─/dev/shm tmpfs tmpfs rw,nosuid,nodev
│ ├─/dev/mqueue mqueue mqueue rw,nosuid,nodev,noexec,relatime
│ └─/dev/hugepages hugetlbfs hugetlbfs rw,nosuid,nodev,relatime,pagesize=2M
├─/proc proc proc rw,nosuid,nodev,noexec,relatime
├─/run tmpfs tmpfs rw,nosuid,nodev,size=32939260k,mode=755
│ ├─/run/keys ramfs ramfs rw,nosuid,nodev,relatime,mode=750
│ ├─/run/wrappers tmpfs tmpfs rw,nodev,relatime,mode=755
│ └─/run/user/1000 tmpfs tmpfs rw,nosuid,nodev,relatime,size=13175704k,nr_inodes=3293926,mode=700,uid=1000,gid=999
├─/sys sysfs sysfs rw,nosuid,nodev,noexec,relatime
│ ├─/sys/kernel/security securityfs securityfs rw,nosuid,nodev,noexec,relatime
│ ├─/sys/fs/cgroup cgroup2 cgroup2 rw,nosuid,nodev,noexec,relatime,nsdelegate,memory_recursiveprot
│ ├─/sys/fs/pstore pstore pstore rw,nosuid,nodev,noexec,relatime
│ ├─/sys/firmware/efi/efivars efivarfs efivarfs rw,nosuid,nodev,noexec,relatime
│ ├─/sys/fs/bpf bpf bpf rw,nosuid,nodev,noexec,relatime,mode=700
│ ├─/sys/kernel/debug debugfs debugfs rw,nosuid,nodev,noexec,relatime
│ │ └─/sys/kernel/debug/tracing tracefs tracefs rw,nosuid,nodev,noexec,relatime
│ ├─/sys/fs/fuse/connections fusectl fusectl rw,nosuid,nodev,noexec,relatime
│ └─/sys/kernel/config configfs configfs rw,nosuid,nodev,noexec,relatime
├─/nix/store /dev/sdc:/dev/sda:/dev/sdb:/dev/sdd:/dev/sde:/dev/nvme1n1:/dev/nvme2n1:/dev/nvme0n1p2[/nix/store] bcachefs ro,noatime,metadata_replicas=2,data_replicas=2,compression=lz4,foreground_target=ssd,background_target=hdd,promote_target=ssd,nojournal_transaction_names
└─/boot /dev/nvme0n1p1 vfat rw,relatime,fmask=0077,dmask=0077,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro
for comparison, here’s the system info and mounts for my machine without the issue:
cat@bippo ~> nix-shell -p xcaddy
- system: `"x86_64-linux"`
- host os: `Linux 6.9.3, NixOS, 24.05 (Uakari), 24.05.984.0b8e7a1ae5a9`
- multi-user?: `yes`
- sandbox: `yes`
- version: `nix-env (Nix) 2.18.2`
- channels(root): `"nixos-24.05"`
- nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`
TARGET SOURCE FSTYPE OPTIONS
/ /dev/sda:/dev/sdb:/dev/nvme0n1p2:/dev/nvme1n1 bcachefs rw,noatime,compression=lz4,foreground_target=ssd,background_target=hdd,promote_target=ssd
├─/dev devtmpfs devtmpfs rw,nosuid,size=1622720k,nr_inodes=4053346,mode=755
│ ├─/dev/pts devpts devpts rw,nosuid,noexec,relatime,gid=3,mode=620,ptmxmode=666
│ ├─/dev/shm tmpfs tmpfs rw,nosuid,nodev,size=16227200k
│ ├─/dev/mqueue mqueue mqueue rw,nosuid,nodev,noexec,relatime
│ └─/dev/hugepages hugetlbfs hugetlbfs rw,nosuid,nodev,relatime,pagesize=2M
├─/proc proc proc rw,nosuid,nodev,noexec,relatime
├─/run tmpfs tmpfs rw,nosuid,nodev,size=8113600k,mode=755
│ ├─/run/keys ramfs ramfs rw,nosuid,nodev,relatime,mode=750
│ ├─/run/wrappers tmpfs tmpfs rw,nodev,relatime,size=16227200k,mode=755
│ └─/run/user/1000 tmpfs tmpfs rw,nosuid,nodev,relatime,size=3245436k,nr_inodes=811359,mode=700,uid=1000,gid=998
│ ├─/run/user/1000/gvfs gvfsd-fuse fuse.gvfsd-fuse rw,nosuid,nodev,relatime,user_id=1000,group_id=998
│ └─/run/user/1000/doc portal fuse.portal rw,nosuid,nodev,relatime,user_id=1000,group_id=998
├─/sys sysfs sysfs rw,nosuid,nodev,noexec,relatime
│ ├─/sys/kernel/security securityfs securityfs rw,nosuid,nodev,noexec,relatime
│ ├─/sys/fs/cgroup cgroup2 cgroup2 rw,nosuid,nodev,noexec,relatime,nsdelegate,memory_recursiveprot
│ ├─/sys/fs/pstore pstore pstore rw,nosuid,nodev,noexec,relatime
│ ├─/sys/firmware/efi/efivars efivarfs efivarfs rw,nosuid,nodev,noexec,relatime
│ ├─/sys/fs/bpf bpf bpf rw,nosuid,nodev,noexec,relatime,mode=700
│ ├─/sys/kernel/debug debugfs debugfs rw,nosuid,nodev,noexec,relatime
│ │ └─/sys/kernel/debug/tracing tracefs tracefs rw,nosuid,nodev,noexec,relatime
│ ├─/sys/fs/fuse/connections fusectl fusectl rw,nosuid,nodev,noexec,relatime
│ └─/sys/kernel/config configfs configfs rw,nosuid,nodev,noexec,relatime
├─/nix/store /dev/sda:/dev/sdb:/dev/nvme0n1p2:/dev/nvme1n1[/nix/store] bcachefs ro,noatime,compression=lz4,foreground_target=ssd,background_target=hdd,promote_target=ssd
└─/boot /dev/nvme0n1p1 vfat rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro
Thank you! Please let me know if you have additional questions I can answer or ideas of things I can try!