Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sx: add desktop file and providedSessions #333678

Merged
merged 8 commits into from
Aug 14, 2024
Merged
47 changes: 35 additions & 12 deletions nixos/modules/services/x11/display-managers/sx.nix
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
{ config, lib, pkgs, ... }:
{
config,
lib,
pkgs,
...
}:

with lib;
let
cfg = config.services.xserver.displayManager.sx;

let cfg = config.services.xserver.displayManager.sx;

in {
in
{
options = {
services.xserver.displayManager.sx = {
enable = mkEnableOption "sx pseudo-display manager" // {
enable = lib.mkEnableOption "" // {
description = ''
Whether to enable the "sx" pseudo-display manager, which allows users
to start manually via the "sx" command from a vt shell. The X server
Expand All @@ -19,16 +24,34 @@ in {
dependency.
'';
};

addAsSession = lib.mkEnableOption "" // {
description = ''
Whether to add sx as a display manager session. Keep in mind that sx
expects to be run from a TTY, so it may not work in your display
manager.
'';
};

package = lib.mkPackageOption pkgs "sx" { };
};
};

config = mkIf cfg.enable {
environment.systemPackages = [ pkgs.sx ];
services.xserver = {
exportConfiguration = true;
logFile = mkDefault null;
config = lib.mkIf cfg.enable {
environment.systemPackages = [ cfg.package ];

services = {
displayManager.sessionPackages = lib.optionals cfg.addAsSession [ cfg.package ];

xserver = {
exportConfiguration = true;
logFile = lib.mkDefault null;
};
};
};

meta.maintainers = with maintainers; [ figsoda ];
meta.maintainers = with lib.maintainers; [
figsoda
thiagokokada
];
}
1 change: 1 addition & 0 deletions nixos/tests/all-tests.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 {};
Expand Down
63 changes: 63 additions & 0 deletions nixos/tests/sx.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import ./make-test-python.nix (
{ pkgs, lib, ... }:
{
name = "sx";
meta.maintainers = with lib.maintainers; [
figsoda
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@figsoda I added you as a maintainer for this test since you also are a maintainer of the module, but I can remove you if you don't want.

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)
'';
}
)
48 changes: 35 additions & 13 deletions pkgs/by-name/sx/sx/package.nix
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
{ lib
, stdenvNoCC
, fetchFromGitHub
, patsh
, xorg
{
lib,
stdenvNoCC,
fetchFromGitHub,
makeDesktopItem,
patsh,
xorg,
nixosTests,
}:

stdenvNoCC.mkDerivation rec {
stdenvNoCC.mkDerivation (finalAttrs: {
pname = "sx";
version = "3.0";

src = fetchFromGitHub {
owner = "earnestly";
repo = pname;
rev = version;
repo = "sx";
rev = finalAttrs.version;
hash = "sha256-hKoz7Kuus8Yp7D0F05wCOQs6BvV0NkRM9uUXTntLJxQ=";
};

Expand All @@ -27,14 +30,33 @@ stdenvNoCC.mkDerivation rec {

postInstall = ''
patsh -f $out/bin/sx -s ${builtins.storeDir}

install -Dm755 -t $out/share/xsessions ${
thiagokokada marked this conversation as resolved.
Show resolved Hide resolved
makeDesktopItem {
name = "sx";
desktopName = "sx";
comment = "Start a xorg server";
exec = "sx";
}
}/share/applications/sx.desktop
'';

meta = with lib; {
passthru = {
providedSessions = [ "sx" ];
tests = {
inherit (nixosTests) sx;
};
};

meta = {
description = "Simple alternative to both xinit and startx for starting a Xorg server";
homepage = "https://github.com/earnestly/sx";
license = licenses.mit;
license = lib.licenses.mit;
mainProgram = "sx";
maintainers = with maintainers; [ figsoda thiagokokada ];
platforms = platforms.linux;
maintainers = with lib.maintainers; [
figsoda
thiagokokada
];
platforms = lib.platforms.linux;
};
}
})