From c09d68aeb4a7143aab54ff1409681f6b240eb85e Mon Sep 17 00:00:00 2001 From: Sandro Date: Mon, 28 Nov 2022 10:23:23 +0100 Subject: [PATCH 1/6] Disable powerManagement (#160) --- modules/wsl-distro.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/wsl-distro.nix b/modules/wsl-distro.nix index a5b3181d..a88b9840 100644 --- a/modules/wsl-distro.nix +++ b/modules/wsl-distro.nix @@ -76,6 +76,8 @@ with lib; { # Otherwise WSL fails to login as root with "initgroups failed 5" users.users.root.extraGroups = [ "root" ]; + powerManagement.enable = false; + security.sudo.wheelNeedsPassword = mkDefault false; # The default user will not have a password by default system.activationScripts = { From 2bb34d04bc866ae4cecd5d23d7fda36bb4832f60 Mon Sep 17 00:00:00 2001 From: Sandro Date: Mon, 28 Nov 2022 10:23:34 +0100 Subject: [PATCH 2/6] Disable timesynced (#159) * Disable timesynced * Add comments --- modules/wsl-distro.nix | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/wsl-distro.nix b/modules/wsl-distro.nix index a88b9840..9811c701 100644 --- a/modules/wsl-distro.nix +++ b/modules/wsl-distro.nix @@ -101,12 +101,16 @@ with lib; { systemd = { # Disable systemd units that don't make sense on WSL services = { + # no virtual console to switch to "serial-getty@ttyS0".enable = false; "serial-getty@hvc0".enable = false; "getty@tty1".enable = false; "autovt@".enable = false; firewall.enable = false; systemd-resolved.enable = false; + # system clock cannot be changed + systemd-timesyncd.enable = false; + # no udev devices can be attached systemd-udevd.enable = false; }; From 7578743a71b79fa3a2bd21cd7a1eb703c447cfe0 Mon Sep 17 00:00:00 2001 From: nzbr Date: Thu, 1 Dec 2022 01:49:46 +0100 Subject: [PATCH 3/6] Fix setting custom nameservers through networking.nameservers (#157) * fix: allow setting DNS servers through networking.nameservers * fix: warnings * Update modules/wsl-distro.nix Co-authored-by: Sandro * add setting names to warning output Co-authored-by: Sandro --- modules/wsl-distro.nix | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/modules/wsl-distro.nix b/modules/wsl-distro.nix index 9811c701..da3cd424 100644 --- a/modules/wsl-distro.nix +++ b/modules/wsl-distro.nix @@ -51,11 +51,15 @@ with lib; { environment = { - etc = { - # DNS settings are managed by WSL - hosts.enable = !config.wsl.wslConf.network.generateHosts; - "resolv.conf".enable = !config.wsl.wslConf.network.generateResolvConf; - }; + # Only set the options if the files are managed by WSL + etc = mkMerge [ + (mkIf config.wsl.wslConf.network.generateHosts { + hosts.enable = false; + }) + (mkIf config.wsl.wslConf.network.generateResolvConf { + "resolv.conf".enable = false; + }) + ]; systemPackages = [ (pkgs.runCommand "wslpath" { } '' @@ -126,9 +130,17 @@ with lib; { # Start a systemd user session when starting a command through runuser security.pam.services.runuser.startSession = true; - warnings = (optional (config.systemd.services.systemd-resolved.enable && config.wsl.wslConf.network.generateResolvConf) - "systemd-resolved is enabled, but resolv.conf is managed by WSL" - ); + warnings = flatten [ + (optional (config.services.resolved.enable && config.wsl.wslConf.network.generateResolvConf) + "systemd-resolved is enabled, but resolv.conf is managed by WSL (wsl.wslConf.network.generateResolvConf)" + ) + (optional ((length config.networking.nameservers) > 0 && config.wsl.wslConf.network.generateResolvConf) + "custom nameservers are set (networking.nameservers), but resolv.conf is managed by WSL (wsl.wslConf.network.generateResolvConf)" + ) + (optional ((length config.networking.nameservers) == 0 && !config.services.resolved.enable && !config.wsl.wslConf.network.generateResolvConf) + "resolv.conf generation is turned off (wsl.wslConf.network.generateResolvConf), but no other nameservers are configured (networking.nameservers)" + ) + ]; } (mkIf (!cfg.nativeSystemd) { users.users.root.shell = "${syschdemd}/bin/syschdemd"; From 928b293f0b456c0c76514e340395824147d9632a Mon Sep 17 00:00:00 2001 From: Sandro Date: Thu, 1 Dec 2022 01:50:33 +0100 Subject: [PATCH 4/6] Fix permissions for files in /dev/pts (#166) The pts should have $USER:tty permissions, not root:tty. This broke gpg with the following not very helpful error message: gpg: signing failed: Permission denied --- scripts/syschdemd.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/syschdemd.sh b/scripts/syschdemd.sh index a28ffccf..71391c75 100644 --- a/scripts/syschdemd.sh +++ b/scripts/syschdemd.sh @@ -134,7 +134,7 @@ main() { --setenv=WSLPATH="$(clean_wslpath)" \ --working-directory="$PWD" \ --machine=.host \ - "$(which runuser)" -u @username@ -- /bin/sh -c "$exportCmd; source /etc/set-environment; exec $command" + "$(which runuser)" --pty -u @username@ -- /bin/sh -c "$exportCmd; source /etc/set-environment; exec $command" } main "$@" From fd921902f4b0dbdd21f5fd7c7f61abe8b8e8919a Mon Sep 17 00:00:00 2001 From: Sandro Date: Thu, 1 Dec 2022 01:51:52 +0100 Subject: [PATCH 5/6] Fix sudo ssh with jumpHost (#167) --- scripts/syschdemd.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/syschdemd.sh b/scripts/syschdemd.sh index 71391c75..19a9ca87 100644 --- a/scripts/syschdemd.sh +++ b/scripts/syschdemd.sh @@ -111,7 +111,7 @@ main() { # If we're executed from inside the container, e.g. sudo if is_in_container; then - exec $command + eval $command fi # If we are currently in /root, this is probably because the directory that WSL was started is inaccessible From 522219248de4b5876f18e47f34d979dd9f4fcbdc Mon Sep 17 00:00:00 2001 From: nzbr Date: Thu, 1 Dec 2022 03:59:52 +0100 Subject: [PATCH 6/6] Fix tests (#173) * debug * try loading modules explicitly * just use ubuntu-20.04 for now --- .github/workflows/main.yml | 2 +- tests/docker/docker.Tests.ps1 | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2a66281e..cfe368a4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -85,7 +85,7 @@ jobs: matrix: test: ${{ fromJSON(needs.find-tests.outputs.tests) }} os: - - ubuntu-latest + - 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 }} steps: diff --git a/tests/docker/docker.Tests.ps1 b/tests/docker/docker.Tests.ps1 index 666d0992..fefff074 100644 --- a/tests/docker/docker.Tests.ps1 +++ b/tests/docker/docker.Tests.ps1 @@ -5,7 +5,13 @@ BeforeAll { Describe "Docker (native)" { BeforeAll { $distro = Install-Distro - $distro.InstallConfig("$PSScriptRoot/docker-native.nix") + try { + $distro.InstallConfig("$PSScriptRoot/docker-native.nix") + } + catch { + $distro.Launch("sudo journalctl --no-pager -u docker.service") + throw $_ + } } It "should be possible to run a docker container" {