diff --git a/.github/workflows/on_release.yml b/.github/workflows/on_release.yml index 0b3aaee..0374c35 100644 --- a/.github/workflows/on_release.yml +++ b/.github/workflows/on_release.yml @@ -42,7 +42,7 @@ jobs: - name: Generate Checksums 🔑 run: | - for x in *.{tar.gz,zip}; do + for x in *.{wsl,zip}; do sha256sum $x > ${x}.sha256 done @@ -50,8 +50,8 @@ jobs: 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: diff --git a/.github/workflows/run_build.yml b/.github/workflows/run_build.yml index 562830b..b4acfa8 100644 --- a/.github/workflows/run_build.yml +++ b/.github/workflows/run_build.yml @@ -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 🛠️ diff --git a/.github/workflows/run_checks.yml b/.github/workflows/run_checks.yml index 2bb70ed..c85d708 100644 --- a/.github/workflows/run_checks.yml +++ b/.github/workflows/run_checks.yml @@ -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 diff --git a/.github/workflows/run_package.yml b/.github/workflows/run_package.yml index 7d186f5..a52b035 100644 --- a/.github/workflows/run_package.yml +++ b/.github/workflows/run_package.yml @@ -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 diff --git a/.gitignore b/.gitignore index d6835c7..f5c299a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ result result-* nixos-wsl*.tar.gz +nixos.wsl diff --git a/Launcher/Launcher-Appx/Launcher-Appx.wapproj b/Launcher/Launcher-Appx/Launcher-Appx.wapproj index f0493c3..59a8554 100644 --- a/Launcher/Launcher-Appx/Launcher-Appx.wapproj +++ b/Launcher/Launcher-Appx/Launcher-Appx.wapproj @@ -1,5 +1,6 @@ - + 15.0 @@ -54,11 +55,12 @@ - + - + diff --git a/Launcher/Launcher/src/Helpers/InstallationHelper.cs b/Launcher/Launcher/src/Helpers/InstallationHelper.cs index 323ba58..f839229 100644 --- a/Launcher/Launcher/src/Helpers/InstallationHelper.cs +++ b/Launcher/Launcher/src/Helpers/InstallationHelper.cs @@ -62,7 +62,7 @@ public static class InstallationHelper { /// /// the full path to the tarball or null 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) diff --git a/README.md b/README.md index a291fa5..08bf5e6 100644 --- a/README.md +++ b/README.md @@ -15,17 +15,13 @@ Run the following from powershell: 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 - ``` +3. Double-click the file you just downloaded (requires WSL >= 2.4.4) 4. You can now run NixOS: diff --git a/docs/src/building.md b/docs/src/building.md index f915387..603c130 100644 --- a/docs/src/building.md +++ b/docs/src/building.md @@ -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`. diff --git a/docs/src/install.md b/docs/src/install.md index 0172897..a480c1c 100644 --- a/docs/src/install.md +++ b/docs/src/install.md @@ -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: @@ -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.* diff --git a/modules/build-tarball.nix b/modules/build-tarball.nix index 7485c7d..e474c21 100644 --- a/modules/build-tarball.nix +++ b/modules/build-tarball.nix @@ -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 @@ -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 @@ -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" diff --git a/tests/README.md b/tests/README.md index 9876c89..d267eaa 100644 --- a/tests/README.md +++ b/tests/README.md @@ -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: diff --git a/tests/lib/lib.ps1 b/tests/lib/lib.ps1 index e8de4c8..b6e45b5 100644 --- a/tests/lib/lib.ps1 +++ b/tests/lib/lib.ps1 @@ -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." }