diff --git a/nix/checks.nix b/nix/checks.nix index 3fdd5ba2c0..a6b66eb8a8 100644 --- a/nix/checks.nix +++ b/nix/checks.nix @@ -954,6 +954,25 @@ postgresql_17_src ; psql_orioledb-17_exts_orioledb_debug = self'.legacyPackages.psql_orioledb-17.exts.orioledb.debug; + glibc-version-check = + let + checkScript = pkgs.writers.writeNuBin "check-glibc-version" { + makeWrapperArgs = [ + "--prefix" + "PATH" + ":" + "${lib.makeBinPath [ pkgs.binutils ]}" + ]; + } (builtins.readFile ./tools/check-glibc-version.nu); + in + pkgs.runCommand "glibc-version-check" + { + paths = lib.collect lib.isDerivation (self'.legacyPackages // self'.packages); + } + '' + ${lib.getExe checkScript} 2.31 $paths + touch $out + ''; }; }; } diff --git a/nix/tools/check-glibc-version.nu b/nix/tools/check-glibc-version.nu new file mode 100755 index 0000000000..fb5617e884 --- /dev/null +++ b/nix/tools/check-glibc-version.nu @@ -0,0 +1,38 @@ +#!/usr/bin/env nu + +def parse-version [] { + split row "." | each { into int } +} + +def is-elf []: path -> bool { + (open --raw $in | bytes at 0..<4) == ("\u{7f}ELF" | into binary) +} + +def max-glibc-version [path: path] { + ^objdump -T $path | complete | get stdout + | parse -r 'GLIBC_(?[0-9.]+)' | get ver + | each { parse-version } + | sort + | last +} + +# Fails if any file under the given paths requires a newer glibc than max_version. +def main [max_version: string, ...paths: path] { + let offenders = ( + $paths + | each { glob $"($in)/**/*" } | flatten + | where { ($in | path type) == file } + | where { is-elf } + | par-each { |f| { file: $f, version: (max-glibc-version $f) } } + | compact version + | where version > ($max_version | parse-version) + ) + + if ($offenders | is-empty) { + print $"glibc version OK \(<= ($max_version)\)" + exit 0 + } + + print $offenders + exit 1 +}