WSL: Difference between revisions
imported>Onny Note that NixOS is not yet officially packaged on MS store |
m Copyedits |
||
| (4 intermediate revisions by 3 users not shown) | |||
| Line 1: | Line 1: | ||
Notes on running NixOS on the Windows Subsystem for Linux (WSL, WSL2) | Notes on running NixOS on the Windows Subsystem for Linux (WSL, WSL2). | ||
== Setup == | == Setup == | ||
Ensure that WSL is installed and up to date | Ensure that WSL is installed and up to date. | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="powershell"> | ||
wsl --install | |||
wsl --update | wsl --update | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Sometimes you'll have to install WSL2 manually by [https://github.com/microsoft/WSL/releases downloading the msi-installation package]. | |||
NixOS is [https://github.com/microsoft/WSL/issues/11206 not yet packaged] as a official WSL distribution or on the Microsoft store. Download the latest release of <code>nixos-wsl.tar.gz</code> from the [https://github.com/nix-community/NixOS-WSL/releases NixOS-WSL Github page]. | NixOS is [https://github.com/microsoft/WSL/issues/11206 not yet packaged] as a official WSL distribution or on the Microsoft store. Download the latest release of <code>nixos-wsl.tar.gz</code> from the [https://github.com/nix-community/NixOS-WSL/releases NixOS-WSL Github page]. | ||
| Line 13: | Line 16: | ||
Import the WSL container using PowerShell | Import the WSL container using PowerShell | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="powershell"> | ||
wsl --import NixOS .\NixOS\ nixos-wsl.tar.gz --version 2 | wsl --import NixOS .\NixOS\ nixos-wsl.tar.gz --version 2 | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| Line 19: | Line 22: | ||
== Usage == | == Usage == | ||
Start it with | Start it with PowerShellː | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="powershell"> | ||
wsl -d NixOS | wsl -d NixOS | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| Line 27: | Line 30: | ||
== Tips and tricks == | == Tips and tricks == | ||
== Run container on startup == | === Run container on startup === | ||
To run the distro <code>NixOS</code> on Windows startup or user login in the background, | To run the distro <code>NixOS</code> on Windows startup or user login in the background, use these commands in PowerShellː | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="powershell"> | ||
echo "" > $HOME\run_wsl2_at_startup.vbs | echo "" > $HOME\run_wsl2_at_startup.vbs | ||
notepad $HOME\run_wsl2_at_startup.vbs | notepad $HOME\run_wsl2_at_startup.vbs | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Inside the script we define <code>NixOS</code> as the distribution name, as imported in the setup step above | Inside the script we define <code>NixOS</code> as the distribution name, as imported in the setup step above. | ||
{{file|$HOME\run_wsl2_at_startup.vbs| | {{file|$HOME\run_wsl2_at_startup.vbs|vbscript|<nowiki> | ||
set object = createobject("wscript.shell") | set object = createobject("wscript.shell") | ||
object.run "wsl.exe --distribution NixOS", 0 | object.run "wsl.exe --distribution NixOS", 0 | ||
</nowiki>}} | </nowiki>}} | ||
Open the task schedulerː | |||
<syntaxhighlight lang=" | <syntaxhighlight lang="powershell"> | ||
taskschd.msc | taskschd.msc | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Click on <code> | Click on <code>Create task</code> on the right pane, set name to <code>WSL</code>. On the tab "Triggers" click on "New ..." and select "run task on user login" in the dropdown menu. On the tab "Action" click on "New ..." and insert as command: <code>%USERPROFILE%\run_wsl2_at_startup.vbs</code> | ||
[[Category:Container]] | |||
Latest revision as of 10:22, 8 August 2025
Notes on running NixOS on the Windows Subsystem for Linux (WSL, WSL2).
Setup
Ensure that WSL is installed and up to date.
wsl --install
wsl --update
Sometimes you'll have to install WSL2 manually by downloading the msi-installation package.
NixOS is not yet packaged as a official WSL distribution or on the Microsoft store. Download the latest release of nixos-wsl.tar.gz from the NixOS-WSL Github page.
Import the WSL container using PowerShell
wsl --import NixOS .\NixOS\ nixos-wsl.tar.gz --version 2
Usage
Start it with PowerShellː
wsl -d NixOS
Tips and tricks
Run container on startup
To run the distro NixOS on Windows startup or user login in the background, use these commands in PowerShellː
echo "" > $HOME\run_wsl2_at_startup.vbs
notepad $HOME\run_wsl2_at_startup.vbs
Inside the script we define NixOS as the distribution name, as imported in the setup step above.
set object = createobject("wscript.shell")
object.run "wsl.exe --distribution NixOS", 0
Open the task schedulerː
taskschd.msc
Click on Create task on the right pane, set name to WSL. On the tab "Triggers" click on "New ..." and select "run task on user login" in the dropdown menu. On the tab "Action" click on "New ..." and insert as command: %USERPROFILE%\run_wsl2_at_startup.vbs