Most of my flakes contain something like this:
{
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11";
}
Eventually, the nixos-24.11
branch will be deprecated, and I’ll want to move my flakes to the nixos-25.05
branch. Once the nixos-24.11
branch is deprecated, I want to start getting some sort of warning or error that will tell me that the branch is deprecated. I want a warning or error because I want to make sure that I don’t forget to switch branches.
Here’s what I’ve come up with so far:
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11";
nixpkgs-master.url = "github:NixOS/nixpkgs/master";
};
outputs =
{
self,
nixpkgs,
nixpkgs-master,
}:
let
system = "x86_64-linux";
pkgs = nixpkgs.legacyPackages."${system}";
removePeriod = builtins.replaceStrings [ "." ] [ "" ];
in
{
checks."${system}".check-nixpkgs-version = pkgs.runCommand "check-nixpkgs-version" { } ''
${nixpkgs.lib.strings.toShellVars {
nixpkgsReleaseThatsBeingUsed = removePeriod nixpkgs.lib.trivial.release;
oldestSupportedNixpkgsRelease = nixpkgs-master.lib.trivial.oldestSupportedRelease;
}}
if [ "$nixpkgsReleaseThatsBeingUsed" -lt "$oldestSupportedNixpkgsRelease" ]
then
echo You’re using an unsupported Nixpkgs release. >&2
exit 1
fi
touch "$out"
'';
};
}
When I run nix flake check
on that flake, it will fail if I’m using an unsupported Nixpkgs release. It won’t fail if I’m using a deprecated Nixpkgs release. Is there anyway to make it fail if I’m using a deprecated Nixpkgs release? In other words, is there a way to programmatically determine if a Nixpkgs branch is deprecated?