My NixOS laptop often freezes

I have a newish laptop, only about one year old, that’s dual-booting NixOS and Windows. For some reason, on NixOS, it will routinely freeze, becoming unresponsive to keyboard, touchpad, touch screen, and everything. The mouse pointer stops moving. I also can’t do Ctrl+Alt+F1 to switch to a TTY. The only thing I can do is hard-poweroff my system by holding down the power button for ten seconds. This can’t be good.

It seems to happen a few times a day, at random times. That is, not only while I’m doing something compute-intensive.

I don’t think it could be the HD failing, since I just upgraded the SSD to a new one recently. (And this was happening before the upgrade, too.) I also don’t think it can be overheating, since this seems to happen when the computer’s cold, too.

Here’s my configuration.nix, if it helps.

I’ve tried looking through my log files, using the Log File Viewer, but I don’t see anything relevant, as far as I can tell. Maybe I don’t know what to look for, or am looking in the wrong files?

1 Like

What’s the model of the laptop? Check out GitHub - NixOS/nixos-hardware: A collection of NixOS modules covering hardware quirks. - perhaps someone already published tweaks specific to that model.

If it’s very new it’s worth trying the latest Linux kernel version (instead of the default LTS), by setting boot.kernelPackages = pkgs.linuxPackages_latest;.

You should be able to view the complete log from the previous boot using journalctl -b -1, there might me relevant information at the end.

Have you tried updating BIOS/firmware to the latest version? Helped me last time I had similar problem.

1 Like

Do you happen to use Linux 5.x and have an Intel GPU? There is a known bug in the in the i915 driver. I had to revert to 4.19 to get rid of the freezes.

You can find out whether this bug affects you by logging in on the machine with SSH (after a hang) and using journalctl or dmesg to hunt for a message along the lines of:

hsw iommu i915 0000:00:02.0: GPU HANG: ecode 7:0:0x00000000, hang on rcs0 (446)
2 Likes

It’s a Lenovo Yoga C930. I think it does have Intel graphics. I’m using whatever the default kernel is on unstable. Maybe I should try upgrading it or downgrading it.

I have

boot.kernelPackages = pkgs.linuxPackages_4_19;

In the configuration.nix of that machine, until it is fixed upstream.

I found nixOS to be extra IO-intensive by having installed it on a cheap USB key.
The pauses I had appeared to be exactly like your description.
Once I moved to an actual SSD the problem was gone.
I think it might depend on what SSD you are using.
When your input devices freeze it may also be the USB bus clogged.

I have the same problem, laptop (1 year old) crashes - using power button is the only way to reboot.
the thing is, I already have

boot.kernelPackages = pkgs.linuxPackages_4_19;

in my configuration.nix
Laptop: Asus Zenbook UX430UA-GV265T

I figured out that Firefox hardware acceleration was the culprit. I haven’t had any freezes yet, since disabling hardware acceleration on Firefox. See the discussion here at Mozilla.

That said, I wonder where I can find NixOS’s graphics driver settings. Is something disabled in the graphics driver that makes Firefox crash? Mozilla’s discussion recommends updating one’s graphics driver to one that supports WebGL. Does anyone know how to do that?

2 Likes

I may have spoke too soon—this problem persists, even without using a web browser. Also, maybe related to this, I get the same total system freeze whenever I unplug my external monitor and USB hub. I have no idea what’s going on here.

Sounds like you are able to reproduce this somewhat reliably. Perhaps with ssh connected with dmesg and journalctl open while you unplug an external monitor will give a clue?

I also have Intel graphics with a NUC. Here are some system settings I have which may be relevant:

    hardware.cpu.intel.updateMicrocode = true;

    hardware.firmware = with pkgs; [
      firmwareLinuxNonfree
    ];
    # Opengl / video hardware acceleration
    nixpkgs.config = {
      allowUnfree = true;
    };
    nixpkgs.config.packageOverrides = pkgs: {
      vaapiIntel = pkgs.vaapiIntel.override { enableHybridCodec = true; };
    };
    hardware.opengl = {
      enable = true;
      extraPackages = with pkgs; [
        vaapiIntel
        vaapiVdpau
        libvdpau-va-gl
        intel-media-driver
      ];
    };
2 Likes

@JonathanReeve I’d give it a try with Linux kernel 5.6 (pkgs.linuxPackages_latest).

I had two (IIRC) freezes with my Intel GPU on 4.19 (that release was initially perfectly fine, but some backports must have introduced regressions there as well - though I haven’t really verified this).

You might also want to use something like this:

# Enable all sysrq functions (useful to recover from some issues):
kernel.sysctl."kernel.sysrq" = 1; # NixOS default: 16 (only the sync command)
# Documentation: https://www.kernel.org/doc/html/latest/admin-guide/sysrq.html

To test if you can recover (unraw etc. - see e.g. Wikipedia) from the freezes (in some cases only the X server hangs).

1 Like

The sysrq approach is a good idea.

You want to use it to check whether it’s truly a kernel freeze, or whether you’re just running out of RAM and swapping or getting stuck in the OOM killer.

When you use the sysrq key combo for reboot, and it works, that indicates with some probability that it’s not a full kernel hang.

just in case, same needs to be done using vscode (Visual Studio Code October 2019)