sometimes I have a setting in my system config that is a temporary fix for something.
For example a system (that I rarely start) started to fail to boot after an update and I discovered the following line:
boot.kernelPackages = pkgs.linuxPackages_5_15;
(due to some other unfortunate circumstances, I had to fix it with a rescue usb-stick, but that’s beside the point)
Unfortunately there was no comment telling me why I added that line, but it was probably some temporary fix, that I had just forgotten.
This is not the first time I wished there was a way how I could make my build fail after a certain date… so for example something like
boot.kernelPackages =
if buildins.isDateAfter buildins.getDate "01/01/2025"
then abort "look at this line again"
else pkgs.linuxPackages_5_15;
I know that this is not idiomatic, but is there a way to basically get this behaviour or a similar one?
You probably don’t want the external date, apart from that being an impurity and therefore just tricky to access, you don’t want to break recovery of old revisions (even if it’s rarely likely to be needed).
What you actually want is something within the source tree, that reflects the progression of nixpkgs being used past the point where the workaround might be needed. The release version number seems like an obvious and easy choice: bumps in 6-monthly increments, and when it bumps is a good time to re-evaluate your config (even if you’re following -unstable).
boot.kernelPackages =
assert lib.assertMsg (builtins.currentTime < 1735689600) "Look at this line again";
pkgs.linuxPackages_5_15;
But yes, currentTime is impure (for obvious reasons, generally you don’t want eval to depend on when you eval), so I wouldn’t normally recommend using it.
PS if you forgot to write a comment, how would you remember to write a good assertion message?
Ok thanks for the suggestions. Yeah I don’t want to introduce impurity into the building process and it’s absolutely right that I don’t want to prevent old configs from building.
So instead I created a small pre-commit hook that scans all files for lines containing “todo”, searches for a date in that line and just fails to commit if no such date exists or when it’s before the current date