diff options
| author | nzbr <mail@nzbr.de> | 2023-01-28 07:03:37 +0100 |
|---|---|---|
| committer | nzbr <mail@nzbr.de> | 2023-01-28 07:03:37 +0100 |
| commit | 19bc20188db046664dafcf717fc53b9b513bf64b (patch) | |
| tree | 90db259f44169ea832e8b2e5c21e4d8c32d0c3c7 | |
| parent | da9c1be5bc750f88730a1511fe973011da125064 (diff) | |
Add tests for changing username and diverging user attr and name
| -rw-r--r-- | checks/side-effects.nix | 4 | ||||
| -rw-r--r-- | checks/username.nix | 29 | ||||
| -rw-r--r-- | flake.nix | 1 | ||||
| -rw-r--r-- | modules/wsl-distro.nix | 3 | ||||
| -rw-r--r-- | tests/username-change/username-change.Tests.ps1 | 19 | ||||
| -rw-r--r-- | tests/username-change/username-change.nix | 6 |
6 files changed, 60 insertions, 2 deletions
diff --git a/checks/side-effects.nix b/checks/side-effects.nix index 84b8866..a3e0236 100644 --- a/checks/side-effects.nix +++ b/checks/side-effects.nix @@ -1,7 +1,7 @@ # Test that including the WSL module in a config does not change anything without enabling it -{ inputs -, system +{ system +, inputs , emptyFile , ... }: diff --git a/checks/username.nix b/checks/username.nix new file mode 100644 index 0000000..53337c7 --- /dev/null +++ b/checks/username.nix @@ -0,0 +1,29 @@ +{ system +, inputs +, runCommand +, ... +}: + +let + baseModule = { ... }: { + imports = [ ../configuration.nix ]; + + wsl.enable = true; + }; + changedUsername = { lib, ... }: { + wsl.defaultUser = lib.mkForce "different"; + }; + changedUserAttr = { config, lib, ... }: { + wsl.defaultUser = lib.mkForce "userattr"; + users.users.${config.wsl.defaultUser}.name = "username"; + }; + buildConfig = module: (inputs.nixpkgs.lib.nixosSystem { + inherit system; + modules = [ baseModule module ]; + }).config.system.build.toplevel; +in +runCommand "different=usernames" { } '' + mkdir -p $out + ln -s ${buildConfig changedUsername} $out/changedUsername + ln -s ${buildConfig changedUserAttr} $out/changedUserAttr +'' @@ -55,6 +55,7 @@ nixpkgs-fmt = pkgs.callPackage ./checks/nixpkgs-fmt.nix args; shfmt = pkgs.callPackage ./checks/shfmt.nix args; side-effects = pkgs.callPackage ./checks/side-effects.nix args; + username = pkgs.callPackage ./checks/username.nix args; }; packages.staticShim = pkgs.pkgsStatic.callPackage ./scripts/native-systemd-shim/shim.nix { }; diff --git a/modules/wsl-distro.nix b/modules/wsl-distro.nix index 37b0dec..43d2bc6 100644 --- a/modules/wsl-distro.nix +++ b/modules/wsl-distro.nix @@ -104,6 +104,9 @@ with lib; { ln -sf ${bash}/bin/sh /bin/sh ln -sf ${pkgs.util-linux}/bin/mount /bin/mount ''; + update-entrypoint.text = '' + ln -sf ${config.users.users.root.shell} /nix/nixos-wsl/entrypoint + ''; }; systemd = { diff --git a/tests/username-change/username-change.Tests.ps1 b/tests/username-change/username-change.Tests.ps1 new file mode 100644 index 0000000..dd10173 --- /dev/null +++ b/tests/username-change/username-change.Tests.ps1 @@ -0,0 +1,19 @@ +BeforeAll { + . $PSScriptRoot/../lib/lib.ps1 +} + +Describe "Login Shell" { + BeforeAll { + $distro = Install-Distro + } + + It "should be possible to change the username" { + $distro.Launch("whoami") | Select-Object -Last 1 | Should -BeExactly "nixos" + $distro.InstallConfig("$PSScriptRoot/username-change.nix") + $distro.Launch("whoami") | Select-Object -Last 1 | Should -BeExactly "different-name" + } + + AfterAll { + $distro.Uninstall() + } +} diff --git a/tests/username-change/username-change.nix b/tests/username-change/username-change.nix new file mode 100644 index 0000000..77a2cdd --- /dev/null +++ b/tests/username-change/username-change.nix @@ -0,0 +1,6 @@ +{ pkgs, lib, ... }: +{ + imports = [ ./base.nix ]; + + wsl.defaultUser = lib.mkForce "different-name"; +} |
