Code Monkey home page Code Monkey logo

nixos-wsl's Introduction

NixOS-WSL
Matrix Chat nixpkgs 23.11 Downloads

Modules for running NixOS on the Windows Subsystem for Linux

Documentation is available here

Quick Start

  1. Enable WSL if you haven't done already:
  • wsl --install --no-distribution
  1. Download nixos-wsl.tar.gz from the latest release.

  2. Import the tarball into WSL:

  • wsl --import NixOS $env:USERPROFILE\NixOS\ nixos-wsl.tar.gz
  1. You can now run NixOS:
  • wsl -d NixOS

For more detailed instructions, refer to the documentation.

License

Apache License, Version 2.0. See LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html for details.

nixos-wsl's People

Contributors

abehidek avatar ajaxbits avatar ajgrf avatar andoriyu avatar atry avatar dev-null-undefined avatar erikmcclure avatar fruitiex avatar github-actions[bot] avatar hschaeidt avatar jamiemagee avatar jojoatxgme avatar k900 avatar kovirobi avatar mausch avatar mprasil avatar noamraph avatar nzbr avatar philippheuer avatar prince213 avatar psmf avatar renovate[bot] avatar scottwillmoore avatar supersandro2000 avatar teofilc avatar terlar avatar trundle avatar veehaitch avatar willbush avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nixos-wsl's Issues

Mount windows drives with metadata option

Hi, first of all: Awesome work! :)

To use git and some other programs from inside a WSL distro and access the filesystem "outside", which is (probably in most cases?) an NTFS formated drive, one needs to instruct WSL to mount the Windows drives with the metadata option.

This is done via /etc/wsl.conf (inside the disto):

[automount]
options = "metadata"

Therefore I've added

  environment.etc."wsl.conf" = {
    text = ''
      [automount]
      options = "metadata"
           '';
  };

to /etc/nixos/configuration.nix.

I figured this might be useful for some.
Fixes issues such as fatal: could not set 'core.filemode' to 'false' messages when using git clone or git init.

Reference: https://askubuntu.com/a/1242671/635446

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

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.

using with rdp and xmonad

I have the following configuration.nix based off this repo which lets me log into a desktop environment via rdp and its great to have gotten that working. However it uses kde / plasma5 as the desktop manager but I prefer to just use xmonad.

I run nixos natively on my laptop and my config file as far as server goes is very similar to below except the commented our xmonad lines are uncommented and I get a plasma login prompt but it logs me into an xmonad environment by default.

If I uncomment those lines here rdp just kind of hangs after the rdp login prompt on a blue screen and does nothing

I think my issues comes down to either or both of these lines:

services.xserver.displayManager.defaultSession = "none+xmonad";
`services.xrdp.defaultWindowManager = "startplasma-x11";

any ideas what the values of these settings should be to allow me to get xmonad spun up by default on login via rdp?

{ lib, pkgs, config, modulesPath, ... }:

with lib;
let
  defaultUser = "nixos";
  syschdemd = import ./syschdemd.nix { inherit lib pkgs config defaultUser; };
in
{
  imports = [
    "${modulesPath}/profiles/minimal.nix"
  ];

  # WSL is closer to a container than anything else
  boot.isContainer = true;

  environment.noXlibs = false;
  environment.etc.hosts.enable = false;
  environment.etc."resolv.conf".enable = false;

  networking.dhcpcd.enable = false;

  users.users.${defaultUser} = {
    isNormalUser = true;
    extraGroups = [ "wheel" ];
  };

  users.users.root = {
    shell = "${syschdemd}/bin/syschdemd";
    # Otherwise WSL fails to login as root with "initgroups failed 5"
    extraGroups = [ "root" ];
  };

  users.users.mark = {
    isNormalUser = true;
    home = "/home/mark";
    extraGroups = ["wheel" "networkmanager"];
  };
  security.sudo.wheelNeedsPassword = false;

  # Disable systemd units that don't make sense on WSL
  systemd.services."serial-getty@ttyS0".enable = false;
  systemd.services."serial-getty@hvc0".enable = false;
  systemd.services."getty@tty1".enable = false;
  systemd.services."autovt@".enable = false;

  systemd.services.firewall.enable = false;
  systemd.services.systemd-resolved.enable = false;
  systemd.services.systemd-udevd.enable = false;

  # Don't allow emergency mode, because we don't have a console.
  systemd.enableEmergencyMode = false;

  services.xserver.enable = true;
  services.xserver.layout = "us";
  #services.xserver.windowManager = {
   # xmonad.enable = true;
    #xmonad.enableContribAndExtras = true;
   # xmonad.extraPackages = hpkgs: [
    #  hpkgs.xmonad-contrib
     # hpkgs.xmonad-extras
     # hpkgs.xmonad
    #];
  #};

  services.xserver.displayManager.sddm.enable = true;
  #services.xserver.displayManager.defaultSession = "none+xmonad";
  services.xserver.desktopManager.plasma5.enable = true;

  services.xrdp.enable = true;
  services.xrdp.defaultWindowManager = "startplasma-x11";
  networking.firewall.allowedTCPPorts = [ 3389 ];
}

21.11-d89f18a1 fails after initial import with `nsenter: failed to parse pid: '-p'`

This is on a Dell Latitude 7320 with Windows 11 fresh from the box.

Ubuntu on WSL works fine.

Import goes fine.
First run gives An error occurred mounting one of your file systems. Please run 'dmesg' for more details. but continues installation.
Second run exits with An error occurred mounting one of your file systems. Please run 'dmesg' for more details. nsenter: failed to parse pid: '-p'.

I'll see if I can troubleshoot what's going on. I suspect it may be behind on updates.
I'll update it and report back.
If the updates fix it, I'll close the issue and hopefully somebody else who runs into this issue is helped by this.

PS C:\Users\erik.smit.ALETHO\Downloads> wsl --unregister NixOS
Unregistering...
PS C:\Users\erik.smit.ALETHO\Downloads> wsl --import NixOS .\NixOS\ nixos-wsl-installer.tar.gz --version 2
PS C:\Users\erik.smit.ALETHO\Downloads> wsl -d NixOS
An error occurred mounting one of your file systems. Please run 'dmesg' for more details.
Unpacking root file system...
 184MiB 0:00:15 [11.8MiB/s] [========================================================================================================================================================================================================================================>] 100%
Activating nix configuration...
Copying /usr/share/applications
Copying /usr/share/icons
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
        LANGUAGE = (unset),
        LC_ALL = (unset),
        LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
setting up /etc...
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
        LANGUAGE = (unset),
        LC_ALL = (unset),
        LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
Cleaning up installer files...
finding garbage collector roots...
removing stale link from '/nix/var/nix/gcroots/auto/6yfbrv8wfkyl40wq6827lamr9m29z7wg' to '/build/nix/var/nix/profiles/per-user/root/channels-1-link'
removing stale link from '/nix/var/nix/gcroots/auto/zxi8v969la5n36bg7gs016wgcif4qjhp' to '/build/nix/var/nix/profiles/system-1-link'
deleting garbage...
deleting '/nix/store/svw89j47vr3h792f75nfgh5x9s48rn0w-pv-1.6.20'
deleting '/nix/store/m0qmllywgy9wl4ia7vvpz7p53kzxv681-busybox-1.34.1'
deleting '/nix/store/m7cghw288wks5s5mkxpg1k3h5ivlg1ch-installer.sh'
deleting '/nix/store/8hm7r6m8y0fjrb4qjv8gs1ba04g51166-tarball'
deleting '/nix/store/y608sw04xdqhha69raxpj2rsk007n7wf-wsl-prepare'
deleting '/nix/store/4ryxif8fmjb362ry8ylx29hsxp0zgpax-source'
deleting '/nix/store/trash'
deleting unused links...
note: currently hard linking saves -0.00 MiB
6 store paths deleted, 185.42 MiB freed
Optimizing store...
5.05 MiB freed by hard-linking 3499 files
Starting systemd...
PS C:\Users\erik.smit.ALETHO\Downloads> wsl -d NixOS
An error occurred mounting one of your file systems. Please run 'dmesg' for more details.
nsenter: failed to parse pid: '-p'
PS C:\Users\erik.smit.ALETHO\Downloads> wsl --unregister NixOS
Unregistering...
PS C:\Users\erik.smit.ALETHO\Downloads> wsl --import NixOS .\NixOS\ nixos-wsl-installer.tar.gz --version 2
PS C:\Users\erik.smit.ALETHO\Downloads> wsl -d NixOS
An error occurred mounting one of your file systems. Please run 'dmesg' for more details.
Unpacking root file system...
 184MiB 0:00:12 [14.9MiB/s] [========================================================================================================================================================================================================================================>] 100%
Activating nix configuration...
Copying /usr/share/applications
Copying /usr/share/icons
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
        LANGUAGE = (unset),
        LC_ALL = (unset),
        LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
setting up /etc...
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
        LANGUAGE = (unset),
        LC_ALL = (unset),
        LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
Cleaning up installer files...
finding garbage collector roots...
removing stale link from '/nix/var/nix/gcroots/auto/6yfbrv8wfkyl40wq6827lamr9m29z7wg' to '/build/nix/var/nix/profiles/per-user/root/channels-1-link'
removing stale link from '/nix/var/nix/gcroots/auto/zxi8v969la5n36bg7gs016wgcif4qjhp' to '/build/nix/var/nix/profiles/system-1-link'
deleting garbage...
deleting '/nix/store/svw89j47vr3h792f75nfgh5x9s48rn0w-pv-1.6.20'
deleting '/nix/store/m0qmllywgy9wl4ia7vvpz7p53kzxv681-busybox-1.34.1'
deleting '/nix/store/m7cghw288wks5s5mkxpg1k3h5ivlg1ch-installer.sh'
deleting '/nix/store/8hm7r6m8y0fjrb4qjv8gs1ba04g51166-tarball'
deleting '/nix/store/y608sw04xdqhha69raxpj2rsk007n7wf-wsl-prepare'
deleting '/nix/store/4ryxif8fmjb362ry8ylx29hsxp0zgpax-source'
deleting '/nix/store/trash'
deleting unused links...
note: currently hard linking saves -0.00 MiB
6 store paths deleted, 185.42 MiB freed
Optimizing store...
5.05 MiB freed by hard-linking 3499 files
Starting systemd...
PS C:\Users\erik.smit.ALETHO\Downloads> wsl -d NixOS
An error occurred mounting one of your file systems. Please run 'dmesg' for more details.
nsenter: failed to parse pid: '-p'
PS C:\Users\erik.smit.ALETHO\Downloads>

Man pages doesn't work

When I try to execute the command man man, man says that there is no manual entry for man.

I tried to add this line in my config:

pkgs.manpages

But this didn't work.

Is this a bug ?

Mount error during activation

after running /nix/var/nix/profiles/system/activate this error appears, running nixos-rebuild with any hardware configuration spits the same error, I don't know how to start debugging this.

error:

setting up /etc...
mount: /: mount point not mounted or bad option.
Activation script snippet 'specialfs' failed (32)

lsblk:

NAME MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda    8:0    0  256G  0 disk
sdb    8:16   0  256G  0 disk /
sdc    8:32   0  256G  0 disk

Update README/Documentation

The documentation should be updated. It currently mentions manual steps after installing, that are no longer required.
Details on how to build and use the installer tarball should be added

How to `nixos-rebuild` with edited `configuration.nix` ?

Hi, I'm trying to switch to my own configuration.nix, but failed with following error:

You must set the option ‘boot.loader.grub.devices’ or 'boot.loader.grub.mirroredBoots' to make the system bootable.

(after nixos-generate-config)

image

Is there any suggestion?

Package for Windows Store

It would be nice to just have this available on the Windows Store. It's more or less just a matter of making a manifest and emailing the right people.

See: github.com/microsoft/WSL-DistroLauncher

unable to access root super user:

Hello @Trundle ,
I'm unable to access root in nixos-wsl using su? I'm just wondering if that's normal, and not an issue?
Anyways, I've been able to get by with running sudo commands ..., which works, but this way does not seem secure.

If you could clarify this, thanks in advance for the help!

Machinectl takes over tty

Hello, I'm trying to use GPG but it doesn't work because pinentry cannot open a tty.

$ echo GETPIN | pinentry -T /dev/pts/0
No $DBUS_SESSION_BUS_ADDRESS found, falling back to curses
OK Pleased to meet you
S ERROR gnome3.open_tty_for_read 83918849
ERR 83918849 Permission denied <Pinentry>

It works just fine if I start a new tty with script /dev/null:

$ script /dev/null
$ tty
/dev/pts/1
$ echo GETPIN | pinentry -T /dev/pts/1

Also there should be a way to have a systemd user session running, at least for dbus support. That way, graphical pinentry (GTK3) would work which is better.

/bin/sh: line 1: cd: /root: Permission denied

I imported a fresh NixOS using:

wsl --import NixOS .\NixOS\ .\Downloads\nixos-wsl-installer-fixed.tar.gz --version 2

When I start it I get:

wsl -d NixOS
/bin/sh: line 1: cd: /root: Permission denied

[nixos@nixos:~]$

(Also /mnt/* is not mounted.)

After restarting the distro it seems to work again:

> wsl -t NixOS
> wsl -d NixOS
Copying /usr/share/applications
Copying /usr/share/icons
setting up /etc...

[nixos@myhostname:/mnt/c/Users/michas]$

GPU / DirectML support not working

Bug description

Recent versions of WSL 2 support DirectML, a machine-learning GPU accelerated pipeline. NixOS-WSL will require a few changes in order to support GPU detection/access. I'm not familiar with all the specifics, but I'll list my findings in this issue.

To Reproduce

Steps to reproduce the behavior:

~
❯ nix-shell -p conda

~ via ❄️  impure (shell)
❯ conda-shell
/etc/profile: line 26: /home/shayne/.conda/etc/profile.d/conda.sh: No such file or directory
bash: /home/shayne/.conda/etc/profile.d/conda.sh: No such file or directory

~ via ❄️  impure (shell)
❯ conda-install
...omitted
installation finished.

~ via ❄️  impure (shell)
❯ conda create --name directml python=3.6
Collecting package metadata: done
Solving environment: done
...omitted

~ via ❄️  impure (shell)
❯ conda activate directml

~ via ❄️  impure (shell) via 🅒  directml
❯ pip install tensorflow-directml
Collecting tensorflow-directml
  Using cached tensorflow_directml-1.15.7-cp36-cp36m-manylinux2010_x86_64.whl (109.7 MB)
...omitted

~ via ❄️  impure (shell) via 🅒  directml
❯ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/host/usr/lib/wsl/lib

~ via ❄️  impure (shell) via 🅒  directml
❯ python
Python 3.6.13 |Anaconda, Inc.| (default, Jun  4 2021, 14:25:59)
[GCC 7.5.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow.compat.v1 as tf
>>> tf.enable_eager_execution(tf.ConfigProto(log_device_placement=True))
>>> print(tf.add([1.0, 2.0], [3.0, 4.0]))
2022-05-21 12:05:36.141445: I tensorflow/stream_executor/platform/default/dso_loader.cc:97] Successfully opened dynamic library libdirectml.0de2b4431c6572ee74152a7ee0cd3fb1534e4a95.so
2022-05-21 12:05:36.141533: I tensorflow/stream_executor/platform/default/dso_loader.cc:97] Successfully opened dynamic library libdxcore.so
2022-05-21 12:05:36.154918: I tensorflow/stream_executor/platform/default/dso_loader.cc:97] Successfully opened dynamic library libd3d12.so
2022-05-21 12:05:36.278336: I tensorflow/core/common_runtime/dml/dml_device_cache.cc:250] DirectML device enumeration: found 0 compatible adapters.
2022-05-21 12:05:36.278603: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2022-05-21 12:05:36.281742: I tensorflow/core/common_runtime/eager/execute.cc:571] Executing op Add in device /job:localhost/replica:0/task:0/device:CPU:0
tf.Tensor([4. 6.], shape=(2,), dtype=float32)
>>>

Two things to note:

  1. You must add /host/usr/lib/wsl/lib to the LD_LIBRARY_PATH or the dynamic libraries fails to load
  2. The device enumeration reports found 0 compatible adapters.

Expected behavior

Here's output from running the same tensorflow execution under Ubuntu 20.04

2022-05-21 12:06:28.834960: I tensorflow/stream_executor/platform/default/dso_loader.cc:97] Successfully opened dynamic library libdirectml.0de2b4431c6572ee74152a7ee0cd3fb1534e4a95.so
2022-05-21 12:06:28.835225: I tensorflow/stream_executor/platform/default/dso_loader.cc:97] Successfully opened dynamic library libdxcore.so
2022-05-21 12:06:28.841276: I tensorflow/stream_executor/platform/default/dso_loader.cc:97] Successfully opened dynamic library libd3d12.so
2022-05-21 12:06:30.835907: I tensorflow/core/common_runtime/dml/dml_device_cache.cc:250] DirectML device enumeration: found 1 compatible adapters.
2022-05-21 12:06:30.836634: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2022-05-21 12:06:30.837890: I tensorflow/core/common_runtime/dml/dml_device_cache.cc:186] DirectML: creating device on adapter 0 (NVIDIA GeForce RTX 3090
2022-05-21 12:06:31.451911: I tensorflow/core/common_runtime/eager/execute.cc:571] Executing op Add in device /job:localhost/replica:0/task:0/device:DML:0
tf.Tensor([4. 6.], shape=(2,), dtype=float32)

Trying to run "code <directory>" in terminal gives "Error: Cannot find module '<directory>'"

Bug description

When I try to open a directory with code <directory>, I get Error: Cannot find module '<directory>'. This happens no matter what directory I try to open, whether it is in the WSL filesystem or the Windows filesystem.

To Reproduce

Steps to reproduce the behavior:

  1. Open a NixOS-WSL terminal (NOT the VSCode integrated terminal, since this uses a different binary for code)
  2. Navigate to any directory and type code .
  3. Get error

Expected behavior

Should open the folder in VSCode Remote

Logs

My home-manager settings can be seen at https://github.com/kfish610/wsl-dots/blob/main/home.nix

neofetch:

kfish@KDESKTOP
--------------
OS: NixOS 22.05 (Quokka) on Windows x86_64
Kernel: 5.10.102.1-microsoft-standard-WSL2
Uptime: 16 mins
Packages: 198 (nix-system), 4327 (nix-user), 71 (nix-default)
Shell: zsh 5.8.1
Terminal: Windows Terminal
CPU: AMD Ryzen 5 3600 (12) @ 3.600GHz
GPU: Microsoft Corporation Device 008e
Memory: 606MiB / 7910MiB

code $HOME

node:internal/modules/cjs/loader:990
  throw err;
  ^

Error: Cannot find module '\\wsl.localhost\NixOS\home\kfish'
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:987:15)
    at Module._load (node:internal/modules/cjs/loader:832:27)
    at Function.c._load (node:electron/js2c/asar_bundle:5:13343)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

VSCODE_WSL_DEBUG_INFO=true code $HOME (click expand):

Expand (this one's long)
+ COMMIT=c3511e6c69bb39013c4a4b7b9566ec1ca73fc4d5
+ APP_NAME=code
+ QUALITY=stable
+ NAME=Code
+ SERVERDATAFOLDER=.vscode-server
++++ realpath '/mnt/c/Users/kfish/AppData/Local/Programs/Microsoft VS Code/bin/code'
+++ dirname '/mnt/c/Users/kfish/AppData/Local/Programs/Microsoft VS Code/bin/code'
++ dirname '/mnt/c/Users/kfish/AppData/Local/Programs/Microsoft VS Code/bin'
+ VSCODE_PATH='/mnt/c/Users/kfish/AppData/Local/Programs/Microsoft VS Code'
+ ELECTRON='/mnt/c/Users/kfish/AppData/Local/Programs/Microsoft VS Code/Code.exe'
+ IN_WSL=false
+ '[' -n NixOS ']'
+ IN_WSL=true
+ '[' true = true ']'
+ export WSLENV=ELECTRON_RUN_AS_NODE/w:WT_SESSION::WT_PROFILE_ID
+ WSLENV=ELECTRON_RUN_AS_NODE/w:WT_SESSION::WT_PROFILE_ID
++ wslpath -m '/mnt/c/Users/kfish/AppData/Local/Programs/Microsoft VS Code/resources/app/out/cli.js'
+ CLI='C:/Users/kfish/AppData/Local/Programs/Microsoft VS Code/resources/app/out/cli.js'
+ WSL_EXT_ID=ms-vscode-remote.remote-wsl
+ ELECTRON_RUN_AS_NODE=1
+ '/mnt/c/Users/kfish/AppData/Local/Programs/Microsoft VS Code/Code.exe' 'C:/Users/kfish/AppData/Local/Programs/Microsoft VS Code/resources/app/out/cli.js' --ms-enable-electron-run-as-node --locate-extension ms-vscode-remote.remote-wsl
++ cat /tmp/remote-wsl-loc.txt
+ WSL_EXT_WLOC=
+ '[' -n '' ']'
+ ELECTRON_RUN_AS_NODE=1
+ '/mnt/c/Users/kfish/AppData/Local/Programs/Microsoft VS Code/Code.exe' 'C:/Users/kfish/AppData/Local/Programs/Microsoft VS Code/resources/app/out/cli.js' --ms-enable-electron-run-as-node .
node:internal/modules/cjs/loader:990
  throw err;
  ^

Error: Cannot find module '\\wsl.localhost\NixOS\home\kfish'
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:987:15)
    at Module._load (node:internal/modules/cjs/loader:832:27)
    at Function.c._load (node:electron/js2c/asar_bundle:5:13343)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}
+ exit 1

For what it's worth, I also tested this in the default Ubuntu installation for WSL, and it worked. The debug output is:
VSCODE_WSL_DEBUG_INFO=true code $HOME (click expand):

Expand (Ubuntu)
+ COMMIT=c3511e6c69bb39013c4a4b7b9566ec1ca73fc4d5
+ APP_NAME=code
+ QUALITY=stable
+ NAME=Code
+ SERVERDATAFOLDER=.vscode-server
+ realpath /mnt/c/Users/kfish/AppData/Local/Programs/Microsoft VS Code/bin/code
+ dirname /mnt/c/Users/kfish/AppData/Local/Programs/Microsoft VS Code/bin/code
+ dirname /mnt/c/Users/kfish/AppData/Local/Programs/Microsoft VS Code/bin
+ VSCODE_PATH=/mnt/c/Users/kfish/AppData/Local/Programs/Microsoft VS Code
+ ELECTRON=/mnt/c/Users/kfish/AppData/Local/Programs/Microsoft VS Code/Code.exe
+ IN_WSL=false
+ [ -n Ubuntu ]
+ IN_WSL=true
+ [ true = true ]
+ export WSLENV=ELECTRON_RUN_AS_NODE/w:WT_SESSION::WT_PROFILE_ID
+ wslpath -m /mnt/c/Users/kfish/AppData/Local/Programs/Microsoft VS Code/resources/app/out/cli.js
+ CLI=C:/Users/kfish/AppData/Local/Programs/Microsoft VS Code/resources/app/out/cli.js
+ WSL_EXT_ID=ms-vscode-remote.remote-wsl
+ ELECTRON_RUN_AS_NODE=1 /mnt/c/Users/kfish/AppData/Local/Programs/Microsoft VS Code/Code.exe C:/Users/kfish/AppData/Local/Programs/Microsoft VS Code/resources/app/out/cli.js --ms-enable-electron-run-as-node --locate-extension ms-vscode-remote.remote-wsl
+ cat /tmp/remote-wsl-loc.txt
+ WSL_EXT_WLOC=c:\Users\kfish\.vscode\extensions\ms-vscode-remote.remote-wsl-0.66.3
+ [ -n c:\Users\kfish\.vscode\extensions\ms-vscode-remote.remote-wsl-0.66.3 ]
+ wslpath -u c:\Users\kfish\.vscode\extensions\ms-vscode-remote.remote-wsl-0.66.3
+ WSL_CODE=/mnt/c/Users/kfish/.vscode/extensions/ms-vscode-remote.remote-wsl-0.66.3/scripts/wslCode.sh
+ /mnt/c/Users/kfish/.vscode/extensions/ms-vscode-remote.remote-wsl-0.66.3/scripts/wslCode.sh c3511e6c69bb39013c4a4b7b9566ec1ca73fc4d5 stable /mnt/c/Users/kfish/AppData/Local/Programs/Microsoft VS Code/Code.exe code .vscode-server /home/kfish
+ [ -z .vscode-server ]
+ [ .vscode-server = .vscode-insiders ]
+ [ ! -t 0 ]
+ VSCODE_REMOTE_BIN=/home/kfish/.vscode-server/bin
+ AUTHORITY=wsl+default
+ [ Ubuntu ]
+ AUTHORITY=wsl+Ubuntu
+ dirname /mnt/c/Users/kfish/.vscode/extensions/ms-vscode-remote.remote-wsl-0.66.3/scripts/wslCode.sh
+ /mnt/c/Users/kfish/.vscode/extensions/ms-vscode-remote.remote-wsl-0.66.3/scripts/wslDownload.sh c3511e6c69bb39013c4a4b7b9566ec1ca73fc4d5 stable /home/kfish/.vscode-server/bin
+ [ ! -d /home/kfish/.vscode-server/bin/c3511e6c69bb39013c4a4b7b9566ec1ca73fc4d5 ]
+ RC=0
+ [ 0 -ne 0 ]
+ mktemp /tmp/vscode-distro-env.XXXXXX
+ STORED_ENV=/tmp/vscode-distro-env.WD3oQH
+ env
+ dirname /mnt/c/Users/kfish/.vscode/extensions/ms-vscode-remote.remote-wsl-0.66.3/scripts/wslCode.sh
+ VSCODE_CLIENT_COMMAND=/mnt/c/Users/kfish/AppData/Local/Programs/Microsoft VS Code/Code.exe VSCODE_CLIENT_COMMAND_CWD=/mnt/c/Users/kfish/.vscode/extensions/ms-vscode-remote.remote-wsl-0.66.3/scripts VSCODE_CLI_AUTHORITY=wsl+Ubuntu VSCODE_CLI_REMOTE_ENV=/tmp/vscode-distro-env.WD3oQH VSCODE_STDIN_FILE_PATH= WSLENV=VSCODE_CLI_REMOTE_ENV/w:ELECTRON_RUN_AS_NODE/w:WT_SESSION::WT_PROFILE_ID /home/kfish/.vscode-server/bin/c3511e6c69bb39013c4a4b7b9566ec1ca73fc4d5/bin/remote-cli/code /home/kfish
+ exit 0

As far as I can tell, the place it breaks is where it tries to locate the remote extension. If you isolate the line, you can run (the exact directory will vary slightly by your username):

> export WSLENV="ELECTRON_RUN_AS_NODE/w:$WSLENV"
> ELECTRON_RUN_AS_NODE=1 "/mnt/c/Users/kfish/AppData/Local/Programs/Microsoft VS Code/Code.exe" "C:/Users/kfish/AppData/Local/Programs/Microsoft VS Code/resources/app/out/cli.js" --ms-enable-electron-run-as-node --locate-extension ms-vscode-remote.remote-wsl
cli.js: bad option: --locate-extension

This is supposed to output the folder of the VSCode remote extension (and on Ubuntu the exact same command does output /mnt/c/Users/kfish/.vscode/extensions/ms-vscode-remote.remote-wsl-0.66.3/ for me), but instead it gives that weird error. I have absolutely no clue what makes NixOS-WSL different enough to cause that error, but it does only happen on NixOS.

The import fails with Unspecified error

Trying to wsl --import the resulting tar.gz fails with "Unspecified error". Exporting/importing Ubuntu-20.04 from the Windows store works with no issues. Is there any way to diagnose further?

Default distribution comes without networking enabled

Bit of a catch-22, as I can't rebuild to enable networking, and I can't have networking without rebuilding.

Maybe having at least dhcpcd or dhclient will be good, or the networking.dhcpcd.enable = true; option as default?

Systemd user process

Hi, this seems like a great project. I've run into an issue where the systemd user manager doesn't appear to be started (meaning that systemd user processes can't run).

I'm trying to track down why this is occurring (may just be due to lazy evaluation tbh).

Specific problem:

nixos@Shale > systemctl status --user
Failed to connect to bus: No such file or directory
nixos@Shale /m/c/U/Cjen0 [255]> ps aux | grep systemd
root         1  0.1  0.0  22280 10676 ?        Ss   12:18   0:00 systemd
root        21  0.0  0.0  36996 11644 ?        Ss   12:18   0:00 /nix/store/q6ylicsava582g55mdx0788yg2fib7js-systemd-246.6/lib/systemd/systemd-journald
root        48  0.0  0.0  16568  5904 ?        Ss   12:18   0:00 /nix/store/q6ylicsava582g55mdx0788yg2fib7js-systemd-246.6/lib/systemd/systemd-logind
message+    50  0.0  0.0   6288  3504 ?        Ss   12:18   0:00 /nix/store/4013xmv3pjddrdgb6vkncb4iqlyij8pq-dbus-1.12.20/bin/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation --syslog-only
nixos      365  0.0  0.0 223440  2260 pts/0    S+   12:19   0:00 /nix/store/3mx947xcmsyk79izqc8ifv31qafp80pc-gnugrep-3.6/bin/grep --color=auto systemd

While the equivalent run on a server:

cjen1@____:~$ ps aux | grep systemd
root         1  0.0  0.0 226592  7784 ?        Ss    2020  22:15 /lib/systemd/systemd --system --deserialize 23
root      1243  0.0  0.0  65628  5484 ?        Ss    2020   3:19 /lib/systemd/systemd-logind
message+  1261  0.0  0.0 154432  3644 ?        Ss    2020  10:09 /usr/bin/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation --syslog-only
cjen1     4893  0.0  0.0  14436  1072 pts/0    S+   12:20   0:00 grep systemd
cjen1    10568  0.0  0.0  39476  3748 ?        Ss   Feb16   0:00 /usr/bin/dbus-daemon --session --address=systemd: --nofork --nopidfile --systemd-activation --syslog-only
cjen1    12768  0.0  0.0  77332  6840 ?        Ss   Feb15   0:45 /lib/systemd/systemd --user

I have looked into what should be starting that systemd user process but haven't been able to make much headway there...

nsenter: failed to parse pid: '-p'

Bug description

I installed it but I cannot start it, because `nsenter: failed to parse pid: '-p'.

To Reproduce

  1. Get the installer and follow readme instructions (see terminal output below)

Include relevant console logs

PS C:\Users\bcr88\Downloads> wsl --import NixOS ..\NixOS\ .\nixos-wsl-installer.tar.gz --version 2
PS C:\Users\bcr88\Downloads> wsl -d NixOS
Unpacking root file system...
 184MiB 0:00:07 [24.6MiB/s] [=================================================================================================================================================================>] 100%
Activating nix configuration...
Copying /usr/share/applications
Copying /usr/share/icons
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
        LANGUAGE = (unset),
        LC_ALL = (unset),
        LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
setting up /etc...
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
        LANGUAGE = (unset),
        LC_ALL = (unset),
        LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
Cleaning up installer files...
finding garbage collector roots...
removing stale link from '/nix/var/nix/gcroots/auto/6yfbrv8wfkyl40wq6827lamr9m29z7wg' to '/build/nix/var/nix/profiles/per-user/root/channels-1-link'
removing stale link from '/nix/var/nix/gcroots/auto/zxi8v969la5n36bg7gs016wgcif4qjhp' to '/build/nix/var/nix/profiles/system-1-link'
deleting garbage...
deleting '/nix/store/svw89j47vr3h792f75nfgh5x9s48rn0w-pv-1.6.20'
deleting '/nix/store/m0qmllywgy9wl4ia7vvpz7p53kzxv681-busybox-1.34.1'
deleting '/nix/store/m7cghw288wks5s5mkxpg1k3h5ivlg1ch-installer.sh'
deleting '/nix/store/8hm7r6m8y0fjrb4qjv8gs1ba04g51166-tarball'
deleting '/nix/store/y608sw04xdqhha69raxpj2rsk007n7wf-wsl-prepare'
deleting '/nix/store/4ryxif8fmjb362ry8ylx29hsxp0zgpax-source'
deleting unused links...
note: currently hard linking saves -0.00 MiB
6 store paths deleted, 185.42 MiB freed
5.05 MiB freed by hard-linking 3499 files
Starting systemd...
PS C:\Users\bcr88\Downloads> wsl -d NixOS
nsenter: failed to parse pid: '-p'

ec7667a682ac2a796774d9357210438359c1f19df8755fb72ed730305612e29a nixos-wsl-installer.tar.gz

Upgrading NixOS to 21.05

Has anybody successfully been able to update their NixOS WSL installation to the 21.05 channel?

As I understand it, the upgrade process looks like this:

sudo nix-channel --add https://nixos.org/channels/nixos-21.05 nixos
sudo nixos-rebuild switch

Unfortunately, I run into a WSL-specific issue when building packages here:

Time
  Clock
    resolution
      getCurrentTime:                                                             FAIL (0.16s)
        test/main/Test/Clock/Resolution.hs:55:
        resolution
        expected: 0.000000001s
         but got: 0.0000001s
      taiClock:                                                                   FAIL (0.14s)
        test/main/Test/Clock/Resolution.hs:55:
        resolution
        expected: 0.000000001s
         but got: 0.0000001s

As noted on the linked issue, the package in question does build, but I don't see a way for nixos-rebuild to move past the test failure.

Is there a way to work around this?

I'm also guessing that one solution is to build a system tarball with 21.05 on another system, and then set up the WSL environment with that tarball. Is that right?

Access display

Hey y'all.

Just recently grabbed NixOS-WSL. I have VcXsrv running, and display works on my Ubuntu WSL. But when I open up NixOS and running xclock, I get a Error: Can't open display: localhost:0 (this is also my $DISPLAY variable on Ubuntu WSL).

I've tried running the Nyxt browser as well, same error.

All help appreciated!

bootloader script as a replacement for grub/systemd-boot/extlinux NixOS rollback feature

First of all, thank you for making NixOS on WSL a reality! It works!

Originally, NixOS comes with a handy rollback feature which helps in case the system got broken. At the current (974a7c4) state it's even easier: making some systemd service enter a failed state prevents the login. Though, there is a workaround wsl -u nixos for exact this case with some nasty hacks following it related to namespaces, but I think the problem is clear.

The idea is to develop a not so complex NixOS module or maybe patch the grub/systemd-boot/extlinux module to allow a user select the system configuration to load instead of the most recent.
Without NixOS module, in the most primitive form: listing directories symlinks in /nix/var/nix/profiles and waiting for a user to type the desired one should suffice, residing in syschdemd.sh script.

Who wants to take over this project?

As you might have noticed, I don't have the time or energy to really take care of NixOS-WSL. The project seems to have some users, so the best way forward would probably be to hand it over to someone who actively maintains it. Any suggestions or volunteers?

nsenter: failed to execute /run/wrappers/bin/su: No such file or directory

PS C:\Users\luoch> wsl --import NixOS .\NixOS\ .\NixOS\nixos-system-x86_64-linux.tar.gz --version 2
PS C:\Users\luoch> wsl --list
适用于 Linux 的 Windows 子系统分发版:
Ubuntu (默认)
NixOS
PS C:\Users\luoch> wsl -d NixOS
-sh-4.4# /nix/var/nix/profiles/system/activate
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
        LANGUAGE = (unset),
        LC_ALL = (unset),
        LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
setting up /etc...
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
        LANGUAGE = (unset),
        LC_ALL = (unset),
        LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
-sh-4.4# logout
PS C:\Users\luoch> wsl -d NixOS
nsenter: failed to execute /run/wrappers/bin/su: No such file or directory

Systemd fails to start when cgroups v2 is enabled

#logs:

Processing fstab with mount -a failed.

Unpacking root file system...
184MiB 0:00:06 [26.5MiB/s] [========================================================================>] 100%
Activating nix configuration...
Copying /usr/share/applications
Copying /usr/share/icons
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LANG = "en_US.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
setting up /etc...
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LANG = "en_US.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
Cleaning up installer files...
finding garbage collector roots...
removing stale link from '/nix/var/nix/gcroots/auto/zxi8v969la5n36bg7gs016wgcif4qjhp' to '/build/nix/var/nix/profiles/system-1-link'
removing stale link from '/nix/var/nix/gcroots/auto/6yfbrv8wfkyl40wq6827lamr9m29z7wg' to '/build/nix/var/nix/profiles/per-user/root/channels-1-link'
deleting garbage...
deleting '/nix/store/m0qmllywgy9wl4ia7vvpz7p53kzxv681-busybox-1.34.1'
deleting '/nix/store/3y5hdyv6n1dbkfg7x3nn59hzhpwj51bl-installer.sh'
deleting '/nix/store/svw89j47vr3h792f75nfgh5x9s48rn0w-pv-1.6.20'
deleting '/nix/store/4z8x8wq942jxghp1261lc5hajj7q3fx3-tarball'
deleting '/nix/store/pjsz3xk31a6w0z22n0yiir0cjz6w1lx1-wsl-prepare'
deleting '/nix/store/grqvhmymidyp0si0gga824jkwi4lfpjn-source'
deleting '/nix/store/trash'
deleting unused links...
note: currently hard linking saves -0.00 MiB
6 store paths deleted, 185.42 MiB freed
Optimizing store...
5.05 MiB freed by hard-linking 3499 files
Starting systemd...

/dev/pts/0 is owned by root user, which breaks emacsclient

[nixos@nixos:~]$ emacsclient -a '' foo.txt -t
/home/nixos/.nix-profile/bin/emacsclient: can't find socket; have you started the server?
/home/nixos/.nix-profile/bin/emacsclient: To start the server in Emacs, type "M-x server-start".

Warning: due to a long standing Gtk+ bug
https://gitlab.gnome.org/GNOME/gtk/issues/221
Emacs might crash when run in daemon mode and the X11 connection is unexpectedly lost.
Using an Emacs configured with --with-x-toolkit=lucid does not have this problem.
Starting Emacs daemon.
Emacs daemon should have started, trying to connect again
*ERROR*: Could not open file: /dev/pts/0

here's a stack overflow discussion of pseudoterminals https://serverfault.com/questions/116775/sudo-as-different-user-and-running-screen/116830

I notice that in an ubuntu wsl container I have that /dev/pts/0 is in fact owned by the non-root user

How to use vscode in NixOS-WSL

In ubuntu version, I usually do code . then vscode opens in windows with remote connection with ubuntu.

Is it possible to have same workflow?

Is there any tutorial on how to use NixOS inside WSL

Nix noob here, couldn't wrap my head around flake and home-manager. Wiki doesn't mention WSL specific instructions and no info found other than here. My goal was to be able to install a list of apps like gcloud-cli, kubectl, neovim, miniconda, ruby etc and to give OS a try.
Somehow installed home-manager (standalone mode, maybe should've gone with NixOS Module approach, please advise) with flakes following this: https://nix-community.github.io/home-manager/index.html#ch-nix-flakes and it seems working, however I'm not sure that it's right way of doing it.

Could you point a documentation that is valid for NixOS under WSL2 for a complete noobs in nix like me?

How can I change the hostname?

I find that setting networking.hostName only works after sudo nixos-rebuild switch, and when I reboot the wsl with wsl --shutdown, it turn back to the Windows hostname again.

So, am I expected to keep the hostname and not touching it ?

How to update?

I installed from a release tarball some time ago, and now I see that improvements have been made. How do I update my existing container to the current version of NixOS-WSL?

In particular, if I figure out a fix to #35 , I don't know how to test or apply my fix.

What is the default password for nixos user?

[nixos@nixos:/mnt/c]$ su nixos
Password:
su: Authentication failure

this is what is get with empty password...
can't reset password without the current password..

just wanted to write commands without sudo at the beginning, but knowing the password is important nevertheless..

Thanks..

How to run this?

I've created the rootfs using your nix expression. But I don't really know how to launch it next?

I didn't go through the full tutorial about how to package a distro, but just used WSL2's import command. After that, I can launch the distro, It only shows -sh-4.4#, but when I access some of the commands at least something happens. But I don't really know how to get it to the point where I can nixos-install or nixos-rebuild. A bit of help would be very much appreciated.

Initial shell is not a login shell, does not source ~/.bash_profile

I'm seeing that ~/.bash_profile is not being sourced automatically when opening a wsl terminal, but it is if I then run bash --login. In the initial shell, I've also checked with this command shopt -q login_shell && echo 'Login shell' || echo 'Not login shell', which I got from https://unix.stackexchange.com/a/26782.

In particular, I'm trying to use home-manager inside wsl, and the programs.bash.sessionVariables option doesn't work because of this.

"wsl.exe some_command" does not run command

The problem:

C:\WINDOWS\System32\wsl.exe echo hello

in the command prompt does not execute "echo hello".



I'm no shell script expert, but it seems like when root shell is called with parameters, the parameters are being ignored:

I figured out that executing

C:\WINDOWS\System32\wsl.exe echo hello

calls

$ROOT_LOGIN_SHELL? -c echo hello

within NixOS distro, which results in

syschdemd.sh -c echo hello

However it seems syschdemd.sh doesn't take care of arguments, causing the problem.



Since this was a blocker of using vscode remote-wsl extension, I managed to hotfix this, by changing
https://github.com/Trundle/NixOS-WSL/blob/32fd863dda65cfa718cd85b088a00fb3bdef42ba/syschdemd.sh#L26
this to:

if [[ $1 = "-c" ]]; then
  exec $sw/nsenter -t $(< /run/systemd.pid) -p -m --wd="$PWD" -- @wrapperDir@/su -s $userShell @defaultUser@ -c "${@:2}"
else
  exec $sw/nsenter -t $(< /run/systemd.pid) -p -m --wd="$PWD" -- @wrapperDir@/su -s $userShell @defaultUser@
fi

, passing arguments surrounded with double quotes.
However it does implement only -c option, and I think there's a way to pass all kinds of shell arguments.

License?

Hi,

What's the license of this project? I would like to include parts of it in my nixfiles repo, but am unsure under what license I can do so.

Thanks for your work, this has functioned very well for me so far!

Documents for flakes user

I tested following and it works for me:

nix build .#nixosConfigurations.mysystem.config.system.build.tarball

Docker using the host

Is it possible to use Docker from docker desktop like with other distros? It's basically the only thing that makes me keep using ubuntu as a escape hatch.

I currently get this output when trying:

> docker ps
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/json": dial unix /var/run/docker.sock: connect: permission denied

Cut new release

Current tarball from feb of last year is essentially unusable given the amount of required changes that were held up for so long.

I think this is urgent as it's very frustrating for someone to come across this repo and not realize it's broken. Maybe consider just pushing a readme change to master to denote that the current tarball can't be used and that you have to build it yourself for now.

Native docker support

Using Docker Desktop from within NixOS now works if it is enabled with wsl.docker.enable = true;.
It would be great, to additionally have the option to use the native Linux-version of docker directly from NixOS like on a bare-metal installation. In the past this was possible by just enabling docker. As of NixOS 21.11 however a kernel that supports nftables is required

wsl: nsenter: failed to parse pid: '-p'

I have a fresh WSL2 install, tried to use this README to install NixOS as my default WSL2 distribution, but when I try to run wsl, I get:

> wsl
nsenter: failed to parse pid: '-p'

From digging around I suspect this has something to do with the systemd hack, but I don't know enough about WSL to troubleshoot what's happening here, any thoughts?

Install process:

> wsl --import NixOS . .\nixos-wsl-installer.tar.gz --version 2

> wsl --list -v
  NAME     STATE           VERSION
* NixOS    Stopped         2

> wsl -d NixOS
Unpacking root file system...
 184MiB 0:00:06 [30.2MiB/s] [==========================================================================================>] 100%
Activating nix configuration...
Copying /usr/share/applications
Copying /usr/share/icons
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
        LANGUAGE = (unset),
        LC_ALL = (unset),
        LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
setting up /etc...
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
        LANGUAGE = (unset),
        LC_ALL = (unset),
        LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
Cleaning up installer files...
finding garbage collector roots...
removing stale link from '/nix/var/nix/gcroots/auto/6yfbrv8wfkyl40wq6827lamr9m29z7wg' to '/build/nix/var/nix/profiles/per-user/root/channels-1-link'
removing stale link from '/nix/var/nix/gcroots/auto/zxi8v969la5n36bg7gs016wgcif4qjhp' to '/build/nix/var/nix/profiles/system-1-link'
deleting garbage...
deleting '/nix/store/svw89j47vr3h792f75nfgh5x9s48rn0w-pv-1.6.20'
deleting '/nix/store/m0qmllywgy9wl4ia7vvpz7p53kzxv681-busybox-1.34.1'
deleting '/nix/store/m7cghw288wks5s5mkxpg1k3h5ivlg1ch-installer.sh'
deleting '/nix/store/8hm7r6m8y0fjrb4qjv8gs1ba04g51166-tarball'
deleting '/nix/store/y608sw04xdqhha69raxpj2rsk007n7wf-wsl-prepare'
deleting '/nix/store/4ryxif8fmjb362ry8ylx29hsxp0zgpax-source'
deleting '/nix/store/trash'
deleting unused links...
note: currently hard linking saves -0.00 MiB
6 store paths deleted, 185.42 MiB freed
Optimizing store...
5.05 MiB freed by hard-linking 3499 files
Starting systemd...

> wsl --list -v
  NAME     STATE           VERSION
* NixOS    Running         2

> wsl
nsenter: failed to parse pid: '-p'

The remote procedure call failed

Hey everyone.

I'm writing this issue because I didn't find one on this repository already. It took me 3-4 separate tries on different dates to solve it, and a lot of midnight oil. WSL errors kill me sometimes, because they're so non-verbose. Anyways, on with the story...

What happened

Downloaded the tarball, ran wsl --import NixOS .\NixOS\ Downloads/nixos-system-x86_64-linux.tar.gz --version 2. Error: The remote procedure call failed.

Expected behaviour

The installer to "just work".

Solution

First off, it seems like my insider build disables Hyper-V, or deletes a .dll file. In all honesty, I don't know which it is.

If you're on Windows 10 Pro, enable Hyper-V in your "Turn Windows features on or off" settings. If you're a Windows 10 Home user, you won't have that by default, and have to follow the following article on how to grab it. TL;DR it asks you to download a .bat that will enable a ton of features and prompt to restart. Once you're done, Hyper-V should be enabled automatically (feel free to check in the "Turn Windows Features on or off" menu, though).

On the other hand, the first part of this answer helped get back a .dll file that's lost. @ coxchris859 provides the following download if you are unable to find the file specified in that answer.

I believe it was a combination of these two fixes that solved the problem. I can finally enjoy NixOS on my Windows 10 laptop in peace.

Cheers, Bobbbay.

systemd --system flag simpler?

I noticed that nowadays, systemd has the --system flag to force it to work as the system instance even if the PID is not 1. Would that work here?

[Windows 11] systemctl --user fails with release 20.09-0cfd08f4881

On Windows 11

[nixos@nixos:~]$ systemctl --user status
Failed to connect to bus: No such file or directory

strace shows connect(3, {sa_family=AF_UNIX, sun_path="/mnt/wslg/runtime-dir/systemd/private"}, 40) = -1 ENOENT (No such file or directory). This pointed me to Windows 11/wslg.

Replacing /etc/nixos/syschdemd.sh with https://raw.githubusercontent.com/nix-community/NixOS-WSL/main/syschdemd.sh fixes systemctl --user.

However, now vscode-server breaks. Going with https://raw.githubusercontent.com/nzbr/NixOS-WSL/main/syschdemd.sh fixes also this part.

Docker Desktop WSL2 not working

Bug description

When I enable the option docker.enable = true; in my configuration.nix I expect then to see my running docker images in Docker Desktop for Windows when executing docker ps. Instead I get:

$ docker ps
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

So my first thought here is, why is it trying to connect to the local docker socket and not the proxy?

After some trials and errors I finally found following hint:

/mnt/wsl/docker-desktop/docker-desktop-proxy -docker-desktop-root /mnt/wsl/docker-desktop
bash: /mnt/wsl/docker-desktop/docker-desktop-proxy: No such file or directory

On my system it seems the name is different, instead when running this command, everything works:

/mnt/wsl/docker-desktop/docker-desktop-user-distro proxy --docker-desktop-root /mnt/wsl/docker-desktop

Before submitting a Pull-Request with a fix that works only for me, I want to figure out how comes that my system behaves differently from the others. In the next step I will let you know the versions of NixOS-WSL and Docker Desktop I use, to let you potentially reproduce this issue.

To Reproduce

Steps to reproduce the behavior:

nsenter: failed to parse pid: '-p'

I just imported the current version of the installer:

wsl --import NixOS .\NixOS\ .\Downloads\nixos-wsl-installer.tar.gz --version 2

When I try to run it I get an error:

> wsl -d NixOS
nsenter: failed to parse pid: '-p'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.