Syncthing
After looking around the web for a little bit, I was unable to find anyone else really having the same problem I was having so that lead me to a horrible horrible place (this is a joke)… the nix docs. Or rather, mynixos, which is a wonderful collection of pretty much every setting available for every program and individiual setting you can have on nixOS.
As with all things nix related, the answer was of course to do things declaratively. After yoinking this syncthing template (which does a really good job explaining what’s going on by the way, definitely worth a read if you want this on your system) and looking a bit at the available settings for syncthing, I added this to my nix config.
# configure syncthing
services.syncthing = {
enable = true;
dataDir = "/home/void/Notes";
user = "void";
group = "users";
guiAddress = "127.0.0.1:8384";
systemService = false;
overrideDevices = true;
overrideFolders = true;
settings = {
devices = {
"laptop" = { id = "SUPER-SECRET-KEY"; };
"phone" = { id = "SUPER-SECRET-KEY"; };
};
folders = {
"Notes" = {
path = "/home/void/Notes";
devices = [ "laptop" ];
versioning = {
type = "simple";
params = {
keep = "10";
};
};
};
};
};
};The important part here is the systemService = false; line which should stop systemd from starting it at boot time which partly solved the issue but not entirely. To fully fix the issue (it truly pains me to say this but I was desperate and traditional searches were yielding nothing) I asked the dreaded A.I overlords for assistance… and they came through! Turns out I had a stray systemd unit file located in ~/.config/systemd/user/default.target.wants/ that was starting syncthing regardless of what settings I declared in the nix config file :sigh:
NetworkManager-wait-online
The networkManager-wait-online thing was less easy to fix than the syncthing… thing, but obviously it wasn’t too bad or I wouldn’t have written this section. Anyways here’s the solution as well as a bit of the trail that lead me there.
There was initially promising things in this post but reading further down it seems that masking the service does not change the wall time1 of booting. After some more digging around and some help from some forums, specifically this discourse and this github issue, I landed on adding the following to my nix config and it seems to be working with no ill side-effects which is nice.
systemd = {
services = {
...
NetworkManager-wait-online.enable = false;
};
};Results
After making those changes, lets rebuild and take a look at the new numbers!
sudo systemd-analyze
Startup finished in 5.360s (firmware) + 542ms (loader) + 6.535s (kernel) + 3.120s (userspace) = 15.558s
graphical.target reached after 2.813s in userspace.Wow! that’s a significant improvement, let’s see what the blame says.
sudo systemd-analyze blame
1.670s firewall.service
489ms display-manager.service
339ms tlp.service
309ms mpd.service
252ms dev-disk-by\x2duuid-8cc603c9\x2d273e\x2d4718\x2dad8a\x2d2d3f7a44894f.device
205ms rpcbind.service
199ms accounts-daemon.service
176ms vboxnet0.service
154ms systemd-udev-trigger.service
149ms suid-sgid-wrappers.serviceHere’s the top 10 longest running things at boot according to the systemd-analyze blame command and again wow! In the last post the longest service was over 7 seconds and now there’s only one taking over a second to run which is a huge improvement.
This was a particularly fast boot with a total time of 15.5 seconds, which compared to the starting point from last post of 49.5 seconds is much faster… roughly 3 times faster in fact! After rebooting it a few times it looks to be averaging about 15-20 seconds which is much more acceptable. Also, I have my drive encrypted so there’s roughly 3 seconds added to the boot time (in the kernel time according to systemd-analyze) from typing the password that could be shaved off but I’ll keep my security thank you :)
Oh! and here’s the new systemd-analyze plot image for those curious.
What did we learn?
The biggest take away for me from this little adventure with the magic rock, is that when using nixOS, you should ALWAYS do the settings and stuff declaratively in the config file when possible to avoid having random files (cough cough systemd units cough cough) messing up your stuff.
Conclusion
As is tradition, thank you for reading! I think I could probably optimize the boot time even more but a ~3x boot time speedup is more than enough for me so I think this will be the end of this particular journey unless I find some super cool thing that also further improves the speed.
Footnotes
wall time is the actual real life time it takes, so think starting a stopwatch and timing it over trusting the programs to accurately report the times they took.↩︎