Skip to content

Instantly share code, notes, and snippets.

@timbertson
Last active July 12, 2018 21:30
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timbertson/eaf5c588065eabc71153 to your computer and use it in GitHub Desktop.
Save timbertson/eaf5c588065eabc71153 to your computer and use it in GitHub Desktop.
Run nixpkgs' gnome shell inside a `xephyr` window
# NOTE: unfortunately `nixpkgs` xephyr doesn't nest properly in my testing.
# So you need to have a system Xephyr.
#
# This script will create a ./scratch directory in the current directory,
# where it'll store temporary files and a makeshift $HOME dir.
#
# To build the script:
# nix-build --out-link gnome-shell.sh gnome-shell.nix
#
# Then run it with:
# ./gnome-shell.sh
{pkgs ? import <nixpkgs> {}, display ? ":1", extraEnv ? "", xephyr ? "/usr/bin/Xephyr" }:
with pkgs;
let dbus-services = with gnome3; [
dconf
gnome_settings_daemon
]; in
writeScript "gnome-shell-wrapper" ''#!${bash}/bin/bash
set -eux
here="$(pwd)"
scratch="$here/scratch"
echo "Making scratch dir in $scratch ..."
mkdir -p "$scratch/home"
me="$(id -un)"
function kill_pid () {
pid="$1"
desc="$2"
if [ -n "$pid" ]; then
echo "Killing $desc ($pid)" >&2
# wait "$pid"
# set -x
kill -INT "$pid" || true
while kill -0 "$pid" 2>/dev/null; do
sleep 0.2
done
fi
}
dbus_pid=""
xephyr_pid=""
function cleanup () {
kill_pid "$dbus_pid" DBus
kill_pid "$xephyr_pid" Xephyr
}
trap cleanup EXIT
exec 3> "$scratch/dbus-pid"
exec 4> "$scratch/dbus-address"
exec 5> "$scratch/xephyr-display"
env XDG_DATA_DIRS="${
lib.concatStringsSep ":" (map (x: "${x}/share") dbus-services)
}''${XDG_DATA_DIRS:+:$XDG_DATA_DIRS}" \
HOME="$here/scratch/home" \
${dbus_daemon}/bin/dbus-daemon --session --fork \
--print-pid=3 --print-address=4
dbus_pid="$(cat "$scratch/dbus-pid")"
export DBUS_SESSION_BUS_ADDRESS="$(cat "$scratch/dbus-address")"
${xephyr} -ac -displayfd 5 -terminate "${display}" &
xephyr_pid="$!"
exec 5>&-
while [ -z "$(cat scratch/xephyr-display)" ]; do
sleep 1
echo "awaiting xephyr..."
done
exec 3>&-
exec 4>&-
exec 5>&-
# use sudo just to clear out envvars
sudo -u "$me" \
env \
LIBGL_DRIVERS_PATH="${mesa_drivers}/lib/dri:${mesa_noglu}/lib" \
DBUS_SESSION_BUS_ADDRESS="$(cat "$scratch/dbus-address")" \
LD_LIBRARY_PATH="''${LD_LIBRARY_PATH:-}:${mesa_noglu}/lib" \
HOME="$here/scratch/home" \
DISPLAY="${display}" \
XDG_DATA_DIRS="$scratch/home/.local/share:$HOME/.local/share:/usr/local/share:/usr/share" \
GIO_EXTRA_MODULES="${gnome3.dconf}/lib/gio/modules" \
PATH="${gnome3.gnome_shell}/bin:${gnome3.gnome-tweak-tool}/bin:$PATH" \
${extraEnv} \
"${gnome3.gnome_shell}/bin/gnome-shell" \
"$@"
''
@olejorgenb
Copy link

olejorgenb commented Jul 7, 2018

This works using nixpkgs xephyr now (@ NixOS/nixpkgs@696c6bed4e8)

The whole session starts very slow and some applications start very slow inside the session. This seems to be the problem: (waiting for ibus?)

** (gnome-shell:25957): WARNING **: 00:13:49.127: Error retrieving accessibility bus address: org.freedesktop.DBus.Error.NoReply: Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken.
GNOME Shell-Message: 00:13:49.799: Failed to launch ibus-daemon: Failed to execute child process “ibus-daemon” (No such file or directory)

I've tried to add ibus to the PATH. Then I get:

** (gnome-shell:23119): WARNING **: 00:09:44.809: Error retrieving accessibility bus address: org.freedesktop.DBus.Error.NoReply: Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken.
portal is not running: GDBus.Error:org.freedesktop.DBus.Error.Spawn.ChildExited: Process org.freedesktop.portal.IBus exited with status 1

Inside the session: starting the the slow-starting applications with NO_AT_BRIDGE=1 make them fast (eg. gnome-tweaks), but adding that variable to the start-environment of the script does not work - the variable is overwritten later it seems (it's not set inside the session)

EDIT: running:

Xephyr :2  &
DISPLAY=:2 dbus-run-session gnome-shell

Works without the slowness (but might be less isolated)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment