How NixOS decides to compile the Linux kernel? And is there a way to avoid it?

Compiling the Linux kernel when running nixos-rebuild takes so much time, and freezes my PC in the meantime. How NOT to build the Linux kernel?

That means you’re either overriding something that changes the kernel, or you’re using a channel that isn’t being serviced by hydra, either because it’s very outdated or too new.

What is your config, and what’s the output of nix-shell -p nix-info --run "nix-info -m"?

1 Like

It happens when I set hardware.bumblebee.enable to true.

The output is

these 6 paths will be fetched (0.75 MiB download, 10.20 MiB unpacked):
  /nix/store/iw9x2m9lxk566qvcn13ypwyb6f2x7kdy-file-5.45
  /nix/store/i9x2sifgd2r28jmvm9yfnykjsmv9xbm9-gnu-config-2024-01-01
  /nix/store/6x42kczk505372wqayhjvwbmjwvxrrkp-gnumake-4.4.1
  /nix/store/s4xysdp2cx1r4zzqqr3c9v2z8q0g5zlj-patchelf-0.15.0
  /nix/store/bc0as359y5y067dfp7afrq1f011m9ny3-stdenv-linux
  /nix/store/x5pfxw8jkaifsbqqhf4lahjxlkm5mfqf-update-autotools-gnu-config-scripts-hook
copying path '/nix/store/i9x2sifgd2r28jmvm9yfnykjsmv9xbm9-gnu-config-2024-01-01' from 'https://cache.nixos.org'...
copying path '/nix/store/6x42kczk505372wqayhjvwbmjwvxrrkp-gnumake-4.4.1' from 'https://cache.nixos.org'...
copying path '/nix/store/s4xysdp2cx1r4zzqqr3c9v2z8q0g5zlj-patchelf-0.15.0' from 'https://cache.nixos.org'...
copying path '/nix/store/iw9x2m9lxk566qvcn13ypwyb6f2x7kdy-file-5.45' from 'https://cache.nixos.org'...
copying path '/nix/store/x5pfxw8jkaifsbqqhf4lahjxlkm5mfqf-update-autotools-gnu-config-scripts-hook' from 'https://cache.nixos.org'...
copying path '/nix/store/bc0as359y5y067dfp7afrq1f011m9ny3-stdenv-linux' from 'https://cache.nixos.org'...
 - system: `"x86_64-linux"`
 - host os: `Linux 6.1.105, NixOS, 24.05 (Uakari), 24.05.20240822.797f7dc`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.18.5`
 - channels(shico): `""`
 - nixpkgs: `/nix/store/5z81la6av4j0ckp0w1949lxiwjyyykks-source`

In that case you’ll build the nvidia kernel module, which might look similar to building the kernel, but it’s just doing some builds for the nvidia driver - no way around this, since it’s proprietary upstream can’t republish it, so the download has to happen on your computer and subsequently built for the kernel you’re running.

That said, it should not be freezing your PC, or take particularly long. While the build is running, can you keep an eye on your system stats to see if you run out of memory or something? This might be caused by mounting /tmp as a tmpfs, for example.

Bumblebee also might not actually be what you need, what GPU/CPU are you using? Is this actually a PC or a laptop?

You’re using the latest NixOS stable commit, but his seems suspicious, what about:

$ nix-channel --list
$ sudo nix-channel --list

Installing the nvidia driver without bumblebee does not trigger a Linux kernel compilation though. Doing what was suggested in this comment fixed my issue

nix-channel --list returns nothing.

sudo nix-channel --list:

nixos https://nixos.org/channels/nixos-23.11
nixpkgs-unstable https://nixos.org/channels/nixpkgs-unstable
1 Like

If your hardeware is new enough, I would recommend not using bumblebee and instead configuring prime render offload, which solves the same problem as bubblebee, but directly in the driver (and officially supported).

3 Likes

My hardware isn’t new. I would have expected bumblebee to work as it is basically abandoned software now and doesn’t change. But with every NixOS update, a new problem with bumblebee comes up .-.

That has been deprecated for months now, pretty sure there have been several critical CVEs since, you should upgrade to 24.05.

Idk if it’s used though, my configuration uses flakes with the updated version. Should I remove these channels if I primarily use flakes or update them instead?

Ah, I see, that also explains the empty channels in nix-info.

I’d suggest removing them, commands like nix-shell could in theory still use your channels, although nixpkgs.flake.setNixPath should override what your commands use these days. If nothing else, it saves a bit of disk space.

1 Like

Also, use nixos-unstable instead of nixpkgs-unstable (unless you know what you’re doing).

2 Likes