I’ve been using startx to use xmonad instead of Gnome on Ubuntu for a few days now. The machine I’m using is an HP Elitebook x360 1040 G7.
The issues I encountered were different than yours, but the config I ended up with may be useful to compare.
(EE) open /dev/fb0: Permission denied
I first got this error, which I tried to work around with this overlay:
self: super: {
xorg = super.xorg // {
xorgserver = super.xorg.xorgserver.overrideAttrs (old: {
configureFlags = old.configureFlags ++ [ "--enable-suid-wrapper" ];
postInstall = old.postInstall + ''
mkdir -p $out/etc/X11
echo "needs_root_rights=yes" >> $out/etc/X11/Xwrapper.config
'';
});
};
}
Which seemed to work at first, but then it didn’t, and I eventually added my user to the video group with:
sudo usermod -a -G video $USER
Incorporating some pieces from “Using X without a Display Manager” from the NixOS wiki, I got startx to show xterm windows and a clock, but the screen got only repainted when I moved the mouse cursor. After reading that the xf86-video-intel driver has been mostly superseded by the modesetting driver, I removed xorg.xf86videointel from the list of packages to install, and that fixed the repaint issue.
My config now looks like:
home.nix:
{ config, pkgs, ... }:
{
imports = [
./modules/xserver.nix
];
xsession = {
enable = true;
windowManager.xmonad.enable = true;
windowManager.xmonad.enableContribAndExtras = true;
};
programs.xserver.enable = true;
programs.xserver.debug = false;
# ...
}
modules/xserver.nix:
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.programs.xserver;
in {
options = {
programs.xserver = {
enable = mkEnableOption "xserver";
debug = mkEnableOption "log errors";
errfilePath = mkOption {
type = types.str;
default = ".xsession-errors";
description = ''
Path, relative to <envar>HOME</envar>, for X session log/error.
'';
};
};
};
config = mkIf cfg.enable {
home.file.".xserverrc".source = pkgs.writeShellScript "xserverrc" ''
exec ${pkgs.xorg.xorgserver}/bin/X -configdir ${config.home.profileDirectory}/share/X11/xorg.conf.d "$@"
'';
home.file.".xinitrc".source = pkgs.writeShellScript "xinitrc" (''
set -e
''
+ (optionalString cfg.debug ''
exec >>"${config.home.homeDirectory}/${cfg.errfilePath}" 2>&1
'')
+
''
set +e
. "${config.home.homeDirectory}/${config.xsession.scriptPath}"
set -e
exit 0
'');
home.sessionVariables.LIBGL_DRIVERS_PATH = "${pkgs.mesa_drivers}/lib/dri/";
home.packages = with pkgs; [
xorg.xorgserver
xorg.xf86inputlibinput
xorg.xinit
xorg.xkill
xorg.xrandr
xorg.xrdb
xorg.xsetroot
xterm
(
pkgs.writeTextFile {
name = "xorg-conf-module-paths.conf";
destination = "/share/X11/xorg.conf.d/00-module-paths.conf";
text = ''
Section "Files"
ModulePath "${config.home.profileDirectory}/lib/xorg/modules/"
FontPath "${config.home.profileDirectory}/share/fonts/"
FontPath "${config.home.profileDirectory}/lib/X11/fonts/"
EndSection
'';
}
)
];
};
}
$HOME/.xinitrc written by the config above sources $HOME/.xsession instead of launching xterm and xclock, which I believe is the behavior of the default xinitrc.
I also installed nixGL but ended up not using it. Setting LIBGL_DRIVERS_PATH took care of an error that was about loading drivers. (Regrettably, I didn’t write down the exact error message.)
I get the same errors with this setup, but apparently the last two modset errors are not fatal. The first three are expected, as those modules aren’t installed in my environment.