query
On this page

compareVersions

lib.strings.compareVersions

Primop
Docs pulled from | This Revision | 18 minutes ago


Nix manual

Takes 2 arguments

s1, s2

Compare two strings representing versions and return -1 if version s1 is older than version s2, 0 if they are the same, and 1 if s1 is newer than s2. The version comparison algorithm is the same as the one used by nix-env -u.

Noogle detected

Aliases

Detected Type
compareVersions :: String -> String -> Int

Implementation

This function is implemented in c++ and is part of the native nix runtime.

src/libexpr/primops.cc:5284

static void prim_compareVersions(EvalState & state, const PosIdx pos, Value ** args, Value & v)
{
    auto version1 =
        state.forceStringNoCtx(*args[0], pos, "while evaluating the first argument passed to builtins.compareVersions");
    auto version2 = state.forceStringNoCtx(
        *args[1], pos, "while evaluating the second argument passed to builtins.compareVersions");
    auto result = compareVersions(version1, version2);
    v.mkInt(result < 0 ? -1 : result > 0 ? 1 : 0);
}