Using X without a Display Manager: Difference between revisions

From NixOS Wiki
imported>Samueldr
m Changed warning to outdated template.
imported>Giraffito
rewrite entirely. xlaunch does not exist since 2016: https://github.com/NixOS/nixpkgs/commit/20fe51661dcea78682420767fb8afd1170b06781 and there is no need for additional setuid wrappers
Line 1: Line 1:
== X without a Display Manager is unsupported ==
'''''Please note''': this page is presently being rewritten by someone very new to nixOS, so do not use it as an example of best practices. The previous content of this page was 2 years out of date and factually incorrect.''
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.
To run X11 as a regular user, ''without'' `services.xserver.enable = true;` in configuration.nix, do the following:


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.
First, '''install packages'''; you need X11 itself, some X11 input modules (e.g. xf86-input-evdev, xf86-input-synaptics, xf86-input-libinput), and possibly video modules as well (xf86-video-intel, xf86-video-ati, xf86-video-nouveau).


== Use xlaunch ==
You probably want to use '''DRI acceleration''' for X; enable it and OpenGL in /etc/nixos/configuration.nix: `hardware.opengl.enable = true;` and `hardware.opengl.driSupport = true;`.
{{outdated|Several users on IRC have reported that this no longer works on unstable. (2015/07)}}


1. Edit configuration.nix appropriately - the following has relevant bits for fluxbox:
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.


<syntaxhighlight lang="nix">
This script does that (though it hard-codes `pkgs` which should instead be computed from the current configuration):
environment.systemPackages = with pkgs; [
<syntaxhighlight lang="sh">
  xlaunch
#!/bin/sh
];
#generate unprivileged user xorg.conf for nixOS
#TODO: obey XDG guidelines rather than assuming ~/.config


security.setuidPrograms = [
mkdir -p ~/.config/xorg.conf.d
  "xlaunch"
cd ~/.config/xorg.conf.d
];


services.xserver = {
#failed glob expansions become empty, not literal 'foo/*'
  autorun = false;
shopt -s nullglob
  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;
  };
};
</syntaxhighlight>


2. nixos-rebuild as usual:
#TODO: don't hard-code package names!
pkgs="
i0r09miwjk8z9wd2261gh3a3mdzln4w4-xf86-input-evdev-2.10.5
av8542xr7kn44abja120hk3ppd2vp8l8-xf86-video-intel-2017-10-19
8vp93ci2lkcg9c5jh7csfz24npjcnhhx-xf86-input-synaptics-1.9.0
660q2zwjrn0cqkjj6cy861pkazs6yrs0-xorg-server-1.19.6
"


<syntaxhighlight lang="console">
echo 'Section "Files"' > 00-nix-module-paths
# nixos-rebuild switch
for pkg in $pkgs; do
for conf in /nix/store/"$pkg"/share/X11/xorg.conf.d/*; do
ln -s "$conf" ./
done
echo ' ModulePath "/nix/store/'"$pkg"'/lib/xorg/modules/"' >> 00-nix-module-paths.conf
done
echo 'EndSection' >> 00-nix-module-paths.conf
</syntaxhighlight>
</syntaxhighlight>


3. Possibly reboot
You can now '''start X11''' by running:
 
<syntaxhighlight lang="sh">
4. Start xlaunch from command line, e.g. for fluxbox:
startx -- :0 -configdir ~/.config/xorg.conf.d
 
<syntaxhighlight lang="console">
$ xlaunch startfluxbox
</syntaxhighlight>
</syntaxhighlight>

Revision as of 16:14, 16 March 2018

Please note: this page is presently being rewritten by someone very new to nixOS, so do not use it as an example of best practices. The previous content of this page was 2 years out of date and factually incorrect.

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

First, install packages; you need X11 itself, some X11 input modules (e.g. xf86-input-evdev, xf86-input-synaptics, xf86-input-libinput), and possibly video modules as well (xf86-video-intel, xf86-video-ati, xf86-video-nouveau).

You probably want to use DRI acceleration for X; enable it and OpenGL in /etc/nixos/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.

This script does that (though it hard-codes `pkgs` which should instead be computed from the current configuration):

#!/bin/sh
#generate unprivileged user xorg.conf for nixOS
#TODO: obey XDG guidelines rather than assuming ~/.config

mkdir -p ~/.config/xorg.conf.d
cd ~/.config/xorg.conf.d

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

#TODO: don't hard-code package names!
pkgs="
i0r09miwjk8z9wd2261gh3a3mdzln4w4-xf86-input-evdev-2.10.5
av8542xr7kn44abja120hk3ppd2vp8l8-xf86-video-intel-2017-10-19
8vp93ci2lkcg9c5jh7csfz24npjcnhhx-xf86-input-synaptics-1.9.0
660q2zwjrn0cqkjj6cy861pkazs6yrs0-xorg-server-1.19.6
"

echo 'Section "Files"' > 00-nix-module-paths
for pkg in $pkgs; do
	for conf in /nix/store/"$pkg"/share/X11/xorg.conf.d/*; do 
		ln -s "$conf" ./
	done
	echo '	ModulePath "/nix/store/'"$pkg"'/lib/xorg/modules/"' >> 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