# How can I speed up \`nixos-rebuild switch\`?

**URL:** https://discourse.nixos.org/t/how-can-i-speed-up-nixos-rebuild-switch/65775
**Category:** Help
**Created:** [June 18, 2025, 3:26am UTC](https://discourse.nixos.org/t/how-can-i-speed-up-nixos-rebuild-switch/65775 "2025-06-18T03:26:27Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![phaeseeKe5Ee](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/p/f0a364/32.png) [@phaeseeKe5Ee](https://discourse.nixos.org/u/phaeseeKe5Ee)
#### Post date: [June 18, 2025, 3:26am UTC](https://discourse.nixos.org/t/how-can-i-speed-up-nixos-rebuild-switch/65775/1 "2025-06-18T03:26:27Z")

</div>

I have a `nixConfiguration` flake for multiple machine. The flake is pretty big, it include everything like home-manager as nixos module.  
Every time I running `nixos-rebuild switch` it start evaluating(?) the flake and it takes multiple minutes (mostly 3-4minutes) before it actually building/copying files. So it is very time consuming to test some even minor configuration changes.

My main PC is about 8 years old. Is evaluating with 4 minutes every time considered normal?  
Thanks!

---

<div class="post-metadata">

### Author: ![nobodyinperson](https://discourse.nixos.org/user_avatar/discourse.nixos.org/nobodyinperson/32/10308_2.png) [@nobodyinperson](https://discourse.nixos.org/u/nobodyinperson)
#### Post date: [June 18, 2025, 4:07am UTC](https://discourse.nixos.org/t/how-can-i-speed-up-nixos-rebuild-switch/65775/2 "2025-06-18T04:07:20Z")

</div>

If you have many inputs, each with their own different version of nixpkgs, it might help to use the [`follows` thing](https://discourse.nixos.org/t/recommendations-for-use-of-flakes-input-follows/17413) to reuse one nixpkgs across inputs. This should reduce eval time.

---

<div class="post-metadata">

### Author: ![phaeseeKe5Ee](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/p/f0a364/32.png) [@phaeseeKe5Ee](https://discourse.nixos.org/u/phaeseeKe5Ee)
#### Post date: [June 18, 2025, 4:59am UTC](https://discourse.nixos.org/t/how-can-i-speed-up-nixos-rebuild-switch/65775/3 "2025-06-18T04:59:27Z")

</div>

Just did that, now it only takes about 2 minutes.

---

<div class="post-metadata">

### Author: ![TLATER](https://discourse.nixos.org/user_avatar/discourse.nixos.org/tlater/32/4257_2.png) [@TLATER](https://discourse.nixos.org/u/TLATER)
#### Post date: [June 18, 2025, 5:56am UTC](https://discourse.nixos.org/t/how-can-i-speed-up-nixos-rebuild-switch/65775/4 "2025-06-18T05:56:40Z")

</div>

2 minutes sounds extremely excessive. You’d need to be evaluating the entire nixpkgs a good dozen times to get there.

Also keep an eye out for `import nixpkgs`, and check that you’re not thrashing - evaluating many nixpkgs instances is very memory hungry, and should be avoided.

Share your config if you can, or at least your `flake.nix`.

---

<div class="post-metadata">

### Author: ![phaeseeKe5Ee](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/p/f0a364/32.png) [@phaeseeKe5Ee](https://discourse.nixos.org/u/phaeseeKe5Ee)
#### Post date: [June 19, 2025, 11:10am UTC](https://discourse.nixos.org/t/how-can-i-speed-up-nixos-rebuild-switch/65775/5 "2025-06-19T11:10:44Z")

</div>

Thanks!  
Now I refactor my flake only using nixos-25.05 (before it have nixos-unstable and master branch), and removing the [applyPatch here](https://discourse.nixos.org/t/what-is-the-best-way-to-change-just-one-line-of-cmakeflags-with-overlay/65572/6) (which cost about 30s evaluation time), now my flake only evaluate in 1 minutes 15 seconds.  
Thanks so much for the advice!
