Rant: Finding errors in module configs after incompatible upgrades is dreadful

Normally, one should be happy if there’s an upgrade, but for Nix I’ve come to absolutely dread doing major version upgrades. When writing new code, it’s often fine if the error messages are not that clear because you usually have some kind of correlation between what you last did and the error messages occurring. But for major upgrades, whenever there’s some incompatible change, you are shit out of luck. Latest example, the error message:

error: nixVersions.unstable has been removed. For bleeding edge (Nix master, roughly weekly updated) use nixVersions.git, otherwise use nixVersions.latest.

Ok, that is mentioned in the release notes, but why do I have this issue?

~/dotfiles master !2 ❯ grep -r nixVersions
~/dotfiles master !2 ❯ 

Fantastic, let’s see what --show-trace says (I skip the part where I need to lookup again how to work around the cached failure because apparently people still think that is a good idea). Well, that’s just fantastic, lots of entries pointing to stuff in modules.nix, attrsets.nix and even aliases.nix, which was close, but the error messages were useless. The whole trace is just nixpkgs and home-manager, not a single thing goes back to my config.

So I start searching for the error message and after a bit I can trace it down to this line in my config:

modules/systems/base.nix:      package = pkgs.nixUnstable;

So why in the name of god can Nix show me hundreds of lines of traceback that are absolutely useless but not this line and say “HERE DUMMY, THIS IS NO LONGER ALLOWED, CHANGE IT”. And on an unrelated side note, when nixVersions.unstable is no longer allowed, why is this alias still there in nixos-24.05:

pkgs/top-level/aliases.nix:  nixUnstable = nixVersions.unstable; # Added 2022-01-26

I swear, the bigger my config gets and the more systems I add, the more of an issue all of this becomes. There’s no more happiness when NixOS releases new versions, it’s just the dread of fixing this kind of crap error while flying completely blind due to absolutely useless error messages and hoping that someone already encountered the issue and it was solved on Github.

Rant over.

8 Likes

oh yes! nix errors are utterly useless!

for example, i discovered, if you put certain dynamic constructions in modules section in nixos config - you get just infinite recursion error, not a single hint of why and where to look :slight_smile:

But anyway, getting an error is still better than getting your config built fine only later to discover that some (sometimes unannounced) breaking changes broke some of your services silently

Traces often being useless notwithstanding, we really need to clean aliases more aggressively. Opened top-level/aliases: Clean up outdated Nix aliases by jtojnar · Pull Request #316664 · NixOS/nixpkgs · GitHub

2 Likes

I wonder how hard and useful it would be to write a reducer for NixOS configurations. You give it a config that errors out and it removes bits and pieces from your config until it can’t reduce anymore without the error disappearing or changing.

It is as harder as to write a bisector.