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

Does running .exe's still work with the custom init system? #32

Closed
lithdew opened this issue May 21, 2021 · 5 comments · Fixed by #56
Closed

Does running .exe's still work with the custom init system? #32

lithdew opened this issue May 21, 2021 · 5 comments · Fixed by #56

Comments

@lithdew
Copy link

lithdew commented May 21, 2021

Apologies in advance for posting the question in the title as an issue (didn't notice anywhere I could post questions regarding this repo), though I'm looking to migrate from NixOS to Windows w/ WSL2 + NixOS and wanted to know if this is doable.

The use case is for writing Windows code in WSL2, and debugging them directly on Windows. As of now w/ NixOS, I use Wine to debug Windows code I write.

@sarahhodne
Copy link

It doesn't seem to work for me. The path isn't forwarded like usual, but even running with the full path I don't get any output from running .exes:

➜ /mnt/c/Windows/System32/ipconfig.exe

➜

Also, if anyone else is having issues with /mnt/c not automounting, try adding tzdata to your environment.systemPackages and this to your /etc/wsl.conf (inside the NixOS FS):

[automount]
enabled = true
options = "metadata,uid=1000,gid=100,noauto,x-systemd.automount"

@sarahhodne
Copy link

I got it to work, you need to forward some environment variables through syschdemd.sh, something like this seems to work for me:

# ...this is replacing the very last line of syschdemd.sh, the `exec $sw/nsenter...`
exportCmd="export WSLENV=\"$WSLENV\"; export WT_SESSION=\"$WT_SESSION\"; export WT_PROFILE_ID=\"$WT_PROFILE_ID\"; export WSL_INTEROP=\"$WSL_INTEROP\""
exec $sw/nsenter -t $(< /run/systemd.pid) -p -m -- $sw/machinectl -q --uid=@defaultUser@ shell .host /bin/sh -c "cd \"$PWD\"; $exportCmd; exec $cmd"

There's probably some nicer way of doing it, though.

@lithdew
Copy link
Author

lithdew commented May 27, 2021

I got it to work, you need to forward some environment variables through syschdemd.sh, something like this seems to work for me:

# ...this is replacing the very last line of syschdemd.sh, the `exec $sw/nsenter...`
exportCmd="export WSLENV=\"$WSLENV\"; export WT_SESSION=\"$WT_SESSION\"; export WT_PROFILE_ID=\"$WT_PROFILE_ID\"; export WSL_INTEROP=\"$WSL_INTEROP\""
exec $sw/nsenter -t $(< /run/systemd.pid) -p -m -- $sw/machinectl -q --uid=@defaultUser@ shell .host /bin/sh -c "cd \"$PWD\"; $exportCmd; exec $cmd"

There's probably some nicer way of doing it, though.

Awesome that you got it working though! I'll have a try then after migrating to Windows. Thanks!

vlaci pushed a commit to vlaci/NixOS-WSL that referenced this issue Jul 26, 2021
Changed machinectl to systemd-run to have finer grained control on how the user session is initiated. It has the following advantages:
* Direct support for specifying working directory
* Can be passed arbitrary directives understood by Systemd (see `systemd.exec(5)` for details). It is used to pass environment variables.
* Returns proper exit status of internal commands (machinectl swallows it)

By passing these variables WSLg and windows executables now just work out of the box. Hopefully any new environment variables introduced in the WSL ecosystem in the future will just work as well.

Fixes nix-community#32
@adrian-gierakowski
Copy link

I got it to work, you need to forward some environment variables through syschdemd.sh, something like this seems to work for me:

# ...this is replacing the very last line of syschdemd.sh, the `exec $sw/nsenter...`
exportCmd="export WSLENV=\"$WSLENV\"; export WT_SESSION=\"$WT_SESSION\"; export WT_PROFILE_ID=\"$WT_PROFILE_ID\"; export WSL_INTEROP=\"$WSL_INTEROP\""
exec $sw/nsenter -t $(< /run/systemd.pid) -p -m -- $sw/machinectl -q --uid=@defaultUser@ shell .host /bin/sh -c "cd \"$PWD\"; $exportCmd; exec $cmd"

after replacing the last line of syschdemd.sh with the above and running sudo nixos-rebuild switch I cannot boot into the system. @sarahhodne @Trundle: any idea how I could recover from this? Thanks!

@sarahhodne
Copy link

I don't really use WSL anymore, so I'm not sure, but you may be able to use wsl --export to export your filesystem into a .tar, extract that and edit the file, and then re-pack and wsl --import it again… but there might be an easier way too, but I can't really try things since I don't have a WSL (or even Windows) environment around anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants