Skip to content

Instantly share code, notes, and snippets.

@KoKuToru
Last active November 1, 2025 09:22
Show Gist options
  • Select an option

  • Save KoKuToru/f42778b21a9786dca49f5151f1175f77 to your computer and use it in GitHub Desktop.

Select an option

Save KoKuToru/f42778b21a9786dca49f5151f1175f77 to your computer and use it in GitHub Desktop.
steam in systemd-nspawn on archlinux (only for intel/amd gpu)
#!/bin/bash
# based on https://liolok.com/containerize-steam-with-systemd-nspawn/
if [ "$EUID" -ne 0 ]; then
echo "Not running as root. Please run with sudo."
exit 1
fi
set -ex
container_name=steam-container
pacman_config_tmp=$(mktemp)
# Create a temporary pacman config with multilib enabled for pacstrap
sed '/\[multilib\]/,/Include/s/^#//' /etc/pacman.conf > "$pacman_config_tmp"
rm -rf $container_name
mkdir -p $container_name
# Use the temporary config to install packages from core, extra, and multilib
sudo pacstrap -C "$pacman_config_tmp" -c -K $container_name \
base steam mesa lib32-mesa noto-fonts \
vulkan-radeon lib32-vulkan-radeon \
vulkan-intel lib32-vulkan-intel \
xdg-desktop-portal \
xdg-desktop-portal-gtk xdg-desktop-portal-kde xdg-desktop-portal-wlr \
lib32-alsa-plugins lib32-libpulse --noconfirm
rm "$pacman_config_tmp"
# Now, configure the container
sudo systemd-nspawn \
--directory="$PWD/$container_name" \
--machine=$container_name \
--bind-ro=/etc/resolv.conf \
--as-pid2 bash -c "sed -i '/\[multilib\]/,/Include/s/^#//' /etc/pacman.conf; sed -i '/en_US.UTF-8/s/^#//' /etc/locale.gen; locale-gen; pacman -Syu --noconfirm"
#!/bin/bash
if [ "$EUID" -eq 0 ]; then
echo "Dont run as root. Please run without sudo."
exit 1
fi
set -x
container_name=steam-container
# Get host user details once
HOST_USER=$USER
HOST_UID=$(id -u $USER)
HOST_GID=$(id -g $USER)
# --- 1. User Creation (Check/Create using the HOST_USER's UID/GID) ---
sudo systemd-nspawn \
--directory="$PWD/$container_name" \
--machine=$container_name \
--bind-ro=/etc/resolv.conf \
--as-pid2 bash -c "id -u $HOST_USER &>/dev/null || useradd -o -u $HOST_UID -g $HOST_GID --create-home $HOST_USER"
# --- 2. Steam Launch ---
sudo systemd-nspawn \
--directory="$PWD/$container_name" \
--machine=$container_name \
--property=DeviceAllow='char-drm rw' \
--bind-ro=/etc/resolv.conf \
--bind=/run/user/$HOST_UID \
--bind-ro=/dev/dri \
--bind=/tmp \
-E WAYLAND_DISPLAY=$WAYLAND_DISPLAY \
-E XAUTHORITY=$XAUTHORITY \
-E DESKTOP_SESSION=$DESKTOP_SESSION \
-E XDG_SESSION_TYPE=$XDG_SESSION_TYPE \
-E GDM_LANG=$GDM_LANG \
-E WAYLAND_DISPLAY=$WAYLAND_DISPLAY \
-E QT_QPA_PLATFORM=$QT_QPA_PLATFORM \
-E TERM=$TERM \
-E DISPLAY=$DISPLAY \
-E XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR \
-E GDMSESSION=$GDMSESSION \
-E DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS \
-E TERM_PROGRAM=$TERM_PROGRAM \
-E XDG_CURRENT_DESKTOP=$XDG_CURRENT_DESKTOP \
--bind=/mnt \
--bind=/media \
--user=$HOST_USER --as-pid2 /usr/bin/steam
#!/bin/bash
if [ "$EUID" -ne 0 ]; then
echo "Not running as root. Please run with sudo."
exit 1
fi
set -ex
container_name=steam-container
systemd-nspawn \
--directory="$PWD/$container_name" \
--machine=$container_name \
--bind-ro=/etc/resolv.conf \
--as-pid2 pacman -Syu --noconfirm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment