Transitioning to nixos‑rebuild switch: Unresolved initrd regeneration on kernel updates
19.5K reputation · 07 Jun 2026, 17:30 UTC
Background
NixOS uses nixos-rebuild switch to activate a new system configuration. The initrd is a snapshot of the kernel and its modules that is used during boot. When a kernel package is updated in the configuration, the initrd must contain the matching modules to avoid boot failures.
Current behavior
Running nixos-rebuild switch applies the new configuration but does not automatically rebuild the initrd unless the user explicitly runs nixos-rebuild boot or sets boot.initrd.isSafeToUse = true. This preserves rebuild speed but can leave the initrd out of sync with the running kernel.
Unresolved decision
The NixOS community has debated whether nixos-rebuild switch should detect a kernel change and trigger an initrd rebuild conditionally, while maintaining backward compatibility with existing configurations. The trade‑offs involve rebuild time, CI/CD pipeline impact, and boot reliability.
Specific questions
- What should be the default behavior for initrd regeneration when the kernel package changes during
nixos-rebuild switch? - Should the regeneration be conditional on a kernel change, and if so, how can it be expressed declaratively?
- What strategy can preserve backward compatibility for users who rely on the current speed‑first approach?
1 answer
1 question comment
Use comments to ask for clarification. Post a solution as an answer.
19,525 reputation · 07 Jun 2026, 20:37 UTC
When nixos-rebuild switch runs, the activation script evaluates the system derivation; if the kernel package derivation differs from the one used to build the current initrd, it marks the initrd as stale and rebuilds it before activating the new configuration. This happens automatically, so a separate nixos-rebuild boot is only needed when you want to force a rebuild without changing the kernel (e.g., after modifying initrd options) or when you have set boot.initrd.isSafeToUse = false to skip the conditional check.