Startx failing with intel graphics

Hello! I’m trying to get nvidia/intel hybrid graphics working on NixOS. I followed the directions on the nvidia wiki page and running $ emacs is working fine (my display manager is exwm via emacs). Unfortunately, I’m unable to get the intel half working. I’m using startx rather than a display manager. Here’s the relevant part of my config:

  environment.systemPackages = with pkgs; [
    # ...

  services = {
    # Enable the X11 windowing system.
    xserver = {
      # Enable touchpad support.
      libinput.enable = true;

      enable = true;
      layout = "us";
      autorun = false;
      exportConfiguration = true;

      # manually start exwm with a startx script. this is only for
      # using the builtin intel GPU. To use the NVIDIA GPU use
      # primerun.
      displayManager.startx = {
        enable = true;
      desktopManager.default = "none";

  hardware = {
    nvidiaOptimus.disable = true;

    opengl = {
      enable = true;

      extraPackages = with pkgs; [
      driSupport = true;
      driSupport32Bit = true;

      extraPackages32 = with pkgs; [

My xinitrc is just exec emacs although I’ve also tried unsuccessfully with the full xinitrc provided by exwm.

When I run $ startx the computer freezes and I have to coldboot. Additionally there are no logs I can look at (journalctl is empty for the timeframe when i ran startx and the xorg log files are never written). I’ve also tried using lightdm to test if this is a problem with startx (displayManager.lightdm.enable = true; and take out the displayManager.startx and desktopManager parts). But when I run sudo systemctl start display-manager.service my computer also freezes and needs a coldboot.