coqPackages.metaFetch: fix sort predicate stability

Incorrect sorting predicate was found as part of
https://github.com/NixOS/nix/issues/12106 where `nix` was crashing on
the code like:

    $ nix eval --expr 'builtins.sort (a: b: true) [ 1 2 3 ]'
    ...
    Aborted (core dumped)

Note: the crash happens here because sorting predicate does not
implement `lessThan` and triggers assertion failures for
`std::stable_sort` that backs `builtins.sort`.

The change restores `lessThan` semantic for `version sorting`.
This commit is contained in:
Sergei Trofimovich 2024-12-26 23:00:05 +00:00
parent 9ceb1173fb
commit ef6ac2dd6e

View File

@ -27,7 +27,7 @@ let
sort
switch
switch-if
versionAtLeast
versionOlder
versions
;
@ -112,7 +112,7 @@ let
shortVersion =
x:
if (isString x && match "^/.*" x == null) then
findFirst (v: versions.majorMinor v == x) null (sort versionAtLeast (attrNames release))
findFirst (v: versions.majorMinor v == x) null (sort (l: r: versionOlder r l) (attrNames release))
else
null;
isShortVersion = x: shortVersion x != null;