diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index 12f8954c4040..413736ab2544 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -925,6 +925,7 @@ in { swayfx = handleTest ./swayfx.nix {}; switchTest = handleTest ./switch-test.nix { ng = false; }; switchTestNg = handleTest ./switch-test.nix { ng = true; }; + sx = handleTest ./sx.nix {}; sympa = handleTest ./sympa.nix {}; syncthing = handleTest ./syncthing.nix {}; syncthing-no-settings = handleTest ./syncthing-no-settings.nix {}; diff --git a/nixos/tests/sx.nix b/nixos/tests/sx.nix new file mode 100644 index 000000000000..1cdc4858cf00 --- /dev/null +++ b/nixos/tests/sx.nix @@ -0,0 +1,63 @@ +import ./make-test-python.nix ( + { pkgs, lib, ... }: + { + name = "sx"; + meta.maintainers = with lib.maintainers; [ + figsoda + thiagokokada + ]; + + nodes.machine = + { ... }: + { + imports = [ ./common/user-account.nix ]; + + environment.systemPackages = with pkgs; [ icewm ]; + + services.getty.autologinUser = "alice"; + + services.xserver = { + enable = true; + displayManager.sx.enable = true; + }; + + # Create sxrc file on login and start sx + programs.bash.loginShellInit = + # bash + '' + mkdir -p "$HOME/.config/sx" + echo 'exec icewm' > "$HOME/.config/sx/sxrc" + chmod +x "$HOME/.config/sx/sxrc" + + sx + ''; + }; + + testScript = + { nodes, ... }: + let + user = nodes.machine.users.users.alice; + in + # python + '' + start_all() + + machine.wait_for_unit("multi-user.target") + + xauthority = "${user.home}/.local/share/sx/xauthority" + machine.wait_for_file(xauthority) + machine.succeed(f"xauth merge {xauthority}") + + def icewm_is_visible(_last_try: bool) -> bool: + # sx will set DISPLAY as the TTY number we started, in this case + # TTY1: + # https://github.com/Earnestly/sx/blob/master/sx#L41. + # We can't use `machine.wait_for_window` here since we are running + # X as alice and not root. + return "IceWM" in machine.succeed("DISPLAY=:1 xwininfo -root -tree") + + # Adding a retry logic to increase reliability + retry(icewm_is_visible) + ''; + } +) diff --git a/pkgs/by-name/sx/sx/package.nix b/pkgs/by-name/sx/sx/package.nix index 09e69728426f..5bbb60e52aba 100644 --- a/pkgs/by-name/sx/sx/package.nix +++ b/pkgs/by-name/sx/sx/package.nix @@ -5,6 +5,7 @@ makeDesktopItem, patsh, xorg, + nixosTests, }: stdenvNoCC.mkDerivation (finalAttrs: { @@ -40,7 +41,12 @@ stdenvNoCC.mkDerivation (finalAttrs: { }/share/applications/sx.desktop ''; - passthru.providedSessions = [ "sx" ]; + passthru = { + providedSessions = [ "sx" ]; + tests = { + inherit (nixosTests) sx; + }; + }; meta = { description = "Simple alternative to both xinit and startx for starting a Xorg server";