WSL: Difference between revisions

imported>Onny
Note that NixOS is not yet officially packaged on MS store
imported>Tetov
m Clarification on task scheduling and corrected language parameters for pre/file
Line 5: Line 5:
Ensure that WSL is installed and up to date
Ensure that WSL is installed and up to date


<syntaxhighlight lang="bash">
<syntaxhighlight lang="powershell">
wsl --update
wsl --update
</syntaxhighlight>
</syntaxhighlight>
Line 13: Line 13:
Import the WSL container using PowerShell
Import the WSL container using PowerShell


<syntaxhighlight lang="bash">
<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 21: Line 21:
Start it with PowerShell
Start it with PowerShell


<syntaxhighlight lang="bash">
<syntaxhighlight lang="powershell">
wsl -d NixOS
wsl -d NixOS
</syntaxhighlight>
</syntaxhighlight>
Line 31: Line 31:
To run the distro <code>NixOS</code> on Windows startup or user login in the background, proceed with following commands in PowerShell
To run the distro <code>NixOS</code> on Windows startup or user login in the background, proceed with following commands in PowerShell


<syntaxhighlight lang="bash">
<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
Line 38: Line 38:
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|vbs|<nowiki>
{{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
Line 45: Line 45:
Execute following command to open the task planer
Execute following command to open the task planer


<syntaxhighlight lang="bash">
<syntaxhighlight lang="powershell">
taskschd.msc
taskschd.msc
</syntaxhighlight>
</syntaxhighlight>


Click on <code>New 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. On the tab "Action" click on "New ..." and insert as command: <code>%USERPROFILE%\run_wsl2_at_startup.vbs</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>