nix-community / NixOS-WSL

NixOS on WSL(2) [maintainer=@nzbr]
Apache License 2.0
1.93k stars 120 forks source link

`/run/binfmt` error #552

Open 573 opened 2 months ago

573 commented 2 months ago

Bug description

nix develop and certain other commands always state:

error: … while setting up the build environment

  error: getting attributes of path '/run/binfmt': No such file or directory

To Reproduce

Steps to reproduce the behavior:

Run nix develop nixpkgs#hello

Logs

nixos-wsl-version

NixOS-WSL DEV_BUILD 20630a560fa658b1f4fc16e6ef2b6b3d6f8539f5 native

sudo systemctl status systemd-binfmt


× systemd-binfmt.service - Set Up Additional Binary Formats
Loaded: loaded (/etc/systemd/system/systemd-binfmt.service; enabled; preset: enabled)
Drop-In: /nix/store/cg1cvw5sailcmzb77980dbz9bvw36gwg-system-units/systemd-binfmt.service.d
└─overrides.conf
Active: failed (Result: exit-code) since Tue 2024-09-24 09:39:19 CEST; 1min 30s ago
Docs: man:systemd-binfmt.service(8)
man:binfmt.d(5)
https://docs.kernel.org/admin-guide/binfmt-misc.html
https://www.freedesktop.org/wiki/Software/systemd/APIFileSystems
Process: 20623 ExecStart=/nix/store/109w24xsb42fali6vh051vd2ghiphj4s-systemd-255.9/lib/systemd/systemd-binfmt (code=exited, status=1/FAILURE)
Main PID: 20623 (code=exited, status=1/FAILURE)
IP: 0B in, 0B out

Sep 24 09:39:19 DANIELKNB1 systemd-binfmt[20623]: /etc/binfmt.d/nixos.conf:1: Failed to add binary format 'WSLInterop': No such file or directory

> sudo systemctl status wsl-binfmt

○ wsl-binfmt.service - WSL binfmt restore Loaded: loaded (/run/systemd/generator.early/wsl-binfmt.service; generated) Active: inactive (dead) since Tue 2024-09-24 09:38:50 CEST; 9min ago Process: 20574 ExecStart=/bin/sh -c (echo -1 > /proc/sys/fs/binfmt_misc/WSLInterop-late) ; (echo :WSLInterop-late:M::MZ::/init:P > /proc/sys/fs/binfmt_misc/register) (code=exited, status=0/SUCCESS) Main PID: 20574 (code=exited, status=0/SUCCESS) IP: 0B in, 0B out

Sep 24 09:38:50 DANIELKNB1 sh[20575]: /nix/store/nmyaxjl9ihqf3d7b3i60x1mj000rvm35-bash-interactive-5.2p32/bin/sh: line 1: /proc/sys/fs/binfmt_misc/WSLInterop-late: Permission denied


## WSL version
<!-- Only WSL 2 version 2.0.0 or newer is supported -->

WSL-Version: 2.2.4.0 Kernelversion: 5.15.153.1-2 WSLg-Version: 1.0.61 MSRDC-Version: 1.2.5326 Direct3D-Version: 1.611.1-81528511 DXCore-Version: 10.0.26091.1-240325-1447.ge-release Windows-Version: 10.0.19045.4780



<!-- If your issue is related to the installation process, please include the SHA256 checksum of the tarball you used to install NixOS-WSL -->
573 commented 2 months ago

When following https://github.com/nix-community/NixOS-WSL/issues/292#issue-1904936552 for recovery it fails at step nix-channel --update:

unpacking channels... error: … while setting up the build environment

  error: getting attributes of path '/run/binfmt': No such file or directory

error: program '/nix/store/mi3yg271xmvsi8832vpl562hv1mh76gg-nix-2.20.8/bin/nix-env' failed with exit code 1

573 commented 2 months ago

Recovery also not possible:

   error: file 'nixos-wsl/modules' was not found in the Nix search path (add it using $NIX_PATH or -I)
   at «none»:0: (source not available)

All found here suggests nix-channel --update so full circle.

573 commented 2 months ago

Workaroud hack: sudo mkdir /run/binfmt and after that I repeated the original, my regular nixos-rebuild command, with the offending boot.binfmt.emulatedSystems = [ "aarch64-linux" ]; line factored out from my configuration.nix.

Marked hack because I still assume that I can log in to my existing install to do that.

The recovery steps still are not useable as long as I do not log in to the freshly built generation and revive via nix-channel --update, hopefully working this time. What might work beforehand was trying to built my config closure from the recovery env somehow, but I don't have time to check on that precautiously now.

573 commented 2 months ago

~-Also, sudo systemctl status wsl-binfmt still has~ ~...~ EDIT: nixos-rebuild switch mitigates last comment's issue.

SuperSandro2000 commented 2 months ago

What do you have set for wsl.interop.register and boot.binfmt.registrations?

573 commented 2 months ago

wsl.interop.register = true; and boot.binfmt.registrations probably only the default - did not set (only boot.binfmt.emulatedSystems = [ "aarch64-linux" ];).

This is what I have now (workaround as stated), not clear what belongs there with emulatedSystems = [ "aarch64-linux" ];:

nix-repl> :p nixosConfigurations.DANIELKNB1.config.boot.binfmt.emulatedSystems [ ] nix-repl> :p nixosConfigurations.DANIELKNB1.config.boot.binfmt.registrations { WSLInterop = { fixBinary = true; interpreter = "/init"; interpreterSandboxPath = null; magicOrExtension = "MZ"; mask = null; matchCredentials = false; offset = null; openBinary = false; preserveArgvZero = true; recognitionType = "magic"; wrapInterpreterInShell = false; }; }

573 commented 2 months ago

With

nix-repl> :p nixosConfigurations.DANIELKNB1.config.boot.binfmt.emulatedSystems [ "aarch64-linux" ]

nix-repl> :p nixosConfigurations.DANIELKNB1.config.boot.binfmt.registrations { WSLInterop = { fixBinary = true; interpreter = "/init"; interpreterSandboxPath = null; magicOrExtension = "MZ"; mask = null; matchCredentials = false; offset = null; openBinary = false; preserveArgvZero = true; recognitionType = "magic"; wrapInterpreterInShell = false"/nix/store/y1qhdk8ijklin832w0vl9ak7dmll0flh-qemu-aarch64-binfmt-P-x86_64-unknown-linux-musl/bin/qemu-aarch64-binfmt-P"; interpreterSandboxPath = "/nix/store/y1qhdk8ijklin832w0vl9ak7dmll0flh-qemu-aarch64-binfmt-P-x86_64-unknown-linux-musl"; magicOrExtension = "\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7\x00"; mask = "\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\x00\xff\xfe\xff\xff\xff"; matchCredentials = false; offset = null; openBinary = false; preserveArgvZero = true; recognitionType = "magic"; wrapInterpreterInShell = false; }; }

573 commented 2 months ago

building the system configuration... activating the configuration... setting up /run/booted-system... setting up /etc... setting up /bin... setting up /bin/login... setting up /sbin/init shim... reloading user units for nixos... restarting sysinit-reactivation.target reloading the following units: dbus.service restarting the following units: home-manager-nixos.service, home-manager-root.service the following new units were started: local-fs.target, sysinit-reactivation.target, systemd-timesyncd.service, systemd-tmpfiles-resetup.service, systemd-tmpfiles-setup.service warning: the following units failed: systemd-binfmt.service

× systemd-binfmt.service - Set Up Additional Binary Formats Loaded: loaded (/etc/systemd/system/systemd-binfmt.service; enabled; preset: enabled) Drop-In: /nix/store/k34v5qxbjw6braddfasf3591immcsfv5-system-units/systemd-binfmt.service.d └─overrides.conf Active: failed (Result: exit-code) since Wed 2024-10-02 12:08:19 CEST; 100ms ago Docs: man:systemd-binfmt.service(8) man:binfmt.d(5) https://docs.kernel.org/admin-guide/binfmt-misc.html https://www.freedesktop.org/wiki/Software/systemd/APIFileSystems Process: 148180 ExecStart=/nix/store/nswmyag3qi9ars0mxw5lp8zm0wv5zxld-systemd-255.9/lib/systemd/systemd-binfmt (code=exited, status=1/FAILURE) Main PID: 148180 (code=exited, status=1/FAILURE) IP: 0B in, 0B out

Oct 02 12:08:19 sis systemd-binfmt[148180]: /etc/binfmt.d/nixos.conf:1: Failed to add binary format 'WSLInterop': No such file or directory warning: error(s) occurred while switching to the new configuration

$ cat /etc/binfmt.d/nixos.conf :WSLInterop:M::MZ::/run/binfmt/WSLInterop:PF