I’m on a new Thinkpad P15 Gen 2. I’m trying to dual boot Windows and NixOS. I’m at the point where I’ve installed NixOS on its partition and I’m trying to get my hardware set up correctly. However, since this laptop is quite new, a lot of sketchy stuff is going on with the drivers and it has caused quite a headache.
First, the WiFi adapter drivers are only on Linux kernel >=5.10, so I had to use an unstable (22.05) iso to do the install. Then I changed my channel back to 21.11 and added boot.kernelPackages = pkgs.linuxPackages_5_16 to my configuration.nix.
Now, I cannot figure out why my display isn’t working. I’m trying to use the plasma DE as a starting point, but I’ll happily use something else if it may get things to work. Here’s my configuration.nix:
# Edit this configuration file to define what should be installed on
# your system. Help is available in the configuration.nix(5) man page
# and in the NixOS manual (accessible by running ‘nixos-help’).
{ config, pkgs, ... }:
{
imports =
[ # Include the results of the hardware scan.
./hardware-configuration.nix
];
# Use the systemd-boot EFI boot loader.
boot.loader.systemd-boot.enable = true;
boot.loader.efi.canTouchEfiVariables = true;
boot.kernelPackages = pkgs.linuxPackages_5_16;
networking.hostName = "fins-thinkpad"; # Define your hostname.
networking.networkmanager.enable = true; # Easiest to use and most distros use this by default.
# Nvidia drivers unfree
nixpkgs.config.allowUnfree = true;
# Enable the X11 windowing system.
services.xserver.enable = true;
# Enable the Plasma 5 Desktop Environment.
services.xserver.displayManager.sddm.enable = true;
services.xserver.desktopManager.plasma5.enable = true;
services.xserver.videoDrivers = [ "nvidia" ];
hardware.opengl.enable = true;
users.users.finley = {
isNormalUser = true;
extraGroups = [ "wheel" ]; # Enable ‘sudo’ for the user.
};
environment.systemPackages = with pkgs; [
vim # Do not forget to add an editor to edit configuration.nix! The Nano editor is also installed by default.
wget
firefox
];
system.stateVersion = "22.05"; # Did you read the comment?
}
And my hardware-configuration.nix:
# Do not modify this file! It was generated by ‘nixos-generate-config’
# and may be overwritten by future invocations. Please make changes
# to /etc/nixos/configuration.nix instead.
{ config, lib, pkgs, modulesPath, ... }:
{
imports =
[ (modulesPath + "/installer/scan/not-detected.nix")
];
boot.initrd.availableKernelModules = [ "xhci_pci" "thunderbolt" "nvme" "usb_storage" "sd_mod" "sdhci_pci" ];
boot.initrd.kernelModules = [ ];
boot.kernelModules = [ "kvm-intel" ];
boot.extraModulePackages = [ ];
fileSystems."/" =
{ device = "/dev/disk/by-uuid/7e6bcba1-25e7-43f5-8dd2-1458d863c0c4";
fsType = "ext4";
};
fileSystems."/boot" =
{ device = "/dev/disk/by-uuid/19A7-C717";
fsType = "vfat";
};
swapDevices =
[ { device = "/dev/disk/by-uuid/14412169-fb90-4e0c-ae3f-735c817b8cf3"; }
];
# The global useDHCP flag is deprecated, therefore explicitly set to false here.
# Per-interface useDHCP will be mandatory in the future, so this generated config
# replicates the default behaviour.
networking.useDHCP = lib.mkDefault false;
networking.interfaces.enp11s0.useDHCP = lib.mkDefault true;
networking.interfaces.wlp9s0.useDHCP = lib.mkDefault true;
powerManagement.cpuFreqGovernor = lib.mkDefault "powersave";
hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;
# high-resolution display
hardware.video.hidpi.enable = lib.mkDefault true;
}
I am happy to post any more logs or files if they would be beneficial! Thanks so much for any help with this, I’ve been at it for over a day now and I’m really looking forward to getting this figured out eventually!
What exactly is the “not working” symptom? Your logs complain about modesetting being off, which makes sense because you’re apparently on nvidia. Nothing else seems out of the ordinary in those logs.
Ah sorry, forgot to explain that! When I boot, no display comes up and I have to ctrl+alt+F1 to get a shell. I would expect the display to come up since I’ve enabled the plasma5 desktop manager in my configuration.
The lines that concern me most in the logs are these ones:
Mar 19 19:47:21 fins-thinkpad xserver-wrapper[1077]: MESA-LOADER: failed to open iris: /run/opengl-driver/lib/dri/iris_dri.so: cannot open shared object file: No such file or directory (search paths /run/opengl-driver/lib/dri, suffix _dri)
Mar 19 19:47:21 fins-thinkpad xserver-wrapper[1077]: failed to load driver: iris
Mar 19 19:47:21 fins-thinkpad xserver-wrapper[1077]: MESA-LOADER: failed to open kms_swrast: /run/opengl-driver/lib/dri/kms_swrast_dri.so: cannot open shared object file: No such file or directory (search paths /run/opengl-driver/lib/dri, suffix _dri)
Mar 19 19:47:21 fins-thinkpad xserver-wrapper[1077]: failed to load driver: kms_swrast
Mar 19 19:47:21 fins-thinkpad xserver-wrapper[1077]: MESA-LOADER: failed to open swrast: /run/opengl-driver/lib/dri/swrast_dri.so: cannot open shared object file: No such file or directory (search paths /run/opengl-driver/lib/dri, suffix _dri)
I think those errors go away if I take the default kernel version from the 21.11 channel, but then I don’t have my wifi drivers.
Also, I’ve taken a look at the nixos-hardware repository but I wasn’t sure if I should use it since I didn’t see my specific device. I will take another look and maybe try the generic thinkpad module! Thanks for any more help or advice you can provide!
Hmm, sometimes the nvidia drivers will be incompatible with the newest shiniest kernel. That should normally result in build failures, though (and I don’t have the problems you do, despite running the same driver+kernel).
Okay I just tried installing that with nix-env, rebooted, and still no luck! Pastebin of the display manager logs: https://pastebin.com/raw/YycVPVVd
Still says glamor is failing to initialize, but I’m not sure if that would be what’s causing this. Somehow plasma was able to have a display when I was using the installer ISO, so there must be some configuration that will work, right? I am not necessarily tied to plasma at all, so I’d be willing to tear this configuration up if trying something else may help diagnose it. Thanks again for the help!
Unstable is on a much more recent nvidia driver, which is why this could work on unstable but not stable. That said, looking a bit more closely, your GPU should be supported by the default stable nvidia driver, so this may all be a red herring: Data Center Driver for Linux x64 | 460.73.01 | Linux 64-bit | NVIDIA
Still, since you saw it working on unstable at least once, I’d expect there to be a correct configuration too. If the above still doesn’t work, it’s maybe worth trying out whether switching to unstable temporarily just fixes the problem. Another thing to try would be services.xserver.displayManager.lightdm.enable instead of sddm, which is the only real meaningful difference between my config and yours
As an aside, I really recommend against ever using nix-env to install packages on NixOS, you’ll never lose those packages and come ask why your computer is broken 6 months from now, only to realize that your nix-env'd packages never updated and are now incompatible with a new X version or something. Use environment.systemPackages. nix-env is useful when you’re using nix as just a package manager on another distro, and don’t want to use home-manager.
In fact, it’s possible that prior use of that for sddm or such is causing your problems here.
Okay, I did nix-env -e '.*' which uninstalled the nvidia package from above and pciutils which I had also installed using that method. I will remember to never do that again, thank you for the tip!
I tried setting that hardware.nvidia.package with no luck. Then I downgraded my linux packages to 5.15, also no luck. Then I tried setting my display manager to lightdm and also no luck. Here is my configuration.nix now:
# Edit this configuration file to define what should be installed on
# your system. Help is available in the configuration.nix(5) man page
# and in the NixOS manual (accessible by running ‘nixos-help’).
{ config, pkgs, ... }:
{
imports =
[ # Include the results of the hardware scan.
./hardware-configuration.nix
];
# Use the systemd-boot EFI boot loader.
boot.loader.systemd-boot.enable = true;
boot.loader.efi.canTouchEfiVariables = true;
boot.kernelPackages = pkgs.linuxPackages_5_15;
networking.hostName = "fins-thinkpad"; # Define your hostname.
# Pick only one of the below networking options.
# networking.wireless.enable = true; # Enables wireless support via wpa_supplicant.
networking.networkmanager.enable = true; # Easiest to use and most distros use this by default.
# Set your time zone.
time.timeZone = "America/Denver";
# Configure network proxy if necessary
# networking.proxy.default = "http://user:password@proxy:port/";
# networking.proxy.noProxy = "127.0.0.1,localhost,internal.domain";
# Select internationalisation properties.
# i18n.defaultLocale = "en_US.UTF-8";
# console = {
# font = "Lat2-Terminus16";
# keyMap = "us";
# useXkbConfig = true; # use xkbOptions in tty.
# };
# Nvidia drivers unfree
nixpkgs.config.allowUnfree = true;
# Enable the X11 windowing system.
services.xserver.enable = true;
# Enable the Plasma 5 Desktop Environment.
services.xserver.displayManager.lightdm.enable = true;
services.xserver.desktopManager.plasma5.enable = true;
services.xserver.videoDrivers = [ "nvidia" ];
hardware.opengl.enable = true;
hardware.nvidia.package = pkgs.linuxKernel.packages.linux_5_15.nvidia_x11;
# Configure keymap in X11
# services.xserver.layout = "us";
# services.xserver.xkbOptions = {
# "eurosign:e";
# "caps:escape" # map caps to escape.
# };
# Enable CUPS to print documents.
# services.printing.enable = true;
# Enable sound.
# sound.enable = true;
# hardware.pulseaudio.enable = true;
# Enable touchpad support (enabled default in most desktopManager).
# services.xserver.libinput.enable = true;
# Define a user account. Don't forget to set a password with ‘passwd’.
users.users.finley = {
isNormalUser = true;
extraGroups = [ "wheel" ]; # Enable ‘sudo’ for the user.
};
# List packages installed in system profile. To search, run:
# $ nix search wget
environment.systemPackages = with pkgs; [
vim # Do not forget to add an editor to edit configuration.nix! The Nano editor is also installed by default.
wget
firefox
pciutils
];
# Some programs need SUID wrappers, can be configured further or are
# started in user sessions.
# programs.mtr.enable = true;
# programs.gnupg.agent = {
# enable = true;
# enableSSHSupport = true;
# };
# List services that you want to enable:
# Enable the OpenSSH daemon.
# services.openssh.enable = true;
# Open ports in the firewall.
# networking.firewall.allowedTCPPorts = [ ... ];
# networking.firewall.allowedUDPPorts = [ ... ];
# Or disable the firewall altogether.
# networking.firewall.enable = false;
# This value determines the NixOS release from which the default
# settings for stateful data, like file locations and database versions
# on your system were taken. It‘s perfectly fine and recommended to leave
# this value at the release version of the first install of this system.
# Before changing this value read the documentation for this option
# (e.g. man configuration.nix or on https://nixos.org/nixos/options.html).
system.stateVersion = "22.05"; # Did you read the comment?
}
I’m so new to this that I think I may be missing a very simple step somewhere. Based on this configuration, would you expect the desktop environment to come up automatically? Or do I need to run startx or something? After changing my DM to lightdm, the display-manager.service logs are only 4 lines ending with kbuildsycoca5 running....
Should I try switching to unstable and seeing what happens? And if I do switch to unstable, should I remove some lines from my configuration.nix?
I’m as lost as you are! My configuration is not too different. With your config, the display manager should just come up automatically (and it’s clearly trying to).
You can try startx, just to see if it’s X being totally borked, or if it’s something about these DMs. Set this option first: services.xserver.displayManager.startx.enable. I’d also add xterm to my systemPackages and make a ~/.xinitrc with:
exec xterm
If that still doesn’t work, I’d try switching to unstable. There’s nothing you need to change, besides your channels.
If that still doesn’t work, it might be time for an issue against github.com/nixos/nixpkgs… Or a friendly ping to some of the maintainers of these DM/X/nvidia modules, @jonringer might know what’s up.
When I tried startx I saw a page of logs with no errors and then no display came up, so it doesn’t seem like its an X thing. Then I tried switching to unstable by adding the channel, nix-channel --update, nixos-rebuild --switch and then rebooting. Still the same result!
So, should I report this somewhere else now? I’ve already made a post on Unix & Linux SE (no responses) and I have a post pending on LinuxQuestions, but this seems like it will require some Nix expertise beyond those sites
Thanks again so much for all of your help! I really appreciate it.
The nvidia config looks fine, other than hardware.nvidia.package = pkgs.linuxKernel.packages.linux_5_15.nvidia_x11; being repetitive, as this what services.xserver.videoDrivers = [ "nvidia" ]; under the covers.
I’ve never run a system with mixed intel/Nvidia CPUs, so I don’t actually know how you configure them. It’s possible you should be using the intel drivers to start X, rather than the nvidia ones.
The wiki has a good overview of how you get the more complex stuff to work, also nixos-hardware has an nvidia module that helps configure this: Nvidia - NixOS Wiki
I just changed services.xserver.videoDrivers to [ "modesetting" ] and now plasma DE is working… logged in and now have the normal KDE display. I was just looking at this section of the manual so I changed my drivers. What would that indicate? Am I okay to leave it as “modesetting”?
Awesome. I’ve got the prime stuff working now with KDE and lightdm. Here is the configuration I’ve landed on (finally posted directly from my nixos laptop):
# Edit this configuration file to define what should be installed on
# your system. Help is available in the configuration.nix(5) man page
# and in the NixOS manual (accessible by running ‘nixos-help’).
{ config, pkgs, lib, ... }:
let
nvidia-offload = pkgs.writeShellScriptBin "nvidia-offload" ''
export __NV_PRIME_RENDER_OFFLOAD=1
export __NV_PRIME_RENDER_OFFLOAD_PROVIDER=NVIDIA-G0
export __GLX_VENDOR_LIBRARY_NAME=nvidia
export __VK_LAYER_NV_optimus=NVIDIA_only
exec -a "$0" "$@"
'';
in
{
imports =
[ # Include the results of the hardware scan.
./hardware-configuration.nix
];
# Use the systemd-boot EFI boot loader.
boot.loader.systemd-boot.enable = true;
boot.loader.efi.canTouchEfiVariables = true;
boot.kernelPackages = pkgs.linuxPackages_5_15;
networking.hostName = "fins-thinkpad"; # Define your hostname.
networking.networkmanager.enable = true; # Easiest to use and most distros use this by default.
# Set your time zone.
time.timeZone = "America/Denver";
# Nvidia drivers unfree
nixpkgs.config.allowUnfree = true;
# Enable the X11 windowing system.
services.xserver.enable = true;
# Enable the Plasma 5 Desktop Environment.
services.xserver.displayManager.lightdm.enable = true;
services.xserver.desktopManager.plasma5.enable = true;
# Configure PRIME
services.xserver.videoDrivers = lib.mkDefault [ "nvidia" ];
# hardware.nvidia.modesetting.enable = true;
hardware.nvidia.prime = {
offload.enable = lib.mkDefault true;
intelBusId = "PCI:0:2:0";
nvidiaBusId = "PCI:1:0:0";
};
# Define a user account. Don't forget to set a password with ‘passwd’.
users.users.finley = {
isNormalUser = true;
extraGroups = [ "wheel" ]; # Enable ‘sudo’ for the user.
};
# List packages installed in system profile. To search, run:
# $ nix search wget
environment.systemPackages = with pkgs; [
vim # Do not forget to add an editor to edit configuration.nix! The Nano editor is also installed by default.
wget
firefox
pciutils
nvidia-offload
];
system.stateVersion = "22.05";
}
Do you know how I could use the nixos-hardware nvidia.nix file directly and then just et my own bus identifiers? I know there’s a way I can pull the configuration from that repo in my configuration.nix. Would you recommend doing that?
I’d also like to contribute a configuration for the Thinkpad P15 to the nixos/nixos-hardware repository, but I think I’ll need to take some time to minimize my own configuration using what’s already provided by that repository.
I’d recommend using the upstream recommendation for now, at least until you get comfortable with the ecosystem.
You can also use fetchurl to pin the repository in a let block, but it’s a bit of a dirty hack - probably not much harm in the short term, but I don’t think I would recommend it personally. Hacks have a habit of sticking around.
There are ways to do that that are actually designed for this purpose. Have a look at flakes (in-development future official way of doing this) or niv (current community-created option).