-
-
Save timbertson/eaf5c588065eabc71153 to your computer and use it in GitHub Desktop.
Run nixpkgs' gnome shell inside a `xephyr` window
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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" \ | |
"$@" | |
'' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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?)
I've tried to add ibus to the PATH. Then I get:
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:
Works without the slowness (but might be less isolated)