From 8e3f467b3a40bec98faf5c326cbbb20642ca39b7 Mon Sep 17 00:00:00 2001 From: Mikael Voss Date: Fri, 23 Aug 2024 09:18:16 +0200 Subject: [PATCH] Add scripts to run headless Wayland sessions --- package/wayland-headless/package.nix | 36 ++++++++++++++++++++++++++++ package/wayland-headless/wl-run.sh | 11 +++++++++ package/wayland-headless/xvfb-run.sh | 12 ++++++++++ 3 files changed, 59 insertions(+) create mode 100644 package/wayland-headless/package.nix create mode 100644 package/wayland-headless/wl-run.sh create mode 100644 package/wayland-headless/xvfb-run.sh diff --git a/package/wayland-headless/package.nix b/package/wayland-headless/package.nix new file mode 100644 index 0000000..7c42ef6 --- /dev/null +++ b/package/wayland-headless/package.nix @@ -0,0 +1,36 @@ +{ ... }: { stdenvNoCC, lib, shellcheck-minimal, runtimeShell, cage }: + +stdenvNoCC.mkDerivation { + name = "wayland-headless"; + + nativeInstallCheckInputs = [ shellcheck-minimal ]; + + dontUnpack = true; + dontConfigure = true; + dontBuild = true; + doInstallCheck = true; + + installPhase = '' + mkdir -p "$out/bin" + + substitute ${./wl-run.sh} "$out/bin/wl-run" \ + --subst-var-by runtimeShell ${lib.escapeShellArg runtimeShell} \ + --subst-var-by cage ${lib.escapeShellArg cage} + + substitute ${./xvfb-run.sh} "$out/bin/xvfb-run" \ + --subst-var-by runtimeShell ${lib.escapeShellArg runtimeShell} \ + --subst-var out + + chmod +x "$out/bin/"{wl-run,xvfb-run} + ''; + + installCheckPhase = '' + runHook preInstallCheck + shellcheck "$out/bin/"{wl-run,xvfb-run} + runHook postInstallCheck + ''; + + meta = { + inherit (cage.meta) platforms; + }; +} diff --git a/package/wayland-headless/wl-run.sh b/package/wayland-headless/wl-run.sh new file mode 100644 index 0000000..6ae0182 --- /dev/null +++ b/package/wayland-headless/wl-run.sh @@ -0,0 +1,11 @@ +#!@runtimeShell@ + +set -o errexit +set -o nounset +set -o pipefail + +WLR_BACKENDS=headless \ +WLR_LIBINPUT_NO_DEVICES=1 \ +WLR_RENDERER=pixman \ +XDG_RUNTIME_DIR="$(mktemp -d)" \ + exec '@cage@/bin/cage' -- "$@" diff --git a/package/wayland-headless/xvfb-run.sh b/package/wayland-headless/xvfb-run.sh new file mode 100644 index 0000000..a5a71e7 --- /dev/null +++ b/package/wayland-headless/xvfb-run.sh @@ -0,0 +1,12 @@ +#!@runtimeShell@ + +set -o errexit +set -o nounset +set -o pipefail + +# Discard all options +while [[ "$1" =~ ^- ]]; do + shift +done + +exec '@out@/bin/wl-run' "$@"