Skip to content

Commit

Permalink
coqPackages.metaFetch: fix sort predicate stability
Browse files Browse the repository at this point in the history
Incorrect sorting predicate was found as part of
NixOS/nix#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`.
  • Loading branch information
trofi committed Dec 26, 2024
1 parent 9ceb117 commit ef6ac2d
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkgs/build-support/coq/meta-fetch/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ let
sort
switch
switch-if
versionAtLeast
versionOlder
versions
;

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit ef6ac2d

Please sign in to comment.