How do I pin a specific version of glibc using shell.nix?

Hello!
I am trying to create a shell.nix for the sequoia project (Rust pgp implementation).

I need glibc 2.32 or greater. I thought I could simply pin a commit of nixpkgs-unstable that has 2.32 or greater but that does not seem to work.
I found 66e44425c6dfecbea68a5d6dc221ccd56561d4f1 from a PR to nixpkgs on GitHub.
I have the following:

# adapted from examples at https://nixos.wiki/wiki/Rust
let
  # Pinned nixpkgs, deterministic
  nixpkgs = import (fetchTarball ("https://github.com/NixOS/nixpkgs/archive/66e44425c6dfecbea68a5d6dc221ccd56561d4f1.tar.gz")) { };

  # Rolling updates, not deterministic.
  # pkgs = import (fetchTarball("channel:nixpkgs-unstable")) {};
in
nixpkgs.mkShell {
  buildInputs = [
    nixpkgs.rustup
    nixpkgs.openssl
    nixpkgs.pkgconfig
    nixpkgs.capnproto
    nixpkgs.gnumake
    nixpkgs.sqlite
    nixpkgs.nettle
    nixpkgs.clang
    nixpkgs.glibc
  ];
}

anyone see what I am doing wrong? I also tried specifying glibc-2_32 and variants but that did not work.

Thank you!

1 Like

So I may have the correct shell.nix but something else is off.
I executed nix-shell --pure.
I then echoed $PATH and do see only glibc 2.32 and greater available.

The error persists after cargo clean, then cargo test.
The error I see is:

error: /nix/store/q53f5birhik4dxg3q3r2g5f324n7r5mc-glibc-2.31-74/lib/libc.so.6: version `GLIBC_2.32' not found (required by sequoia/target/debug/deps/libproc_macro_hack-4d3ccf889f1c0a1c.so)

Here goes my rambling attempts at solving this compiling puzzle.

I have a feeling this is a variant of glibc-2.30 libraries link to glibc-2.27 · Issue #84043 · NixOS/nixpkgs · GitHub.
I have simplified this to:

  1. git clone git@github.com:rust-lang/futures-rs.git
  2. nix-shell -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/870dbb751f4d851a3dfb554835a0c2f528386982.tar.gz --verbose --pure
  3. cargo check

That yields this error:

error: /nix/store/q53f5birhik4dxg3q3r2g5f324n7r5mc-glibc-2.31-74/lib/libc.so.6: version `GLIBC_2.32' not found (required by futures-rs/target/debug/deps/libproc_macro_hack-c3f554c71dd3bf18.so)
  --> futures-macro/src/lib.rs:16:5

I am running stable nixOS.

I believe the main problem is that my nixOS glibc takes precedence over what I declare in shell.nix for some reason.

Hey,

Have you installed the toolchain using rustup a while ago? I’m inclined to think that you may have gc’d the glibc it was using, which is why it started whining.
I don’t think you should ever need to specify glibc in your shell’s buildInputs. --pure probably does not help either, because the rustup installations are impure.
There are ways to make this “impure” type of setup work, if you absolutely need to use rustup, otherwise I would highly suggest using GitHub - oxalica/rust-overlay: Pure and reproducible nix overlay of binary distributed rust toolchains or GitHub - mozilla/nixpkgs-mozilla: Mozilla overlay for Nixpkgs..
Bests

2 Likes

Yes! Thank you for this insight. I have rustup declared in my configuration.nix. I have imperatively installed toolchains using rustup.

I’ve also run nix-collect-garbage -d a few times since.

This sounds perfect! Rustup is not a requirement.

I approached this from what the nixos wiki had. But oxalica/rust-overlay solves my problem even more cleanly.

I tested nix-shell -p rust-bin.stable.latest.rust in a simplified project and it solved the GLIBC_2.32' not found compilation error. I am most certainly switching to that overly for Rust development on nixOS.

Thank you again @ldesgoui !

1 Like