X11 won't start (no devices detected)

I installed NixOS on bare metal from my configuration that I had made on a virtual machine. I have a laptop with an nvidia gpu and an AMD cpu. An external monitor is connected to it via an HDMI cable.

I use startx to start my X session.

I set up nvidia following the official guide. Here’s the relevant configuration.nix: https://0x0.st/Xl6i.nix

Here’s the output of lshw -c display: https://0x0.st/Xl6H.txt

Here’s my xsession.nix, managed by home-manager: https://0x0.st/XlEF.nix

Here’s the Xorg.0.log: https://0x0.st/XlEk.0.log/

I use a similar configuration on my desktop, since I leave the integrated graphics enabled.

We might want to double check your bus IDs. Post the output of lspci | grep VGA.

The videoDrivers you can change to [ "amdgpu" ] or [ "amdgpu" "nvidia" ]. I had this set the same as you, but I wonder if that was only working because I also set boot.initrd.kernelModules = [ "amdgpu" ].

Here’s lspci | grep VGA: https://0x0.st/XlUh.txt

I tried to change videoDrivers to [ “amdgpu” “nvidia” ] but X still won’t start except the Xorg.0.log no longer has errors in regard to screens

Oh, I see: it should be `“PCI:5:0:0” instead of “PCI:0:5:0” and the same deal with the other one.

If you still have problems after that, let’s also verify that a non prime config is working.

I set it to be “PCI:5:0:0” and “PCI:1:0:0” but I still don’t get the X server to run properly. The Xorg.0.log shows no errors though (except failing to set my mouse scroll to 2 finger mode but that shouldn’t be an issue) insted my laptop screen goes black for like a second and then X crashes.

Tried commenting out all of the PRIME-related stuff and it still doesn’t work. The Xorg.0.log still looks the same to me

Hmm. Did you get it working?

We need to find some config that works, even if it’s not the exact setup that you want, so we can start to debug it on the basis of differences. With everything on defaults it also doesn’t start? I’d also add that initrd line, if you still haven’t. Review everything at https://nixos.wiki/wiki/AMD_GPU to see what applies to you.

Did some troubleshooting:

I disabled all of prime and put an .xinitrc (not declarative) to my home directory and I got it working on my externally connected monitor. Here’s the .xinitrc:

#!/bin/sh

userresources=$HOME/.Xresources
usermodmap=$HOME/.Xmodmap
sysresources=/etc/X11/xinit/.Xresources
sysmodmap=/etc/X11/xinit/.Xmodmap

# merge in defaults and keymaps if [ -f $sysresources ]; then







    xrdb -merge $sysresources


if [ -f $sysmodmap ]; then
    xmodmap $sysmodmap
fi

if [ -f "$userresources" ]; then







    xrdb -merge "$userresources"

fi

if [ -f "$usermodmap" ]; then
    xmodmap "$usermodmap"
fi

# start some nice programs

if [ -d /etc/X11/xinit/xinitrc.d ] ; then
 for f in /etc/X11/xinit/xinitrc.d/?*.sh ; do
  [ -x "$f" ] && . "$f"
 done
 unset f
fi

clipmenud &
xclip &
setxkbmap -layout "us,ua" -option "grp:alt_shift_toggle" &
xrandr --output HDMI-0 --mode 2560x1440 --rate 144 &
exec bspwm

So it does work quite well, writing from that X11 environment. Problem is that I can’t actually configure that .xinitrc via home-manager, here is what I tried:

{ pkgs, ... }: {
    xsession = {
        enable = true;
        windowManager = {
            bspwm.enable = true;
        };
        # maybe it's not the best place to explain my philosophy regarding autostarting programs, but who cares?
        # basically, programs that you always need in the background, that aren't provided by any de/wm and those that don't need a graphical environment to run should be ran as a systemd/openrc/whatever other init system you use service. That way, they will be running in the background and you will be able to track their behaviour via your distribution's init system.
        # programs that you always need in the background and those that some de/wm provide should be ran through X, like what you see below.
        # programs that are specific to your currently used de/wm should be ran within that de/wm's config file.

        # this may sound complex and make it harder to work with autostarting software as there are 3 different ways to do that, but it becomes easier to switch environments and tweak your config, as you won't have to disable systemd units, but comment what's provided by an another de/wm. 
        initExtra = ''
        userresources=$HOME/.Xresources
        usermodmap=$HOME/.Xmodmap
        sysresources=/etc/X11/xinit/.Xresources
        sysmodmap=/etc/X11/xinit/.Xmodmap
        
        # merge in defaults and keymaps if [ -f $sysresources ]; then
        
            xrdb -merge $sysresources
        
        
        if [ -f $sysmodmap ]; then
            xmodmap $sysmodmap
        fi
        
        if [ -f "$userresources" ]; then
        
        
        
        
        
        
        
            xrdb -merge "$userresources"
        
        fi
        
        if [ -f "$usermodmap" ]; then
            xmodmap "$usermodmap"
        fi
        
        # start some nice programs
        
        if [ -d /etc/X11/xinit/xinitrc.d ] ; then
         for f in /etc/X11/xinit/xinitrc.d/?*.sh ; do
          [ -x "$f" ] && . "$f"
         done
         unset f
        fi

            clipmenud &
            xclip &
            setxkbmap -layout "us,ua" -option "grp:alt_shift_toggle" &
            xrandr --output HDMI-0 --mode 2560x1440 --rate 144
            xinput set-prop 'Logitech G102 Prodigy Gaming Mouse' 'libinput Accel Speed' -0.4 &
        '';
    };
}

which adds those lines to .xsession instead of .xinitrc and it still doesn’t launch.

Okay, so we have a different problem than “X11 won’t start” now, right?

How is it working now, if you don’t use bspwm? If that xrandr line is something that you require, it would probably go in services.xserver.displayManager.setupCommands, but that’s only supported by certain window managers according to the option description.

I do use bspwm, my .xinitrc has exec bspwm at the very end of it. The problem is that setting up a .xinitrc isn’t declarative, which I’d like to avoid. It should work without the .xinitrc as I tried setting up xsession via home-manager.

All the xrandr line does is change the refresh rate, I get the right display and resolution even without using it

And that’s without prime: I don’t need it when I have an external monitor connected, but I do need it when I don’t have the monitor connected

I don’t use home-manager, and so it’s getting difficult for me to conceptualize. I’d recommend you make a new post and try to clarify as much as possible. Include the same debugging info, making sure it’s all up to date, but add more narrative on what you’ve been trying to accomplish, what you’ve tried and what’s not working.

Sorry I can’t be of more help.

1 Like

That’s no problem, I will try to solve this and if I don’t succeed I’ll just make an another post.

Thank you

1 Like

I updated my packages (did a doas nix flake update) and prime works now! If I comment out the prime section I get image on my external monitor, if I keep it then I get image on my laptop’s screen.

Will probably set it up so I can quickly switch between those configurations.

1 Like

See Bspwm configured through home-manager doesn't start for the thread involving .xinitrc/.xsession troubles