Using X without a Display Manager: Difference between revisions

From NixOS Wiki
imported>Fadenb
m Syntaxhighlight
Klinger (talk | contribs)
mNo edit summary
 
(14 intermediate revisions by 7 users not shown)
Line 1: Line 1:
== X without a Display Manager is unsupported ==
{{note|This page is a WIP, it doesn't describe best-practices with nix and NixOS and should be updated to use a nix derivation generating the necessary files instead of manipulating the contents of the store.}}
Many people (especially coming from Arch Linux) are used to starting X manually, e.g. with `startx`. In NixOS, this is currently unsupported.


The reason that it is unsupported is that the upstreams (Xorg and systemd) by default do not support this functionality. Arch Linux has special hacks in place to make it work at all.
== Setting up Xorg without system wide modifications ==


If you really care about this feature, you are welcome to port these hacks to NixOS - there is no philosophical objection to having manual startx working. However, to date no one in the community has cared enough to get it working.
To run X11 as a regular user, ''without'' <code>services.xserver.enable = true;</code> in configuration.nix, do the following:


== Use xlaunch ==
First, '''install packages''':
{{warning|text=Several users on IRC have reported that this no longer works on unstable. (2015/07)}}
* X11 itself:
** <code>xorg.xorgserver</code>
* X11 input modules
** <code>xorg.xf86inputevdev</code>
** <code>xorg.xf86inputsynaptics</code>
** <code>xorg.xf86inputlibinput</code>
*X11 video modules
** <code>xorg.xf86videointel</code>
** <code>xorg.xf86videoati</code>
** <code>xorg.xf86videonouveau</code>


1. Edit configuration.nix appropriately - the following has relevant bits for fluxbox:
You probably want to use '''DRI acceleration''' for X; enable it and OpenGL in configuration.nix: <code>hardware.opengl.enable = true;</code> and <code>hardware.opengl.driSupport = true;</code>.


<syntaxhighlight lang="nix">
Then, it's just necessary to '''gather X configuration files''' into one directory and create a config file that also points X at the correct module paths, by running the following script (which should be re-run each time you run <code>nixos-rebuild switch</code>), but you will need to add or remove to the <code>pkgs</code> and <code>fontpkgs</code> arrays according to your preferences:
  environment.systemPackages = with pkgs; [
<syntaxhighlight lang="sh">
    xlaunch
generateXorgConf.sh
  ];
------------------------------------------------
#!/bin/sh
#generate unprivileged user xorg.conf for nixOS
#before running:
#    install any desired packages by placing them in `/etc/nixos/configuration.nix`
#    update by running `nix-channel --update` and `nixos-rebuild switch`
 
config_dir=${XDG_CONFIG_HOME:-~/.config}/xorg.conf.d
 
mkdir -p "$config_dir"
cd "$config_dir"
 
#failed glob expansions become empty, not literal 'foo/*'
shopt -s nullglob
 
get_pkg_path() {
attr=$1
nix show-derivation -f '<nixpkgs>' "$attr" | jq -r '.[].env.out'
}
 
#add to this set according to your driver needs
pkgs="
xorg.xf86inputevdev
xorg.xf86videointel
xorg.xf86inputsynaptics
xorg.xorgserver
"
 
#make the intel backlight helper setuid if it isn't already
xf86videointel_path=$(get_pkg_path xorg.xf86videointel)
backlight_helper_path="${xf86_video_intel_path}/libexec/xf86-video-intel-backlight-helper"
if [ -e "$backlight_helper_path" -a ! -u "$backlight_helper_path" ]; then
sudo chmod +s ${xf86_video_intel_path}/libexec/xf86-video-intel-backlight-helper
fi
 
echo 'Section "Files"' > 00-nix-module-paths.conf
for pkg in $pkgs; do
pkg_path=$(get_pkg_path $pkg)
for conf in "$pkg_path"/share/X11/xorg.conf.d/*; do
ln -sf "$conf" ./
done
echo ' ModulePath "'"$pkg_path"'/lib/xorg/modules/"' >> 00-nix-module-paths.conf
done
 
#add to this set according to your font preferences
fontpkgs="
xorg.fontmiscmisc
ucsFonts
"


  security.setuidPrograms = [
for pkg in $fontpkgs; do
    "xlaunch"
pkg_path=$(get_pkg_path $pkg)
  ];
path="$pkg_path"'/share/fonts/'
[ -d "$path" ] && echo ' FontPath "'"$path"'"' >> 00-nix-module-paths.conf
path="$pkg_path"'/lib/X11/fonts/misc/'
[ -d "$path" ] && echo ' FontPath "'"$path"'"' >> 00-nix-module-paths.conf
done


  services.xserver = {
echo 'EndSection' >> 00-nix-module-paths.conf
    autorun = false;
</syntaxhighlight>
    enable = true;
    enableTCP = false;
    exportConfiguration = true;
    layout = "us";
    desktopManager = {
      xterm.enable = false;
      xfce.enable = false;
    };
    # XXX: slim must not be disabled for xlaunch to work
#    displayManager = {
#      slim.enable = false;
#      job.execCmd = "";
#    };
    windowManager = {
      fluxbox.enable = true;
    };
  };


You can now '''start X11''' by running:
<syntaxhighlight lang="sh">
startx -- :0 -configdir ~/.config/xorg.conf.d
</syntaxhighlight>
</syntaxhighlight>


2. nixos-rebuild as usual:
== Setting up Xorg system-wide but without a Display Manager ==
 
If you don't mind having <code>services.xserver.enable = true;</code> but you don't want a display manager, and you want only a TTY login prompt, use the following in your <code>configuration.nix</code>:


<syntaxhighlight lang="console">
<syntaxhighlight lang="nix">
# nixos-rebuild switch
services.xserver.displayManager.startx.enable = true;
</syntaxhighlight>
</syntaxhighlight>


3. Possibly reboot
<code>startx</code> is treated as a displayManager and therefore it is used instead of the default (<code>lightdm</code>).
 
== Setting up the user's D-Bus Daemon ==
 
Both of the methods above, don't start the user's dbus-daemon properly on startup. Unfortunately, it is unclear exactly why this is missing, but here's a fix for startx users:
 
Put the following in your <code>~/.xinitrc</code>:


4. Start xlaunch from command line, e.g. for fluxbox:
<syntaxhighlight lang="sh">
if test -z "$DBUS_SESSION_BUS_ADDRESS"; then
eval $(dbus-launch --exit-with-session --sh-syntax)
fi
systemctl --user import-environment DISPLAY XAUTHORITY


<syntaxhighlight lang="console">
if command -v dbus-update-activation-environment >/dev/null 2>&1; then
$ xlaunch startfluxbox
        dbus-update-activation-environment DISPLAY XAUTHORITY
fi
</syntaxhighlight>
</syntaxhighlight>
[[Category: Desktop environment]]

Latest revision as of 19:44, 24 April 2024

Note: This page is a WIP, it doesn't describe best-practices with nix and NixOS and should be updated to use a nix derivation generating the necessary files instead of manipulating the contents of the store.

Setting up Xorg without system wide modifications

To run X11 as a regular user, without services.xserver.enable = true; in configuration.nix, do the following:

First, install packages:

  • X11 itself:
    • xorg.xorgserver
  • X11 input modules
    • xorg.xf86inputevdev
    • xorg.xf86inputsynaptics
    • xorg.xf86inputlibinput
  • X11 video modules
    • xorg.xf86videointel
    • xorg.xf86videoati
    • xorg.xf86videonouveau

You probably want to use DRI acceleration for X; enable it and OpenGL in configuration.nix: hardware.opengl.enable = true; and hardware.opengl.driSupport = true;.

Then, it's just necessary to gather X configuration files into one directory and create a config file that also points X at the correct module paths, by running the following script (which should be re-run each time you run nixos-rebuild switch), but you will need to add or remove to the pkgs and fontpkgs arrays according to your preferences:

generateXorgConf.sh
------------------------------------------------
#!/bin/sh
#generate unprivileged user xorg.conf for nixOS
#before running:
#    install any desired packages by placing them in `/etc/nixos/configuration.nix`
#    update by running `nix-channel --update` and `nixos-rebuild switch`

config_dir=${XDG_CONFIG_HOME:-~/.config}/xorg.conf.d

mkdir -p "$config_dir"
cd "$config_dir"

#failed glob expansions become empty, not literal 'foo/*'
shopt -s nullglob

get_pkg_path() {
	attr=$1
	nix show-derivation -f '<nixpkgs>' "$attr" | jq -r '.[].env.out' 
}

#add to this set according to your driver needs
pkgs="
	xorg.xf86inputevdev
	xorg.xf86videointel
	xorg.xf86inputsynaptics
	xorg.xorgserver
"

#make the intel backlight helper setuid if it isn't already
xf86videointel_path=$(get_pkg_path xorg.xf86videointel)
backlight_helper_path="${xf86_video_intel_path}/libexec/xf86-video-intel-backlight-helper"
if [ -e "$backlight_helper_path" -a ! -u "$backlight_helper_path" ]; then
	sudo chmod +s ${xf86_video_intel_path}/libexec/xf86-video-intel-backlight-helper
fi

echo 'Section "Files"' > 00-nix-module-paths.conf
for pkg in $pkgs; do
	pkg_path=$(get_pkg_path $pkg)
	for conf in "$pkg_path"/share/X11/xorg.conf.d/*; do 
		ln -sf "$conf" ./
	done
	echo '	ModulePath "'"$pkg_path"'/lib/xorg/modules/"' >> 00-nix-module-paths.conf
done

#add to this set according to your font preferences
fontpkgs="
	xorg.fontmiscmisc
	ucsFonts
"

for pkg in $fontpkgs; do
	pkg_path=$(get_pkg_path $pkg)
	path="$pkg_path"'/share/fonts/'
	[ -d "$path" ] && echo '	FontPath "'"$path"'"' >> 00-nix-module-paths.conf
	path="$pkg_path"'/lib/X11/fonts/misc/'
	[ -d "$path" ] && echo '	FontPath "'"$path"'"' >> 00-nix-module-paths.conf
done

echo 'EndSection' >> 00-nix-module-paths.conf

You can now start X11 by running:

startx -- :0 -configdir ~/.config/xorg.conf.d

Setting up Xorg system-wide but without a Display Manager

If you don't mind having services.xserver.enable = true; but you don't want a display manager, and you want only a TTY login prompt, use the following in your configuration.nix:

services.xserver.displayManager.startx.enable = true;

startx is treated as a displayManager and therefore it is used instead of the default (lightdm).

Setting up the user's D-Bus Daemon

Both of the methods above, don't start the user's dbus-daemon properly on startup. Unfortunately, it is unclear exactly why this is missing, but here's a fix for startx users:

Put the following in your ~/.xinitrc:

if test -z "$DBUS_SESSION_BUS_ADDRESS"; then
	eval $(dbus-launch --exit-with-session --sh-syntax)
fi
systemctl --user import-environment DISPLAY XAUTHORITY

if command -v dbus-update-activation-environment >/dev/null 2>&1; then
        dbus-update-activation-environment DISPLAY XAUTHORITY
fi