Files

76 lines
3.8 KiB
Markdown
Raw Permalink Normal View History

2025-09-28 20:25:33 -05:00
---
title: "Nixos Build Issues"
date: 2025-09-28T20:06:51-05:00
draft: false
---
So I am doing a rebuild of my [NixOS](https://nixos.org) laptop in order to (supposedly) highly optimize the resulting
binary code for my local host. Or, at least, all of the libraries written in C. So doing this
was pretty straightforward. Before we can build the optimized code, we need to tell Nix that our
system supports this as a feature. So the first thing I enabled in my configuration is:
```nix
nix.settings.system-features = [ "gccarch-x86-64-v3" ];
```
A quick `nixos-rebuild switch` has me up and going in a few moments, as all it needs to do is
write a new `nix.conf` file.
## Enabling the Optimized Build
Now, enabling the optimized build in your system is pretty straightforward. All you need to do
is configure the `nixpkgs.hostPlatform`. The key setting to enable in my flake looks like such:
```nix
nixpkgs.hostPlatform = {
system = "x86_64-linux";
gcc.arch = "x86-64-v3";
};
```
Ostensibly you can do this as well if you are doing an `import nixpkgs { ... }` function somewhere,
but setting the above in my Flake config file was all I needed.
## Go Grab a Drink
...and a nap, and the rest of the afternoon, and probably an overnight sleep. Because this, for me,
on a daily driver laptop with Gnome took building more than 3300 packages. All the way up from a
bootstrap of the systems. My laptop, admittedly, isn't the most powerful system around. It's an
11th gen [Intel](https://www.intel.com) i7 mobile processor from [Framework](https://frame.work).
The benchmarks for it are kinda weak. The [i7-1165G7](https://www.cpubenchmark.net/cpu.php?cpu=Intel+Core+i7-1165G7+%40+2.80GHz&id=3814)
from those first generation Framework boards are great for day to day work, and it doesn't limit me
from anything that I need to do (I'm a software engineer, but most of what I do on my personal system
is writing little scripts and personal data tracking projects here and there and doing some VM
development). The low power consumption is great.
My point is, your mileage may vary. My home servers are much more potent systems and can probably get
their builds done much more quickly if this proves out to be useful.
## A Build Failure?!
Rather than waltz straight into a `nixos-rebuild switch` with wild abandon, I strongly recommend that
you trial the build process with a `nix build` or similar. At the very least you will want to do something
along the lines of `--keep-going` flag so that the builds continue. I know that NixOS builds are intended
to be reproducible. But that doesn't mean every single package in the build tree has completely figured
out deterministic tests.
For my purposes, I had a build failure somewhere in the middle of the bootstrapping process that
required me to manually build a single package. For me, it was the `bmake` package that failed when it
tried to run its unit tests. Proving that it was no fluke, it failed 3 more times in the midst of a
full system build. But it passes when built in isolation.
Since I was building a very specific version of `bmake` that included the architecture tuning,
I couldn't just do a `nix build "nixpkgs#bmake"` to get it into my local store. However, and this
only works with a flake configuration - you'll need slightly diffrent syntax if you aren't using flakes.
You can still get the build of a very specific package to happen. In my case, with a laptop host named
"exodus", I could do the following
```console
nix build ".#nixosConfigurations.exodus.pkgs.bmake"
```
This command build the exact version of the package that was going to be used on my system with the
optimizations in place and allowed me to progress the rest of the build.
This time, with the `--keep-going` flag in order to waste as little time as possible if there were
future hiccups.