diff --git a/.github/workflows/run_build.yml b/.github/workflows/run_build.yml index f30441e1..3e616d8c 100644 --- a/.github/workflows/run_build.yml +++ b/.github/workflows/run_build.yml @@ -12,7 +12,6 @@ jobs: config: - modern - legacy - - test steps: - name: Checkout uses: actions/checkout@v4 diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml index ac0e5d62..ade693c2 100644 --- a/.github/workflows/run_tests.yml +++ b/.github/workflows/run_tests.yml @@ -31,10 +31,7 @@ jobs: fail-fast: false matrix: test: ${{ fromJSON(needs.prepare.outputs.tests) }} - os: - - ubuntu-20.04 - # - windows-latest # doesn't work due to lack of nested virtualization on the runners, hopefully this will work one day - runs-on: ${{ matrix.os }} + runs-on: windows-latest steps: - name: Checkout uses: actions/checkout@v4 @@ -44,9 +41,13 @@ jobs: - name: Download Tarball ๐Ÿ“ฅ uses: actions/download-artifact@v4 with: - name: tarball-test + name: tarball-modern + + - name: Setup WSL ๐Ÿง + run: | + wsl --update + wsl --version - name: Execute Test ๐Ÿงช shell: pwsh - run: | - Invoke-Pester -Output Detailed ${{ matrix.test }} + run: Invoke-Pester -Output Detailed ${{ matrix.test }} diff --git a/.vscode/settings.json b/.vscode/settings.json index 218a47b5..b5cd76e0 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,12 +1,14 @@ { "rust-analyzer.linkedProjects": [ - "scripts/native-utils/Cargo.toml" + "utils/Cargo.toml" ], "workbench.colorCustomizations": { "commandCenter.border": "#e7e7e799", "sash.hoverBorder": "#6194da", "titleBar.activeBackground": "#3878d0", "titleBar.inactiveBackground": "#3878d099", + "titleBar.activeForeground": "#e7e7e7", + "titleBar.inactiveForeground": "#e7e7e799" }, "peacock.remoteColor": "#3878d0" } diff --git a/flake.nix b/flake.nix index 30988c05..521e8fbf 100644 --- a/flake.nix +++ b/flake.nix @@ -28,11 +28,22 @@ nixosConfigurations = let - initialConfig = { config, ... }: { + config = { legacy ? false }: { config, lib, pkgs, ... }: { wsl.enable = true; - + wsl.nativeSystemd = lib.mkIf legacy false; programs.bash.loginShellInit = "nixos-wsl-welcome"; - + systemd.tmpfiles.rules = + let + channels = pkgs.runCommand "default-channels" { } '' + mkdir -p $out + ln -s ${pkgs.path} $out/nixos + ln -s ${./.} $out/nixos-wsl + ''; + in + [ + "L /nix/var/nix/profiles/per-user/root/channels-1-link - - - - ${channels}" + "L /nix/var/nix/profiles/per-user/root/channels - - - - channels-1-link" + ]; system.stateVersion = config.system.nixos.release; }; in @@ -41,7 +52,7 @@ system = "x86_64-linux"; modules = [ self.nixosModules.default - initialConfig + (config { }) ]; }; @@ -49,33 +60,7 @@ system = "x86_64-linux"; modules = [ self.nixosModules.default - initialConfig - { wsl.nativeSystemd = false; } - ]; - }; - - test = nixpkgs.lib.nixosSystem { - system = "x86_64-linux"; - modules = [ - self.nixosModules.default - ({ config, pkgs, ... }: { - wsl.enable = true; - wsl.nativeSystemd = false; - - system.activationScripts.create-test-entrypoint.text = - let - syschdemdProxy = pkgs.writeShellScript "syschdemd-proxy" '' - shell=$(${pkgs.getent}/bin/getent passwd root | ${pkgs.coreutils}/bin/cut -d: -f7) - exec $shell $@ - ''; - in - '' - mkdir -p /bin - ln -sfn ${syschdemdProxy} /bin/syschdemd - ''; - - system.stateVersion = config.system.nixos.release; - }) + (config { legacy = true; }) ]; }; }; diff --git a/tests/README.md b/tests/README.md index 7c5eb920..89ee8b51 100644 --- a/tests/README.md +++ b/tests/README.md @@ -1,26 +1,20 @@ # Tests -This directory contains tests that are executed against a built NixOS-WSL "legacy" tarball. +This directory contains tests that are executed against a built NixOS-WSL tarball. The tests are written using the [Pester](https://pester.dev/) testing framework. ## Execute Tests -The tests can be executed on both Windows or Linux. - -### Windows +The tests can only be executed on Windows. Support for running the tests in an emulated WSL environment through docker has been removed. Make sure that you are able to run a distro in WSL2 before trying to run the tests. Please note that the tests are not compatible with Windows PowerShell, but require the new [PowerShell Core](https://apps.microsoft.com/store/detail/powershell/9MZ1SNWT0N5D?hl=en-us&gl=us). -### Linux - -Running the tests requires Docker and PowerShell to be installed on your system. Make sure that the user you are running the tests as has permissions to run docker containers and that it is possible to access the internet from inside docker containers. - ### Running the Tests If you haven't already, [install Pester](https://pester.dev/docs/introduction/installation/). -The tests require a "legacy" `nixos-wsl.tar.gz` to be present in the current working directory, which can be built with -`sudo nix run .#nixosConfigurations.legacy.config.system.build.tarballBuilder -- nixos-wsl.tar.gz`. +The tests require a "modern" `nixos-wsl.tar.gz` to be present in the current working directory, which can be built with +`sudo nix run .#nixosConfigurations.modern.config.system.build.tarballBuilder -- nixos-wsl.tar.gz`. Once everything is in place, run the test by running the following in PowerShell at the root of this repo: @@ -28,7 +22,6 @@ Once everything is in place, run the test by running the following in PowerShell Invoke-Pester -Output Detailed ./tests ``` - ## Writing Test Please refer to [the Pester documentation](https://pester.dev/docs/quick-start) on how to write new tests. @@ -42,10 +35,10 @@ BeforeAll { } ``` -- `Install-Distro`: Creates a new NixOS-WSL instance, automatically selecting the appropriate runtime (WSL or Docker) for the host OS. Returns a new `Distro` object +- `[Distro]::new()`: Creates a new NixOS-WSL instance. - A Distro object has the following methods: - - `Launch($command)`: Runs the specified command inside the container. Returns the command output - - `GetPath($path)`: Returns the path inside the container, that points to the specified file on the host. + - `Launch($command)`: Runs the specified command inside the distro. Returns the command output + - `GetPath($path)`: Returns the path inside the distro, that points to the specified file on the host. - `InstallConfig($path)`: Installs a nix-file as the systems `configuration.nix`. - - `Shutdown()`: End all processes running in the container - - `Uninstall()`: Stop and then delete the container from the system. This should be called in an AfterEach or AfterAll block, so that the test does not leave it on the system. + - `Shutdown()`: End all processes running in the distro + - `Uninstall()`: Stop and then delete the distro from the system. This should be called in an AfterEach or AfterAll block, so that the test does not leave it on the system. diff --git a/tests/basic-functionality.Tests.ps1 b/tests/basic-functionality.Tests.ps1 index 9459b15a..884ebad4 100644 --- a/tests/basic-functionality.Tests.ps1 +++ b/tests/basic-functionality.Tests.ps1 @@ -4,7 +4,7 @@ BeforeAll { Describe "Basic Functionality" { BeforeAll { - $distro = Install-Distro + $distro = [Distro]::new() } It "is possible to run a command in the container" { @@ -24,17 +24,17 @@ Describe "Basic Functionality" { } It "is possible to use nixos-rebuild" { - $distro.Launch("sudo nixos-rebuild switch") + $distro.Launch("sudo nixos-rebuild switch < /dev/null") $LASTEXITCODE | Should -Be 0 } It "is possible to run a command through nix-shell" { - $distro.Launch("nix-shell -p neofetch --command neofetch") + $distro.Launch("nix-shell -p hello --command hello") | Select-Object -Last 1 | Should -BeExactly "Hello, world!" $LASTEXITCODE | Should -Be 0 } It "is possible to run a command through nix run" { - $distro.Launch("nix --extra-experimental-features 'nix-command flakes' run nixpkgs#neofetch") + $distro.Launch("nix --extra-experimental-features 'nix-command flakes' run nixpkgs#hello") | Select-Object -Last 1 | Should -BeExactly "Hello, world!" $LASTEXITCODE | Should -Be 0 } diff --git a/tests/docker/docker-native.nix b/tests/docker/docker-native.nix index d6f76f04..d2fd4679 100644 --- a/tests/docker/docker-native.nix +++ b/tests/docker/docker-native.nix @@ -4,13 +4,8 @@ ]; wsl.enable = true; - wsl.nativeSystemd = false; users.users.nixos.extraGroups = [ "docker" ]; - virtualisation.docker = { - enable = true; - # Github Actions runners try to use aufs and fail if this is not set explicitly - daemon.settings."storage-driver" = "vfs"; - }; + virtualisation.docker.enable = true; } diff --git a/tests/docker/docker.Tests.ps1 b/tests/docker/docker.Tests.ps1 index 9ea46aa9..350ba433 100644 --- a/tests/docker/docker.Tests.ps1 +++ b/tests/docker/docker.Tests.ps1 @@ -4,7 +4,7 @@ BeforeAll { Describe "Docker (native)" { BeforeAll { - $distro = Install-Distro + $distro = [Distro]::new() try { $distro.InstallConfig("$PSScriptRoot/docker-native.nix") } @@ -15,18 +15,18 @@ Describe "Docker (native)" { } It "should be possible to run a docker container" { - $distro.Launch("docker run --rm -it hello-world") + $distro.Launch("docker run --rm -i hello-world") $LASTEXITCODE | Should -Be 0 } It "should still be possible to run a docker container after a restart" { $distro.Shutdown() - $distro.Launch("docker run --rm -it hello-world") + $distro.Launch("docker run --rm -i hello-world") $LASTEXITCODE | Should -Be 0 } It "should be possible to connect to the internet from a container" { - $distro.Launch("docker run --rm -it alpine wget -qO- http://www.msftconnecttest.com/connecttest.txt") | Select-Object -Last 1 | Should -BeExactly "Microsoft Connect Test" + $distro.Launch("docker run --rm -i alpine wget -qO- http://www.msftconnecttest.com/connecttest.txt") | Select-Object -Last 1 | Should -BeExactly "Microsoft Connect Test" $LASTEXITCODE | Should -Be 0 } @@ -37,7 +37,7 @@ Describe "Docker (native)" { $testfilename = "testfile" $testfile = "${testdir}/${testfilename}" $distro.Launch("echo $teststring > $testfile") - $distro.Launch("docker run --rm -it -v ${testdir}:/mnt alpine cat /mnt/${testfilename}") | Select-Object -Last 1 | Should -BeExactly $teststring + $distro.Launch("docker run --rm -i -v ${testdir}:/mnt alpine cat /mnt/${testfilename}") | Select-Object -Last 1 | Should -BeExactly $teststring $LASTEXITCODE | Should -Be 0 } diff --git a/tests/exit-codes.Tests.ps1 b/tests/exit-codes.Tests.ps1 index 8f8bae94..6f0f9300 100644 --- a/tests/exit-codes.Tests.ps1 +++ b/tests/exit-codes.Tests.ps1 @@ -4,7 +4,7 @@ BeforeAll { Describe "Exit Codes" { BeforeAll { - $distro = Install-Distro + $distro = [Distro]::new() } It "should return 0 when running true" { diff --git a/tests/lib/Dockerfile b/tests/lib/Dockerfile deleted file mode 100644 index e703915b..00000000 --- a/tests/lib/Dockerfile +++ /dev/null @@ -1,2 +0,0 @@ -FROM scratch -ADD nixos-wsl.tar.gz / diff --git a/tests/lib/lib.ps1 b/tests/lib/lib.ps1 index e3985c9c..9408109a 100644 --- a/tests/lib/lib.ps1 +++ b/tests/lib/lib.ps1 @@ -1,6 +1,9 @@ if ($PSVersionTable.PSEdition -ne 'Core') { throw "The tests are not compatible with Windows PowerShell, please use PowerShell Core instead" } +if ($IsWindows -eq $false) { + throw "Support for tests in an emulated WSL environment on Linux has been removed" +} function Remove-Escapes { param( @@ -15,13 +18,31 @@ function Remove-Escapes { # Implementation-independent base class class Distro { [string]$id + [string]$tempdir + + Distro() { + $tarball = $this.FindTarball() + + $this.id = $(New-Guid).ToString() + $this.tempdir = Join-Path $([System.IO.Path]::GetTempPath()) $this.id + New-Item -ItemType Directory $this.tempdir - [string]Launch() { - throw "Not implemented" + & wsl.exe --import $this.id $this.tempdir $tarball --version 2 | Write-Host + if ($LASTEXITCODE -ne 0) { + throw "Failed to import distro" + } + & wsl.exe --list -q | Should -Contain $this.id + } + + [Array]Launch([string]$command) { + Write-Host "> $command" + $result = @() + Invoke-Expression "wsl.exe -d $($this.id) --% $command" | Tee-Object -Variable result | Write-Host + return $result | Remove-Escapes } [string]GetPath([string]$path) { - throw "Not implemented" + return $this.Launch("wslpath $($path -replace "\\", "/")") | Select-Object -Last 1 } [string]FindTarball() { @@ -38,113 +59,16 @@ class Distro { Write-Host "Installing config: $path" # Copy the new config - $this.Launch("sudo cp $($this.GetPath($path)) /etc/nixos/configuration.nix") + $this.Launch("sudo cp -v $($this.GetPath($path)) /etc/nixos/configuration.nix") $LASTEXITCODE | Should -Be 0 # Rebuild - $this.Launch("sudo nixos-rebuild switch") + $this.Launch("sh -c 'sudo nixos-rebuild switch < /dev/null'") $LASTEXITCODE | Should -Be 0 Write-Host "Config installed successfully" } - [void]Shutdown() { - throw "Not implemented" - } - - [void]Uninstall() { - throw "Not implemented" - } -} - -# Emulates a WSL distro using a Docker container (for Linux hosts) -class DockerDistro : Distro { - static [string]$hostMount = "/mnt/c" - static [string]$imageName = "local:nixos-wsl" - - static [bool]$imageCreated = $false - - DockerDistro() { - $tarball = $this.FindTarball() - - if (!([DockerDistro]::imageCreated)) { - # Build docker image from the tarball - $tmpdir = $(mktemp -d) - Copy-Item $PSScriptRoot/Dockerfile $tmpdir - Copy-Item $tarball $tmpdir - docker build -t $([DockerDistro]::imageName) $tmpdir | Write-Host - Remove-Item $tmpdir -Recurse -Force - - [DockerDistro]::imageCreated = $true - } - - $this.id = $(New-Guid).ToString() - - docker run -di --privileged --volume "/:$([DockerDistro]::hostMount)" --name $this.id $([DockerDistro]::imageName) "/bin/sh" | Out-Null - if ($LASTEXITCODE -ne 0) { - throw "Failed to launch container" - } - - $this.Launch("sudo nix-channel --update") - } - - [Array]Launch([string]$command) { - Write-Host "> $command" - $result = @() - docker exec -t $this.id /bin/syschdemd -c $command | Tee-Object -Variable result | Write-Host - return $result | Remove-Escapes - } - - [string]GetPath([string]$path) { - return [DockerDistro]::hostMount + $(readlink -f $path) - } - - [void]Shutdown() { - docker restart $this.id # Restart instead of stop so that exec can still be used - if ($LASTEXITCODE -ne 0) { - throw "Failed to stop container" - } - } - - [void]Uninstall() { - docker rm -f $this.id - if ($LASTEXITCODE -ne 0) { - throw "Failed to remove container" - } - } -} - -# A real WSL distro (for Windows hosts) -class WslDistro : Distro { - [string]$tempdir - - WslDistro() { - $tarball = $this.FindTarball() - - $this.id = $(New-Guid).ToString() - $this.tempdir = Join-Path $([System.IO.Path]::GetTempPath()) $this.id - New-Item -ItemType Directory $this.tempdir - - & wsl.exe --import $this.id $this.tempdir $tarball --version 2 | Write-Host - if ($LASTEXITCODE -ne 0) { - throw "Failed to import distro" - } - & wsl.exe --list | Should -Contain $this.id - - $this.Launch("sudo nix-channel --update") - } - - [Array]Launch([string]$command) { - Write-Host "> $command" - $result = @() - & wsl.exe -d $this.id -e /bin/syschdemd -c $command | Tee-Object -Variable result | Write-Host - return $result | Remove-Escapes - } - - [string]GetPath([string]$path) { - return $this.Launch("wslpath $($path -replace "\\", "/")") | Select-Object -Last 1 - } - [void]Shutdown() { & wsl.exe -t $this.id if ($LASTEXITCODE -ne 0) { @@ -160,15 +84,3 @@ class WslDistro : Distro { Remove-Item $this.tempdir -Recurse -Force } } - -# Auto-select the implementation to use -function Install-Distro() { - if ($IsWindows) { - Write-Host "Detected Windows host, using WSL2" - return [WslDistro]::new() - } - else { - Write-Host "Detected Linux host, using Docker" - return [DockerDistro]::new() - } -} diff --git a/tests/login-shell/login-shell.Tests.ps1 b/tests/login-shell/login-shell.Tests.ps1 index 3aefbb83..5987979e 100644 --- a/tests/login-shell/login-shell.Tests.ps1 +++ b/tests/login-shell/login-shell.Tests.ps1 @@ -4,18 +4,30 @@ BeforeAll { Describe "Login Shell" { BeforeAll { - $distro = Install-Distro + $distro = [Distro]::new() } It "should start commands in a login shell" { - $distro.Launch("shopt -q login_shell") - $LASTEXITCODE | Should -Be 0 + # The echo should eat the \r PowerShell appends to stdin + Write-Host "> shopt login_shell" + Write-Output "shopt login_shell`necho " | wsl -d $distro.id | Tee-Object -Variable output | Write-Host + $output | Select-Object -Index ($output.Length - 2) | Should -Match "login_shell\s*on" } It "should be possible to access home manager sessionVariables" { $distro.InstallConfig("$PSScriptRoot/session-variables.nix") - $distro.Launch("echo \`$TEST_VARIABLE") | Select-Object -Last 1 | Should -BeExactly "THISISATESTSTRING" - $distro.Launch("echo \`$EDITOR") | Select-Object -Last 1 | Should -BeExactly "vim" + + # Session variable file should exist + $distro.Launch("test -f ~/.nix-profile/etc/profile.d/hm-session-vars.sh") + $LASTEXITCODE | Should -Be 0 + + Write-Host "> echo `$TEST_VARIABLE" + Write-Output "echo `$TEST_VARIABLE" | wsl -d $distro.id | Tee-Object -Variable output | Write-Host + $output | Select-Object -Last 1 | Should -BeExactly "THISISATESTSTRING" + + Write-Host "> echo `$EDITOR" + Write-Output "echo `$EDITOR" | wsl -d $distro.id | Tee-Object -Variable output | Write-Host + $output | Select-Object -Last 1 | Should -BeExactly "vim" } AfterAll { diff --git a/tests/login-shell/session-variables.nix b/tests/login-shell/session-variables.nix index c3cca3c7..6829bbfb 100644 --- a/tests/login-shell/session-variables.nix +++ b/tests/login-shell/session-variables.nix @@ -9,7 +9,6 @@ in ]; wsl.enable = true; - wsl.nativeSystemd = false; home-manager.users.nixos = { ... }: { home = { diff --git a/tests/shells.Tests.ps1 b/tests/shells.Tests.ps1 index 5123e53d..31bc99ea 100644 --- a/tests/shells.Tests.ps1 +++ b/tests/shells.Tests.ps1 @@ -4,9 +4,9 @@ BeforeAll { Describe "Shells" { BeforeAll { - $distro = Install-Distro + $distro = [Distro]::new() - function Add-ShellTest([string]$package, [string]$executable) { + function Add-ShellTest([string]$package, [string]$executable, [string]$command) { $temp = New-TemporaryFile @" { pkgs, lib, config, options, ... }: @@ -18,7 +18,6 @@ Describe "Shells" { config = mkMerge [ { wsl.enable = true; - wsl.nativeSystemd = false; users.users.nixos.shell = pkgs.$package; } (optionalAttrs (hasAttrByPath ["programs" "$package" "enable"] options) { @@ -29,51 +28,44 @@ Describe "Shells" { "@ > $temp $distro.InstallConfig($temp) Remove-Item $temp - $distro.Launch("echo `$SHELL") | Select-Object -Last 1 | Should -BeExactly "/run/current-system/sw/bin/$executable" + $distro.Launch($command) | Select-Object -Last 1 | Should -BeExactly "/run/current-system/sw/bin/$executable" $LASTEXITCODE | Should -Be 0 } } It "should be possible to use bash" { - Add-ShellTest "bashInteractive" "bash" + Add-ShellTest "bashInteractive" "bash" "echo `$SHELL" } It "should be possible to use zsh" { - Add-ShellTest "zsh" "zsh" + Add-ShellTest "zsh" "zsh" "echo `$SHELL" } It "should be possible to use dash" { - Add-ShellTest "dash" "dash" + Add-ShellTest "dash" "dash" "echo `$SHELL" } It "should be possible to use ksh" { - Add-ShellTest "ksh" "ksh" + Add-ShellTest "ksh" "ksh" "echo `$SHELL" } It "should be possible to use mksh" { - Add-ShellTest "mksh" "mksh" + Add-ShellTest "mksh" "mksh" "echo `$SHELL" } It "should be possible to use yash" { - Add-ShellTest "yash" "yash" + Add-ShellTest "yash" "yash" "echo `$SHELL" } It "should be possible to use fish" { - Add-ShellTest "fish" "fish" + Add-ShellTest "fish" "fish" "echo `$SHELL" } - if (!$IsWindows) { - # Skip on windows, because it just doesn't work for some reason - It "should be possible to use PowerShell" { - Add-ShellTest "powershell" "pwsh" - } + It "should be possible to use PowerShell" { + Add-ShellTest "powershell" "pwsh" "Write-Output `$env:SHELL" } It "should be possible to use nushell" { - $distro.Launch("mkdir -p /home/nixos/.config/nushell") - $LASTEXITCODE | Should -Be 0 - $distro.Launch("touch /home/nixos/.config/nushell/env.nu /home/nixos/.config/nushell/config.nu") - $LASTEXITCODE | Should -Be 0 - Add-ShellTest "nushell" "nu" + Add-ShellTest "nushell" "nu" "echo `$env.SHELL" } It "should be possible to use xonsh" { - Add-ShellTest "xonsh" "xonsh" + Add-ShellTest "xonsh" "xonsh" "echo `$SHELL" } - # Do bash last so every shell was used to run InstallConfig + # Do bash again so every shell was used to run InstallConfig It "should be possible to go back to bash" { - Add-ShellTest "bashInteractive" "bash" + Add-ShellTest "bashInteractive" "bash" "echo `$SHELL" } AfterAll { diff --git a/tests/systemd-services.Tests.ps1 b/tests/systemd-services.Tests.ps1 index 2ba9eda0..f87e7786 100644 --- a/tests/systemd-services.Tests.ps1 +++ b/tests/systemd-services.Tests.ps1 @@ -4,7 +4,7 @@ BeforeAll { Describe "Systemd Services" { BeforeAll { - $distro = Install-Distro + $distro = [Distro]::new() } It "should boot" { diff --git a/tests/systemd-user.Tests.ps1 b/tests/systemd-user.Tests.ps1 index 63eabd96..b2c2cf79 100644 --- a/tests/systemd-user.Tests.ps1 +++ b/tests/systemd-user.Tests.ps1 @@ -4,10 +4,14 @@ BeforeAll { Describe "Systemd User Daemon" { BeforeAll { - $distro = Install-Distro + $distro = [Distro]::new() } It "should be possible to connect to the user daemon" { + # Boot the distro + $distro.Launch("true") + Start-Sleep 10 # Give the user daemon time to start + $distro.Launch("systemctl --user status --no-pager") $LASTEXITCODE | Should -Be 0 } diff --git a/tests/username-change/username-change.Tests.ps1 b/tests/username-change/username-change.Tests.ps1 index dd10173e..1d106b19 100644 --- a/tests/username-change/username-change.Tests.ps1 +++ b/tests/username-change/username-change.Tests.ps1 @@ -4,12 +4,28 @@ BeforeAll { Describe "Login Shell" { BeforeAll { - $distro = Install-Distro + $distro = [Distro]::new() } It "should be possible to change the username" { $distro.Launch("whoami") | Select-Object -Last 1 | Should -BeExactly "nixos" - $distro.InstallConfig("$PSScriptRoot/username-change.nix") + $config = "$PSScriptRoot/username-change.nix" + + # Copy the new config + $distro.Launch("sudo cp -v $($distro.GetPath($config)) /etc/nixos/configuration.nix") + $LASTEXITCODE | Should -Be 0 + + # Rebuild (boot not switch!) + $distro.Launch("sh -c 'sudo nixos-rebuild boot < /dev/null'") + $LASTEXITCODE | Should -Be 0 + + # Shutdown + $distro.Shutdown() + + # Run the activation scripts once + wsl -d $distro.id --user root exit + $distro.Shutdown() + $distro.Launch("whoami") | Select-Object -Last 1 | Should -BeExactly "different-name" } diff --git a/tests/username-change/username-change.nix b/tests/username-change/username-change.nix index fc4609ff..32d7e1e0 100644 --- a/tests/username-change/username-change.nix +++ b/tests/username-change/username-change.nix @@ -4,6 +4,5 @@ ]; wsl.enable = true; - wsl.nativeSystemd = false; wsl.defaultUser = "different-name"; }