Skip to content

Instantly share code, notes, and snippets.

@netbrain
Created October 6, 2023 07:32
Show Gist options
  • Select an option

  • Save netbrain/a1093ff0d882b95c8fb62787c1c53227 to your computer and use it in GitHub Desktop.

Select an option

Save netbrain/a1093ff0d882b95c8fb62787c1c53227 to your computer and use it in GitHub Desktop.
nixos wsl
# Function to download the tar file
function Download-NixOS {
$url = "https://github.com/nix-community/nixos-wsl/releases/latest/download/nixos-wsl.tar.gz"
$output = "$env:TEMP\nixos-wsl.tar.gz"
Invoke-WebRequest -Uri $url -OutFile $output
return $output
}
# Function to check if WSL is installed and install if it's not
function Install-WSL {
$wslInstalled = Get-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
if ($wslInstalled.State -ne 'Enabled') {
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux -All -NoRestart
}
}
# Function to import into WSL
function Import-WSL ($tarPath) {
wsl --import NixOS .\NixOS\ $tarPath --version 2
}
# Main execution
$tarPath = Download-NixOS
Install-WSL
Import-WSL -tarPath $tarPath
@netbrain
Copy link
Author

netbrain commented Oct 6, 2023

After install of nixos:

wsl -d NixOS -u root
usermod -d /home/<newuser> nixos
usermod -l <newuser> nixos
nano /etc/nixos/configuration.nix
# change user = nixos to user = <newuser>
nixos-rebuild switch
exit

wsl --shutdown
wsl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment