Add tests for changing username and diverging user attr and name

This commit is contained in:
nzbr
2023-01-28 07:03:37 +01:00
parent da9c1be5bc
commit 19bc20188d
6 changed files with 60 additions and 2 deletions
+2 -2
View File
@@ -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
, ...
}:
+29
View File
@@ -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
''
+1
View File
@@ -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 { };
+3
View File
@@ -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 = {
@@ -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()
}
}
@@ -0,0 +1,6 @@
{ pkgs, lib, ... }:
{
imports = [ ./base.nix ];
wsl.defaultUser = lib.mkForce "different-name";
}