Recently, I was wondering why my computer was not starting way faster than it does. It’s a lot more powerful than the previous one, yet the difference does not feel very big.

As often, it turns out it’s due to IO waiting.

1. Let’s ask!

NixOS uses systemd, so we can directly ask systemd to nicely show what takes time:

➤ systemd-analyze critical-chain
The time when unit became active or started is printed after the "@" character.
The time the unit took to start is printed after the "+" character. @12.150s
└─ @12.150s
 └─ @12.149s
  └─dhcpcd.service @1.270s +10.879s
   └─ @1.257s
    └─ @1.255s
     └─pcscd.socket @1.254s
      └─ @1.243s
       └─systemd-timesyncd.service @1.214s +27ms
        └─systemd-tmpfiles-setup.service @1.204s +6ms
         └─ @1.202s
          └─run-user-1000-gvfs.mount @8.610s
           └─run-user-1000.mount @7.394s
            └─ @225ms
             └─systemd-remount-fs.service @193ms +30ms
              └─systemd-journald.socket @172ms
               └─-.mount @163ms
                └─-.slice @163ms

First thing to notice is the jump from @225ms to @7.394s: this is the step where I’m being asked for my password to mound the partition (run-user-1000.mount).

The next big jump is +10.879s by dhcpcd.service!

So, most of the time is spent waiting for the network!

2. Why?

My first question was: “Why is the network in the critical path of the boot process?”

And then: “If I cannot change that, can it be made faster?”

3. Solutions

First, we can disable from the critical path of the boot: = false;

However, the system will quickly boot up to the tty, and then the GUI will appear 1 or 2 seconds later, so it’s not that great a fix IMO.

Let’s assume we keep it then.

In this case, I know dhcpcd is waiting for any interface to have an IP assigned. This can be changed thanks to dhcpcd.wait:

networking = {
  # ...
  # no need to wait interfaces to have an IP to continue booting
  dhcpcd.wait = "background";

Changing this leads to a 50% improvement (from +10.879s to +5.216s): @7.299s
└─ @7.298s
 └─ @7.298s
  └─NetworkManager-wait-online.service @2.081s +5.216s
   └─NetworkManager.service @2.015s +61ms
    └─ @2.012s
     └─resolvconf.service @1.979s +31ms
      └─ @1.961s
       └─ @1.959s
        └─pcscd.socket @1.958s
         └─ @1.946s
          └─systemd-timesyncd.service @1.917s +27ms
           └─systemd-tmpfiles-setup.service @1.907s +7ms
            └─ @1.905s
             └─run-user-132.mount @2.332s
              └─ @215ms
               └─systemd-remount-fs.service @184ms +28ms
                └─systemd-journald.socket @161ms
                 └─-.mount @151ms
                  └─-.slice @151ms

Next, it’s waiting for the network to see if the IP it has got is not already owned by another host. On my local network, this should never be an issue, so let’s deactivate That:

networking = {
  # ...
  # avoid checking if IP is already taken to boot a few seconds faster
  dhcpcd.extraConfig = "noarp";

Rebooting, shows another 50% improvement (from +5.216s to +2.573s): @4.681s
└─ @4.680s
 └─ @4.680s
  └─NetworkManager-wait-online.service @2.106s +2.573s
   └─NetworkManager.service @2.037s +64ms
    └─ @2.034s
     └─resolvconf.service @2.001s +30ms
      └─ @1.982s
       └─ @1.981s
        └─pcscd.socket @1.979s
         └─ @1.968s
          └─systemd-timesyncd.service @1.937s +28ms
           └─systemd-tmpfiles-setup.service @1.927s +7ms
            └─ @1.925s
             └─run-user-132.mount @2.349s
              └─ @212ms
               └─systemd-remount-fs.service @181ms +29ms
                └─systemd-journald.socket @159ms
                 └─system.slice @148ms
                  └─-.slice @148ms

That’s good enough for the effort, so I’ll leave it at that.