Nix Overrides That Expire Themselves
In a recent update to the Yesod-form package, project developer <source>72b767ed-9d0</source> introduced a new feature in version 1.7.10. This package relies on dependencies sourced from nixpkgs, which in turn frequently updates its Haskell package offerings from Hackage. Consequently, there exists a temporal gap between the time a package is incorporated into nixpkgs and when it's required for the project.
To address this temporal lag, developers can implement an override in the flake.nix file to ensure they have access to the more recent package version. However, when the nixpkgs version is subsequently updated, the override becomes obsolete. Traditionally, there hasn't been a mechanism to explicitly notify developers of this redundancy.
A colleague shared a technique that addresses this issue by prompting an alert when an override becomes unnecessary. During the Nix evaluation of the flake, the package versions are compared, and a warning is issued if the version is equal to or greater than the version specified in the override. Specifically, <source>hprev.yesod-form.version</source> represents the version that the pinned nixpkgs provides.
The <source>lib.versionAtLeast</source> function facilitates a comparison of version strings, while <source>lib.warnIf</source> takes center stage by displaying a message during evaluation when the specified condition holds true.
This innovative approach transcends the realm of package versions, extending its utility to any scenario where an override's justification can be articulated conditionally. One notable application involves the cleanup of overrides pertaining to packages that were formerly marked as broken within nixpkgs, but later regain their stability. Upon the resolution of the issue upstream, the warning message serves as a clear directive to remove the temporary workaround.
Written by urgent.news from Lobsters's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.
