Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions checks/side-effects.nix
Original file line number Diff line number Diff line change
@@ -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
, ...
}:
Expand Down
29 changes: 29 additions & 0 deletions checks/username.nix
Original file line number Diff line number Diff line change
@@ -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 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 { };
Expand Down
5 changes: 4 additions & 1 deletion modules/wsl-distro.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -153,7 +156,7 @@ with lib; {
})
(mkIf cfg.nativeSystemd {
wsl.wslConf = {
user.default = cfg.defaultUser;
user.default = config.users.users.${cfg.defaultUser}.name;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, probably because my user.users attr matches name.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing the username has always worked fine, but having different username and attr hasn't

boot.systemd = true;
};

Expand Down
19 changes: 19 additions & 0 deletions tests/username-change/username-change.Tests.ps1
Original file line number Diff line number Diff line change
@@ -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()
}
}
6 changes: 6 additions & 0 deletions tests/username-change/username-change.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{ pkgs, lib, ... }:
{
imports = [ ./base.nix ];

wsl.defaultUser = lib.mkForce "different-name";
}