nixos is pretty darn cool

Posted on:July 27, 2023 at 03:17 PM

Disclaimer: I’m very much a newbie at NixOS, but wanted a place to show my excitement over this.

Context

4 years ago, I made the mistake of buying a Legion 5 for my personal use. It was pretty cheap for the hardware I managed to get at the time, but still it had a lot of downfalls. No USB-C charging meant that I had to lug a huge brick and the laptop around everywhere I went. This was okay at first, but eventually got really annoying once I started moving around a lot.

Linux support for legion devices wasn’t really good either. Granted, it was a first generation device that was brand new, but even so, it took months for the touchpad drivers to get patched into the mainline kernel. The built in Nvidia GPU wouldn’t turn off no matter how I tuned it on Hybrid, and the most annoyingly, the Legion design team made it so that the HDMI output bypasses integrated graphics and is connected directly to the discrete GPU.

Yea sure, performance improvements and all, but if someone wanted to game or go for performance, why on earth would I use HDMI 2.0 over Displayport 1.4? Rant aside, the laptop itself was quite of a workhorse, and I enjoyed being able to run basically anything on it. Having a portable 8 core 16 thread CPU was an amazing experience.

New Equipment

That said, I recently got tired of my back pains and decided to get a 2022 G14. This is the 6800H paired with a 6700S GPU, making it an all AMD laptop. This means, no more gimmicky Nvidia stuff on Linux, which is great. I also took the chance to make the switch to NixOS, since it was a fresh laptop anyways, and many people have been raving about NixOS. And it’s great.

Declarative System Management

This is coming from a person who loves the AUR and Arch very much, but NixOS blew my mind with some of the crazy stuff it can provide. I used to have to do a lot of my fresh installs in personalized scripts, but NixOS throws it all away and makes it all simple. From complex applications like bootloaders and kernel modules, are just a single line configuration in your file. It makes system configuration feel fresh and new again, as if I’m playing with legos without any worry of bricking anything.

Tangent: AMD P-states

While spending a few hours playing around with system configurations, a feature that was quite widely anticipated was recently merged into mainline kernel. AMD P-State EPP Performance was quite talked about as an alternative to both acpi_cpifreq and amd_pstate. And so, what usually would take me awhile, modifying kernel parameters, updating install scripts, backing up before rebooting and doing tests, was resolved in two lines in my nix configuration. Two lines. And it’s really great.

If you really want the best battery life, the standard amd_pstate (amd_pstate=passive) still is the king, but you sacrifice significant CPU throttling with no turbo boost at all. But being able to not be throttled while on power for certain occasions is incredible EPP tends to get much better battery life too.

EPP basically introduced as new variable, Energy Performance Profile that you can use as a hint to the CPU in other to tune your power profile. Using either TLP or auto cpu-freq to manage your CPU governer and hint, you can then significantly increase battery life without sacrificing too much performance. (Note that TLP will disable turbo boost).

With just powertop autotune and auto cpu-freq, I was able to get a measly 8-10 watts average when doing light development tasks, such as web development and browsing webpages. And when nix is rebuilding in the background, instead of getting really hot and throttle, it can temporarily boost to it’s max clock without any issues.

But the point being, it was stupidly easy to tune something like this in NixOS, because all the changes are declarative and you don’t need to manually track your changes to remembered what you tuned, what settings you’ve changed, etc. It made tuning the laptop fun again, something that was beginning to look like a chore.

I have a lot of to say about tuning a laptop for battery usage on linux, will probably make a separate post about this in the future.

Nix Shell

Nix Shell is another thing which has been absolutely fantastic and ingenious for dependency management. Being able to use direnv and declaring dependencies within directories and being able to go in and out of environments so easily is amazing, and it makes reverting to a normal debian/arch system feel ancient by comparison.

Reproducibility and rollback features

And of course, the best part of using something like Nix, is that I am able to copy these configuration files and plop them into a new system, and I basically have exactly the same set up. No more fiddling around with scripts and dependency management or any thing like that! And if anything goes wrong, you can very easily rollback a generation and fix anything you might have bricked!

For someone who spends hours tinkering and bricking stuff, this is a game changer, not having to plug a bootable usb to troubleshoot every time you brick something, makes tinkering and bricking stuff so much more … delightful. It was as if I just rediscovered the wonders of tinkering around with things.