update-flake.nix: fix stable pkgs selection

In rare cases, the nixpkgs stable version of a package can be newer
than in unstable nixpkgs. [1]
When this happens, choose the newer stable version instead of the
older unstable version.

[1] E.g., when a package is updated in both nixpkgs stable and unstable,
and nixpkgs stable is released before unstable.
This commit is contained in:
Erik Arvstedt 2022-06-27 20:45:10 +02:00
parent 1ba7ccc547
commit 96144fde81
No known key found for this signature in database
GPG Key ID: 33312B944DD97846
1 changed files with 4 additions and 3 deletions

View File

@ -8,8 +8,8 @@ in rec {
# stable = { bitcoind = "0.21.1"; ... };
# unstable = { btcpayserver = "1.2.1"; ... };
# }
# A pinned pkg is added to `stable` if the stable and unstable pkg versions
# are identical.
# A pinned pkg is added to `stable` if its stable version is newer or
# identical to the unstable version.
versions = let
pinned = flake.legacyPackages.x86_64-linux.pinned;
pinnedPkgs = lib.filterAttrs (n: v: lib.isDerivation v) pinned;
@ -17,7 +17,8 @@ in rec {
unstable = pinned.pkgsUnstable;
isStable = builtins.partition (pkgName:
!(unstable ? "${pkgName}") ||
((stable ? "${pkgName}") && stable.${pkgName}.version == unstable.${pkgName}.version)
((stable ? "${pkgName}")
&& (builtins.compareVersions stable.${pkgName}.version unstable.${pkgName}.version >= 0))
) (builtins.attrNames pinnedPkgs);
in {
stable = lib.genAttrs isStable.right (pkgName: stable.${pkgName}.version);