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

WIP: Distribute as .wsl file instead of .tar.gz #600

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/on_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ jobs:

- name: Generate Checksums 🔑
run: |
for x in *.{tar.gz,zip}; do
for x in *.{wsl,zip}; do
sha256sum $x > ${x}.sha256
done

- name: Attach to Release 📎
uses: softprops/action-gh-release@v2
with:
files: |
nixos-wsl.tar.gz
nixos-wsl.tar.gz.sha256
nixos.wsl
nixos.wsl.sha256
NixOS-WSL-Launcher.zip
NixOS-WSL-Launcher.zip.sha256
env:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/run_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ jobs:
uses: ./.github/actions/build-wsl-tarball
with:
config: default
filename: nixos-wsl.tar.gz
filename: nixos.wsl

- name: Upload Tarball 📤
uses: actions/upload-artifact@v4
with:
name: tarball
path: nixos-wsl.tar.gz
path: nixos.wsl

launcher:
name: Launcher 🛠️
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/run_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:

- name: Create dummy tarball
shell: pwsh
run: echo $null >> Launcher\Launcher-Appx\nixos-wsl.tar.gz
run: echo $null >> Launcher\Launcher-Appx\nixos.wsl

- name: Run InspectCode 🔍
shell: pwsh
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/run_package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:

- name: Bundle tarball with launcher 📦
run: |
Copy-Item nixos-wsl.tar.gz Launcher\Launcher\pkg\
Copy-Item nixos.wsl Launcher\Launcher\pkg\

- name: Upload Launcher 📤
uses: actions/upload-artifact@v4
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
result
result-*
nixos-wsl*.tar.gz
nixos.wsl
8 changes: 5 additions & 3 deletions Launcher/Launcher-Appx/Launcher-Appx.wapproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project ToolsVersion="15.0" DefaultTargets="Build"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '15.0'">
<VisualStudioVersion>15.0</VisualStudioVersion>
</PropertyGroup>
Expand Down Expand Up @@ -54,11 +55,12 @@
<Content Include="Images\Square44x44Logo.targetsize-24_altform-unplated.png" />
<Content Include="Images\StoreLogo.png" />
<Content Include="Images\Wide310x150Logo.scale-200.png" />
<Content Include="nixos-wsl.tar.gz" />
<Content Include="nixos.wsl" />
</ItemGroup>
<Import Project="$(WapProjPath)\Microsoft.DesktopBridge.targets" />
<ItemGroup>
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22000.197" PrivateAssets="all" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22000.197"
PrivateAssets="all" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Launcher\Launcher.csproj" />
Expand Down
2 changes: 1 addition & 1 deletion Launcher/Launcher/src/Helpers/InstallationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Launcher.Helpers;

public static class InstallationHelper {

Check warning on line 8 in Launcher/Launcher/src/Helpers/InstallationHelper.cs

View workflow job for this annotation

GitHub Actions / Build 🛠️ / Launcher 🛠️

Because an application's API isn't typically referenced from outside the assembly, types can be made internal (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1515)

Check warning on line 8 in Launcher/Launcher/src/Helpers/InstallationHelper.cs

View workflow job for this annotation

GitHub Actions / Checks 📋 / Check .NET 📋

CA1515

Because an application's API isn't typically referenced from outside the assembly, types can be made internal

Check warning on line 8 in Launcher/Launcher/src/Helpers/InstallationHelper.cs

View workflow job for this annotation

GitHub Actions / Build 🛠️ / Launcher 🛠️

Because an application's API isn't typically referenced from outside the assembly, types can be made internal (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1515)

Check warning on line 8 in Launcher/Launcher/src/Helpers/InstallationHelper.cs

View workflow job for this annotation

GitHub Actions / Checks 📋 / Check .NET 📋

CA1515

Because an application's API isn't typically referenced from outside the assembly, types can be made internal
/// <summary>
/// Registers the distribution and runs first-time setup
/// </summary>
Expand Down Expand Up @@ -62,31 +62,31 @@
/// </summary>
/// <returns>the full path to the tarball or null</returns>
private static string? FindTarball() {
const string tarFileName = "nixos-wsl.tar.gz";
const string tarFileName = "nixos.wsl";

// Accept a tarball in the current directory when running a debug build
#if (DEBUG)
var pwd = Directory.GetCurrentDirectory();
var debugTarPath = Path.Combine(pwd, tarFileName);
if (File.Exists(debugTarPath)) {

Check notice on line 71 in Launcher/Launcher/src/Helpers/InstallationHelper.cs

View workflow job for this annotation

GitHub Actions / Checks 📋 / Check .NET 📋

RemoveRedundantBraces

Inconsistent braces style: redundant braces

Check notice on line 71 in Launcher/Launcher/src/Helpers/InstallationHelper.cs

View workflow job for this annotation

GitHub Actions / Checks 📋 / Check .NET 📋

RemoveRedundantBraces

Inconsistent braces style: redundant braces
return debugTarPath;
}
#endif

// Look for the tarball in the same directory as the executable
var assemblyPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
if (assemblyPath == null) {

Check notice on line 78 in Launcher/Launcher/src/Helpers/InstallationHelper.cs

View workflow job for this annotation

GitHub Actions / Checks 📋 / Check .NET 📋

RemoveRedundantBraces

Inconsistent braces style: redundant braces

Check notice on line 78 in Launcher/Launcher/src/Helpers/InstallationHelper.cs

View workflow job for this annotation

GitHub Actions / Checks 📋 / Check .NET 📋

RemoveRedundantBraces

Inconsistent braces style: redundant braces
return null;
}

var tarPath = Path.Combine(assemblyPath, tarFileName);
if (File.Exists(tarPath)) {

Check notice on line 83 in Launcher/Launcher/src/Helpers/InstallationHelper.cs

View workflow job for this annotation

GitHub Actions / Checks 📋 / Check .NET 📋

RemoveRedundantBraces

Inconsistent braces style: redundant braces

Check notice on line 83 in Launcher/Launcher/src/Helpers/InstallationHelper.cs

View workflow job for this annotation

GitHub Actions / Checks 📋 / Check .NET 📋

RemoveRedundantBraces

Inconsistent braces style: redundant braces
return tarPath;
}

// In the APPX package, the tarball is in the parent directory
var parentDirectory = Directory.GetParent(assemblyPath)?.FullName;
if (parentDirectory == null) {

Check notice on line 89 in Launcher/Launcher/src/Helpers/InstallationHelper.cs

View workflow job for this annotation

GitHub Actions / Checks 📋 / Check .NET 📋

RemoveRedundantBraces

Inconsistent braces style: redundant braces

Check notice on line 89 in Launcher/Launcher/src/Helpers/InstallationHelper.cs

View workflow job for this annotation

GitHub Actions / Checks 📋 / Check .NET 📋

RemoveRedundantBraces

Inconsistent braces style: redundant braces
return null;
}

Expand Down
20 changes: 5 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,13 @@ Modules for running NixOS on the Windows Subsystem for Linux

1. Enable WSL if you haven't done already:

- ```powershell
wsl --install --no-distribution
```
- ```powershell
wsl --install --no-distribution
```

2. Download `nixos-wsl.tar.gz` from [the latest release](https://github.com/nix-community/NixOS-WSL/releases/latest).
2. Download `nixos.wsl` from [the latest release](https://github.com/nix-community/NixOS-WSL/releases/latest).

3. Import the tarball into WSL:

- ```powershell
wsl --import NixOS $env:USERPROFILE\NixOS\ nixos-wsl.tar.gz --version 2
```

4. You can now run NixOS:

- ```powershell
wsl -d NixOS
```
3. Double-click the file you just downloaded (requires WSL >= 2.4.4)

For more detailed instructions, [refer to the documentation](https://nix-community.github.io/NixOS-WSL/install.html).

Expand Down
2 changes: 1 addition & 1 deletion docs/src/building.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ nix-build -A nixosConfigurations.default.config.system.build.tarballBuilder && s

```

The resulting tarball can then be found under `nixos-wsl.tar.gz`.
The resulting tarball can then be found under `nixos.wsl`.
29 changes: 24 additions & 5 deletions docs/src/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,39 @@ Support for older "inbox" versions is best-effort.

## Install NixOS-WSL

First, [download the latest release](https://github.com/nix-community/NixOS-WSL/releases/latest).
First, download `nixos.wsl` from [the latest release](https://github.com/nix-community/NixOS-WSL/releases/latest).[^wsl-file]

Then open up a PowerShell and run:
If you have WSL version 2.4.4 or later installed, you can open (double-click) the .wsl file to install it.
It is also possible to perform the installation from a PowerShell:

```powershell
wsl --import NixOS $env:USERPROFILE\NixOS\ nixos-wsl.tar.gz --version 2
wsl --install --from-file nixos.wsl
```

`nixos.wsl` must be the path to the file you just downloaded if you're running the command in another directory.

You can use the `--name` and `--location` flags to change the name the distro is registered under (default: `NixOS`) and the location of the disk image (default: `%localappdata%\wsl\{some random GUID}`). For a full list of options, refer to `wsl --help`

To open a shell in your NixOS environment, run `wsl -d NixOS`, select NixOS from the profile dropdown in Windows Terminal or run it from your Start Menu. (Adjust the name accordingly if you changed it)

### Older WSL versions

If you have a WSL version older than 2.4.4, you can install NixOS-WSL like this:

Open up a PowerShell and run:

```powershell
wsl --import NixOS $env:USERPROFILE\NixOS\ nixos.wsl --version 2
```

Or for Command Prompt:

```cmd
wsl --import NixOS %USERPROFILE%\NixOS\ nixos-wsl.tar.gz --version 2
wsl --import NixOS %USERPROFILE%\NixOS\ nixos.wsl --version 2
```

This sets up a new WSL distribution `NixOS` that is installed in a directory called `NixOS` inside your user directory.
`nixos-wsl.tar.gz` is the path to the file you downloaded earlier.
`nixos.wsl` is the path to the file you downloaded earlier.
You can adjust the installation path and distribution name to your liking.

To get a shell in your NixOS environment, use:
Expand All @@ -46,3 +63,5 @@ If you want to make NixOS your default distribution, you can do so with
```powershell
wsl -s NixOS
```

[^wsl-file]: That file is called `nixos-wsl.tar.gz` in releases prior to 2411.*
17 changes: 16 additions & 1 deletion modules/build-tarball.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ with builtins; with lib;
let
cfg = config.wsl.tarball;

icon = ../Launcher/Launcher/nixos.ico;
iconPath = "/etc/nixos.ico";

wsl-distribution-conf = pkgs.writeText "wsl-distribution.conf" (
generators.toINI { } {
oobe.defaultName = "NixOS";
shortcut.icon = iconPath;
}
);

defaultConfig = pkgs.writeText "default-configuration.nix" ''
# Edit this configuration file to define what should be installed on
# your system. Help is available in the configuration.nix(5) man page, on
Expand Down Expand Up @@ -62,7 +72,8 @@ in
exit 1
fi

out=''${1:-nixos-wsl.tar.gz}
# Use .wsl extension to support double-click installs on recent versions of Windows
out=''${1:-nixos.wsl}

root=$(mktemp -p "''${TMPDIR:-/tmp}" -d nixos-wsl-tarball.XXXXXXXXXX)
# FIXME: fails in CI for some reason, but we don't really care because it's CI
Expand All @@ -80,6 +91,10 @@ in
echo "[NixOS-WSL] Adding channel..."
nixos-enter --root "$root" --command 'HOME=/root nix-channel --add https://github.com/nix-community/NixOS-WSL/archive/refs/heads/main.tar.gz nixos-wsl'

echo "[NixOS-WSL] Adding wsl-distribution.conf"
install -Dm644 ${wsl-distribution-conf} "$root/etc/wsl-distribution.conf"
install -Dm644 ${icon} "$root${iconPath}"

echo "[NixOS-WSL] Adding default config..."
${if cfg.configPath == null then ''
install -Dm644 ${defaultConfig} "$root/etc/nixos/configuration.nix"
Expand Down
4 changes: 2 additions & 2 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ Please note that the tests are not compatible with Windows PowerShell, but requi
### Running the Tests

If you haven't already, [install Pester](https://pester.dev/docs/introduction/installation/).
The tests require a "default" (formerly "modern") `nixos-wsl.tar.gz` to be present in the current working directory, which can be built with
`sudo nix run .#nixosConfigurations.default.config.system.build.tarballBuilder -- nixos-wsl.tar.gz`.
The tests require a "default" `nixos.wsl` to be present in the current working directory, which can be built with
`sudo nix run .#nixosConfigurations.default.config.system.build.tarballBuilder -- nixos.wsl`.

Once everything is in place, run the test by running the following in PowerShell at the root of this repo:

Expand Down
2 changes: 1 addition & 1 deletion tests/lib/lib.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Distro {

[string]FindTarball() {
# Check if a fresh tarball exists in result, otherwise try one in the current directory
$tarball = "./nixos-wsl.tar.gz"
$tarball = "./nixos.wsl"
if (!(Test-Path $tarball)) {
throw "Could not find the tarball! Run nix build first, or place one in the current directory."
}
Expand Down
Loading