How to pin the glibc version to 2.19

I am trying to compile a Kotlin native application on linix with a nix flake that depends on glibc 2.19, but I am not able to find out how I can fix the glibc version in my nix flake

{
  description = "Server equivalent of the popular Phoenix wallet";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
    flake-utils.url = "github:numtide/flake-utils";
  };

  outputs = { self, nixpkgs, flake-utils, ... }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        pkgs = import nixpkgs {
          inherit system;
          overlays = [ ];
        };
      in
      {
        packages = {
          default = pkgs.gnumake;
        };
        formatter = pkgs.nixpkgs-fmt;

        devShell = pkgs.mkShell {
          buildInputs = with pkgs; [
            # build dependencies
            sqlite
            curl
            jdk

            pkg-config
            ncurses
            glibc

            git
          ];

          shellHook = ''
             # FIXME: this need to go in a build task
            ./gradlew linuxX64DistZip
          '';
        };
      }
    );
}

What do you mean with “depends on”?
glibc is generally backwards compatible, i.e. you can run applications that were built against an older glibc than they were linked to.
The opposite doesn’t work however, if you have a program that was built against a very new glibc, you can’t use an old one.

Well for kotlin multiplatform looks like that is not the case because the project required the libc 2.19.

Probably works generally but not for my specific case, for this reason I need to fix the libc version

You can get the system revisions for older package versions from Nix Package Versions, then:

      let
        pkgs = import nixpkgs {
          inherit system;
          overlays = [ ];
        };
+      pkgs-glibc = import (builtins.fetchTarball {
+         url = "https://github.com/NixOS/nixpkgs/archive/b6f505c60a2417d4fad4dc5245754e4e33eb4d40.tar.gz";
+         sha256 = "sha256:0hhb8sar8qxi179d6c5h6n8f7nm71xxqqbynjv8pldvpsmsxxzh9";
+       }) { inherit system; };
      in
      {
        packages = {
          default = pkgs.gnumake;
        };
        formatter = pkgs.nixpkgs-fmt;

-       devShell = pkgs.mkShell {
+       devShell = pkgs.mkShellNoCC {
          buildInputs = with pkgs; [
            # build dependencies
            sqlite
            curl
            jdk

            pkg-config
            ncurses
            glibc

            git
-         ];
+         ]
+         ++ [ pkgs-glibc.glibc ];

          shellHook = ''
             # FIXME: this need to go in a build task
            ./gradlew linuxX64DistZip
          '';
        };

We use mkShellNoCC here since we don’t want to use the glibc that comes with the shell by default.

To check the version:

$ ldd --version
ldd (GNU libc) 2.19
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper.

Thanks, helpful.

I can ask if there is an easy way to get the commit where the glibc 2.19 live? I tried but I failed.

In addition thanks for the mkShellNoCC suggestion, it is new for me!

Running the build now, thanks!

1 Like