Commit ef6ac2dd authored by Sergei Trofimovich's avatar Sergei Trofimovich
Browse files

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`.
parent 9ceb1173
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -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;