Strange error building rustc on NixOS

I'm trying to build rustc on NixOS, and am writing a flake.nix file to provide the required dependencies, as is the idiom on NixOS.

So far, my flake.nix looks like this:

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

  outputs = { self, nixpkgs, flake-utils }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        pkgs = import nixpkgs {
          inherit system;
        };
      in
      {
        devShells.default = pkgs.mkShell {
          name = "rust";
          nativeBuildInputs = with pkgs; [
            gnumake
            cmake
            curl
            gcc
            python3

            pkg-config
            glibc.static
            gdb
          ];

          buildInputs = with pkgs; [
            pkg-config
            glibc.static
          ];
        };
      }
    );
}

Runnint ./x.py check then gives me this (fairly inscrutable (for me at least)) error. I've cut it down a bit, since it didn't fit in the forum's max character limit:

  = note: /nix/store/jfkmqz20q8fsaqizcml86adxqyzlwllx-binutils-2.38/bin/ld: /home/cameron/projects/rust/build/x86_64-unknown-linux-gnu/stage0/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-005d707108103aba.rlib(std-005d707108103aba.std.d3848c3a-cgu.0.rcgu.o): in function `std::sys::unix::os::home_dir::fallback':
          /rustc/82bf34178fb14562d158c4611bdab35d4d39b31c/library/std/src/sys/unix/os.rs:629: warning: Using 'getpwuid_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
          /nix/store/jfkmqz20q8fsaqizcml86adxqyzlwllx-binutils-2.38/bin/ld: /home/cameron/projects/rust/build/x86_64-unknown-linux-gnu/stage0/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-005d707108103aba.rlib(std-005d707108103aba.std.d3848c3a-cgu.0.rcgu.o): in function `<std::sys_common::net::LookupHost as core::convert::TryFrom<(&str,u16)>>::try_from':
          /rustc/82bf34178fb14562d158c4611bdab35d4d39b31c/library/std/src/sys_common/net.rs:205: warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
          /nix/store/jfkmqz20q8fsaqizcml86adxqyzlwllx-binutils-2.38/bin/ld: /home/cameron/projects/rust/build/x86_64-unknown-linux-gnu/stage0/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-005d707108103aba.rlib(std-005d707108103aba.std.d3848c3a-cgu.0.rcgu.o): undefined reference to symbol '__tls_get_addr@@GLIBC_2.3'
          /nix/store/jfkmqz20q8fsaqizcml86adxqyzlwllx-binutils-2.38/bin/ld: /nix/store/bzd91shky9j9d43girrrj6vmqlw7x9m8-glibc-2.35-163/lib/ld-linux-x86-64.so.2: error adding symbols: DSO missing from command line
          collect2: error: ld returned 1 exit status

  = help: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
  = note: use the `-l` flag to specify native libraries to link
  = note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#cargorustc-link-libkindname)

error: could not compile `bootstrap` due to previous error
failed to run: /home/cameron/projects/rust/build/x86_64-unknown-linux-gnu/stage0/bin/cargo build --manifest-path /home/cameron/projects/rust/src/bootstrap/Cargo.toml
Build completed unsuccessfully in 0:00:01

I'm not used to seeing these sorts of issues (on Arch, things mostly "just worked), so I don't have much experience resolving them.

Does anyone know what this error is complaining about? And how to fix it?

Or even better if anyone has a working flake.nix or shell.nix to build/test rustc

Thanks :grin:

I think you can't use a static glibc. As far as I can tell, for Rust glibc is required to be available as shared library.

Rust does support statically linking glibc, but as always with a statically linked glibc there are restrictions around which functionality you can use, which your program seems to violate. Hence the linker warnings. As for the actual linker error, not sure what is going on.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.