Skip to content

Commit

Permalink
feat(vine): begin implementation of wayland support
Browse files Browse the repository at this point in the history
  • Loading branch information
HoKim98 committed Nov 4, 2024
1 parent 75432da commit ec854fd
Show file tree
Hide file tree
Showing 13 changed files with 187 additions and 90 deletions.
18 changes: 17 additions & 1 deletion templates/vine/desktop/Dockerfile.ubuntu
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ ARG USER_UID

ENV SHELL="${USER_SHELL}"
ENV USER_SHELL="${USER_SHELL}"
ENV XDG_RUNTIME_DIR="/run/user/${USER_UID}"

# Package Manager Configuration
ARG DEBIAN_FRONTEND='noninteractive'
Expand All @@ -37,6 +38,7 @@ STOPSIGNAL SIGRTMIN+3
WORKDIR /root/
ENTRYPOINT [ "/usr/bin/env" ]
CMD [ "/usr/bin/systemctl", "init", "vine-desktop.service", "--user" ]
ENV NVIDIA_DRIVER_CAPABILITIES="all"

# Volumes Configuration
## home.user
Expand Down Expand Up @@ -331,6 +333,7 @@ RUN apt-get update && apt-get install -y \
libvulkan1 \
mesa-utils \
vulkan-icd \
vulkan-tools \
# Core (Audio/PipeWire)
libldacbt-abr2 libldacbt-enc2 \
libpipewire-0.3-common \
Expand Down Expand Up @@ -362,6 +365,13 @@ RUN apt-get update && apt-get install -y \
python3-yaml \
# Core (Scheduling)
schedtool \
# Core (Wayland)
wayland-protocols \
# Core (Wayland RDP)
winpr-utils \
# Core (Wayland Server)
weston \
xwayland \
# Core (X11)
dbus-x11 \
wmctrl \
Expand Down Expand Up @@ -461,6 +471,9 @@ RUN apt-get update && apt-get install -y \
&& rm -f /etc/fonts/conf.d/65-nonlatin.conf \
# Remove conflicted repositories
&& rm -f /etc/apt/sources.list.d/vscode.list \
# X11 Configuration
&& mkdir -p /tmp/.X11-unix \
&& chmod 777 /tmp/.X11-unix \
# Cleanup
&& apt-get clean all \
&& rm -rf /var/lib/apt/lists/*
Expand Down Expand Up @@ -686,6 +699,9 @@ RUN /sbin/ldconfig.real \
&& useradd -u "${USER_UID}" -g "${USER_GID}" -G "audio,cdrom,input,render,video" \
-s "/bin/${USER_SHELL}" -m -o "${USER_NAME}" \
&& printf "${USER_UID}:2001:65535" > /etc/subuid \
&& printf "${USER_GID}:2001:65535" > /etc/subgid
&& printf "${USER_GID}:2001:65535" > /etc/subgid \
&& mkdir -p "${XDG_RUNTIME_DIR}" \
&& chmod 700 "${XDG_RUNTIME_DIR}" \
&& chown "${USER_UID}:${USER_GID}" "${XDG_RUNTIME_DIR}"
USER "${USER_NAME}"
WORKDIR "/home/${USER_NAME}"
18 changes: 9 additions & 9 deletions templates/vine/desktop/apt/keyrings/kubernetes.gpg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v2.0.15 (GNU/Linux)
Version: GnuPG v1.4.5 (GNU/Linux)

mQENBGMHoXcBCADukGOEQyleViOgtkMVa7hKifP6POCTh+98xNW4TfHK/nBJN2sm
u4XaiUmtB9UuGt9jl8VxQg4hOMRf40coIwHsNwtSrc2R9v5Kgpvcv537QVIigVHH
Expand All @@ -8,13 +8,13 @@ qmREN+3Y9+5VcRZvQHeyBxCG+hdUGE740ixgnY2gSqZ/J4YeQntQ6pMUEhT6pbaE
10q2HUierj/im0V+ZUdCh46Lk/Rdfa5ZKlqYOiA2iN1coDPIdyqKavcdfPqSraKF
Lan2KLcZcgTxP+0+HfzKefvGEnZa11civbe9ABEBAAG0PmlzdjprdWJlcm5ldGVz
IE9CUyBQcm9qZWN0IDxpc3Y6a3ViZXJuZXRlc0BidWlsZC5vcGVuc3VzZS5vcmc+
iQE+BBMBCAAoBQJjB6F3AhsDBQkEHrAABgsJCAcDAgYVCAIJCgsEFgIDAQIeAQIX
gAAKCRAjRlTamilkNhnRCADud9iv+2CUtJGyZhhdzzd55wRKvHGmSY4eIAEKChmf
1+BHwFnzBzbdNtnglY2xSATqKIWikzXI1stAwi8qR0dK32CS+ofMS6OUklm26Yd1
jBWFg4LCCh8S21GLcuudHtW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KlALHnFOYYSTluoYACF1DMt7NJ3
oyA0MELL0JQzEinixqxpZ1taOmVR/8pQVrqstqwqsp3RABaeZ80JbigUC29zJUVf
=F4EX
=Eplj
-----END PGP PUBLIC KEY BLOCK-----
11 changes: 11 additions & 0 deletions templates/vine/desktop/scripts/entrypoint-desktop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ set -x
trap "echo 'Gracefully terminating...'; exit" INT TERM
trap "echo 'Terminated.'; exit" EXIT

# Configure environment variables
export __ENV_HOME='/tmp/.openark-vine-env'
rm -rf "${__ENV_HOME}"
touch "${__ENV_HOME}"

# Initialize rootless container xdg session
"$(dirname "$0")/init-desktop-xdg.sh"

# Initialize rootless container wayland session
"$(dirname "$0")/init-desktop-wayland.sh"

# Initialize rootless container environment
"$(dirname "$0")/init-desktop-podman.sh"

Expand Down
12 changes: 12 additions & 0 deletions templates/vine/desktop/scripts/init-desktop-apps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
# Copyright (c) 2023 Ho Kim ([email protected]). All rights reserved.
# Use of this source code is governed by a GPL-3-style license that can be
# found in the LICENSE file.

# Prehibit errors
set -e -o pipefail
# Verbose
set -x

# Configure environment variables
echo "export MOZ_ENABLE_WAYLAND=\"1\"" >>"${__ENV_HOME}"
16 changes: 5 additions & 11 deletions templates/vine/desktop/scripts/init-desktop-display.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,13 @@ set -e -o pipefail
# Verbose
set -x

# Apply environment variables
source "${__ENV_HOME}"

# Configure screen size
function update_screen_size() {
echo "Finding displays..."
screens="$(xrandr --current | grep ' connected ' | awk '{print $1}')"
if [ "x${screens}" == "x" ]; then
echo 'Display not found!'
return
fi

for screen in $(echo -en "${screens}"); do
echo "Fixing screen size to preferred (${screen})..."
xrandr --output "${screen}" --preferred || true
done
echo "Configuring screen size..."
xrandr --auto || true

# Disable screen blanking
echo "Disabling screen blanking..."
Expand Down
3 changes: 3 additions & 0 deletions templates/vine/desktop/scripts/init-desktop-im.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@ set -e -o pipefail
# Verbose
set -x

# Apply environment variables
source "${__ENV_HOME}"

# Try to run nimf daemon
nimf || true
14 changes: 7 additions & 7 deletions templates/vine/desktop/scripts/init-desktop-podman.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ if which podman; then
cp /etc/containers/podman-containers.conf "${HOME}/.config/containers/containers.conf"

# Initialize rootless podman
podman system migrate
if podman system migrate; then
# Generate a CDI specification that refers to all NVIDIA devices
if ! nvidia-ctk cdi generate --device-name-strategy=type-index --format=json >/etc/cdi/nvidia.json; then
rm -f /etc/cdi/nvidia.json
fi

# Generate a CDI specification that refers to all NVIDIA devices
if ! nvidia-ctk cdi generate --device-name-strategy=type-index --format=json >/etc/cdi/nvidia.json; then
rm -f /etc/cdi/nvidia.json
# Ignore welcome warnings
podman version
fi

# Ignore welcome warnings
podman version
fi
4 changes: 4 additions & 0 deletions templates/vine/desktop/scripts/init-desktop-storage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ function _mount_overlayfs() {
local dst=$2
local read_only="$3"

if [ ! -d "${src}" ]; then
return
fi

if [[ "x${read_only}" != 'xtrue' ]]; then
rm -rf "${dst}"
ln -sf "${src}" "${dst}"
Expand Down
5 changes: 5 additions & 0 deletions templates/vine/desktop/scripts/init-desktop-template.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ set -e -o pipefail
# Verbose
set -x

# Skip if template is not defined
if [ "x${KISS_DESKTOP_TEMPLATE_GIT}" == 'x' ]; then
exec true
fi

# Skip if already initialized
LOCKFILE="${HOME}/.kiss-lock"
if [ -f "${LOCKFILE}" ]; then
Expand Down
64 changes: 64 additions & 0 deletions templates/vine/desktop/scripts/init-desktop-wayland.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/bin/bash
# Copyright (c) 2024 Ho Kim ([email protected]). All rights reserved.
# Use of this source code is governed by a GPL-3-style license that can be
# found in the LICENSE file.

# Prehibit errors
set -e -o pipefail
# Verbose
set -x

# Configure environment variables
export DISPLAY="${DISPLAY:-:0}"
export WAYLAND_DISPLAY="${WAYLAND_DISPLAY:-wayland-0}"

echo "export DISPLAY=\"${DISPLAY}\"" >>"${__ENV_HOME}"
# FIXME: Vulkan support is not stable on Wayland backend
# echo "export WAYLAND_DISPLAY=\"${WAYLAND_DISPLAY}\"" >>"${__ENV_HOME}"

# Create an empty X11 socket directory, if not exists
mkdir -p "/tmp/.X11-unix"

# Create a xwayland session, if not exists
if [ ! -S "/tmp/.X11-unix/X$(echo $DISPLAY | grep -Po '[0-9]+$')" ]; then
# Configure wayland
WAYLAND_BACKEND_RDP='rdp-backend.so'

WAYLAND_ARGS="${WAYLAND_ARGS} --shell=kiosk-shell.so"
# FIXME: Vulkan support is not stable on Wayland backend
# WAYLAND_ARGS="${WAYLAND_ARGS} --socket=${WAYLAND_DISPLAY}"
WAYLAND_ARGS="${WAYLAND_ARGS} --xwayland"
WAYLAND_BACKEND="${WAYLAND_BACKEND:-$WAYLAND_BACKEND_RDP}"

# Configure RDP
if [ "x${WAYLAND_BACKEND}" == "x${WAYLAND_BACKEND_RDP}" ]; then
# Generate a TLS key pair
WAYLAND_RDP_TLS_HOME="${HOME}/.rdp"
if [ ! -f "${WAYLAND_RDP_TLS_HOME}/${HOSTNAME}.crt" ] ||
[ ! -f "${WAYLAND_RDP_TLS_HOME}/${HOSTNAME}.key" ]; then
mkdir -p "${WAYLAND_RDP_TLS_HOME}"
chmod 700 "${WAYLAND_RDP_TLS_HOME}"
winpr-makecert -rdp -path "${WAYLAND_RDP_TLS_HOME}" >/dev/null
fi

# Register the RDP TLS key pair
WAYLAND_ARGS="${WAYLAND_ARGS} --rdp-tls-cert ${WAYLAND_RDP_TLS_HOME}/${HOSTNAME}.crt"
WAYLAND_ARGS="${WAYLAND_ARGS} --rdp-tls-key ${WAYLAND_RDP_TLS_HOME}/${HOSTNAME}.key"
fi

# Detect GPU Devices
if nvidia-smi >/dev/null 2>/dev/null; then
export __GLX_VENDOR_LIBRARY_NAME="nvidia"
export __NV_PRIME_RENDER_OFFLOAD="1"
export VK_DRIVER_FILES="/usr/share/vulkan/icd.d/nvidia_icd.json"
export VK_ICD_FILENAMES="${VK_DRIVER_FILES}"

# Make these environment variables persistent
echo "export __GLX_VENDOR_LIBRARY_NAME=\"${__GLX_VENDOR_LIBRARY_NAME}\"" >>"${__ENV_HOME}"
echo "export __NV_PRIME_RENDER_OFFLOAD=\"${__NV_PRIME_RENDER_OFFLOAD}\"" >>"${__ENV_HOME}"
echo "export VK_DRIVER_FILES=\"${VK_DRIVER_FILES}\"" >>"${__ENV_HOME}"
echo "export VK_ICD_FILENAMES=\"${VK_ICD_FILENAMES}\"" >>"${__ENV_HOME}"
fi

weston --backend="${WAYLAND_BACKEND}" ${WAYLAND_ARGS} &
fi
19 changes: 19 additions & 0 deletions templates/vine/desktop/scripts/init-desktop-xdg.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
# Copyright (c) 2024 Ho Kim ([email protected]). All rights reserved.
# Use of this source code is governed by a GPL-3-style license that can be
# found in the LICENSE file.

# Prehibit errors
set -e -o pipefail
# Verbose
set -x

# Configure environment variables
export XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR:-/run/user/$(id -u)}"

# Make these environment variables persistent
echo "export XDG_RUNTIME_DIR=\"${XDG_RUNTIME_DIR}\"" >>"${__ENV_HOME}"

# Create an empty XDG runtime directory, if not exists
mkdir -p "${XDG_RUNTIME_DIR}"
chmod 700 "${XDG_RUNTIME_DIR}"
54 changes: 4 additions & 50 deletions templates/vine/desktop/scripts/init-desktop-xfce4.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,56 +8,10 @@ set -e -o pipefail
# Verbose
set -x

# Configure screen
function update_screen() {
echo "Finding monitors..."
monitors="$(xrandr --current | grep ' connected ' | awk '{print $1}')"
if [ "x${monitors}" == "x" ]; then
echo 'Display not found!'
return
fi

local target_xml="${HOME}/.config/xfce4/xfconf/xfce-perchannel-xml/displays.xml"
for monitor in $(echo -en "${monitors}"); do
echo "Fixing monitor screen size to preferred (${monitor})..."
spec=$(
xrandr |
awk -v monitor="^${monitor} connected" '/disconnected/ {p = 0} $0 ~ monitor {p = 1} p' |
tail -n +2
)

# Fix FHD if possible
monitor_resolution='1920x1080'
if ! echo "${spec}" | grep -q "${monitor_resolution}"; then
monitor_resolution="$(echo "${spec}" | grep -Po '^ *\K[0-9x]+' | head -n1)"
fi
echo "* Resolution = '${monitor_resolution}'"

monitor_refresh_rate="$(echo "${spec}" | grep -Po "^ *${monitor_resolution} *\K[0-9.]+")"
echo "* Refresh Rate = '${monitor_refresh_rate}'"

# Update screen size if primary
if [ "${monitor}" = "${monitors}" ]; then
xrandr --output "${monitor}" \
--size "${monitor_resolution}" \
--refresh "${monitor_refresh_rate}" || true
fi

xmlstarlet edit \
--inplace \
--update "/channel/property/property[@name='${monitor}']/property[@name='Resolution']/@value" \
--value "${monitor_resolution}" \
"${target_xml}"
xmlstarlet edit \
--inplace \
--update "/channel/property/property[@name='${monitor}']/property[@name='RefreshRate']/@value" \
--value "${monitor_refresh_rate}" \
"${target_xml}"
done
}

# Apply
update_screen
# Apply environment variables
source "${__ENV_HOME}"
rm -f "${__ENV_HOME}"
unset __ENV_HOME

# Remove cached sessions (saved sessions, etc.)
rm -rf "${HOME}/.cache/sessions/" || true
Expand Down
Loading

0 comments on commit ec854fd

Please sign in to comment.