Unable to build pkgsStatic.gcc

Trying to build pkgsStatic.gcc on my local NixOS system and am getting the following error at the end of the build:

mv: cannot stat '/nix/store/0xkrd6yzxbmylf4fzwkw0jczb9pvr0ra-gcc-static-x86_64-unknown-linux-musl-12.2.0-lib/lib/libgcc_s.so': No such file or directory

Full logs here. For posterity sake, tried in a fresh Nixified container with the same result. Any ideas on what’s going on? This is running against a fairly recent (as in last couple of days) version of nixpkgs-unstable.

1 Like

Are you sure you want pkgsStatic.gcc, i.e. a statically-linked gcc, rather than a gcc that produces static binaries? If you actually want the latter, you’re looking for pkgsStatic.buildPackages.gcc (or pkgsStatic.stdenv.cc).

1 Like

Why would one care how GCC was compiled?

There are reasons you might, for example if you wanted to be able to easily use the GCC you produced on another system, but it’s a much less common thing to want to do that produce static binaries with GCC.

Are you sure you want pkgsStatic.gcc , i.e. a statically-linked gcc, rather than a gcc that produces static binaries? If you actually want the latter, you’re looking for pkgsStatic.buildPackages.gcc (or pkgsStatic.stdenv.cc ).

Possibly. This originally came from my efforts to get a static version of cargo/rustc:

rust-bin-static =
  (nixpkgs.appendOverlays [
    (import rust-overlay)
rustToolchain-static = (rust-bin-static.fromRustupToolchainFile (inputs.self + "/rust-toolchain")).override {
  targets = ["x86_64-unknown-linux-musl"];

When I attempt to build the toolchain, it ends up building gcc-static-x86_64-unknown-linux-musl-12.2.0, which fails with the error I originally gave. It’s possible I’m not configuring this correctly. This is using rust-overlay.

Okay, same question again then: do you want to produce static binaries with cargo/rustc, or do you want to have actual static cargo/rustc executables?

For the latter, in Nixpkgs it’s not currently possible (cargo: fix cross by alyssais · Pull Request #196333 · NixOS/nixpkgs · GitHub), but I don’t know about with the overlay you’re using. If that is what you want, you will need an actual static gcc. This used to be possible (pkgsStatic.gcc: fix build · NixOS/nixpkgs@cb040db · GitHub), so you could figure out why it regressed by bisecting.

Yes, it would be the latter: building statically linked rust binaries with cargo/rustc. Thanks for the additional information on the current state of this. I pulled the rust-overlay solution from this issue. It’s possible it regressed since then. Unfortunately, troubleshooting the gcc build is a bit out of my league/capacity at the moment :frowning:

That sounds more like the former of what I asked about:

i.e., if I’m understanding you correctly, you don’t care about what kind of binary “cargo” is, you want to build some Rust application statically.

That’s very well supported. For example, pkgsStatic.ripgrep in Nixpkgs is a statically linked version of ripgrep, a Rust program. To build your own application statically, you can use pkgsStatic.callPackage, and with cargo/rustc from Nixpkgs it should just work.

1 Like

Fix here: pkgsStatic.gcc: fix build by alyssais · Pull Request #229635 · NixOS/nixpkgs · GitHub


When I do

nix build nixpkgs#pkgsStatic.ripgrep -L

it starts trying to build rustc with musl

x86_64-unknown-linux-musl-rustc> unpacking sources
x86_64-unknown-linux-musl-rustc> unpacking source archive /nix/store/ynffmxj771wdpd2hmg38as597asll39c-rustc-1.71.1-src.tar.gz

I think I’m missing something from where you say “with cargo/rustc from Nixpkgs”.

How do you use rustPlatform.buildRustPackage to statically compile a package without compiling rustc with musl?

1 Like

@RaitoBezarius told me this isn’t possible with the existing rust build infra in Nixpkgs

I was able to compile a statically linked rust program without compiling my own rust by cribbing off of the Determinate Nix Installer and using Fenix and naersk.

1 Like