mirror of
https://github.com/nix-community/NixOS-WSL.git
synced 2026-11-07 14:59:35 +00:00
Add tests for changing username and diverging user attr and name
This commit is contained in:
@@ -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
|
||||
, ...
|
||||
}:
|
||||
|
||||
@@ -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 { };
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
Reference in New Issue
Block a user