5

I'm using Nix as a dependency manager for a Rust program. I have the following default.nix (simplified, but working):

rec {
  pkgs = import <nixpkgs> {};

  hello = pkgs.stdenv.mkDerivation rec {
    name = "rust-hello";

    buildInputs = [
      pkgs.rustc
    ];

    src = ./source;

    buildPhase = "rustc main.rs -o rust-hello";
    installPhase = ''
      mkdir -p $out/bin
      install -s rust-hello $out/bin
    '';
  };
}

I'm trying to override the libc for all dependencies (including the Rust compiler) to be pkg.musl, but I fail to do so. How can this be achieved?

Julian Stecklina
  • 1,271
  • 1
  • 10
  • 24

1 Answers1

5

Try the pkgsMusl convenience attribute (source)

rec {
  pkgs = (import <nixpkgs> {}).pkgsMusl;
  # ...
}
hellow
  • 12,430
  • 7
  • 56
  • 79
Robert Hensing
  • 6,708
  • 18
  • 23
  • 1
    Robert, please indent (code-)blocks with four spaces instead of three backticks. – hellow Nov 13 '18 at 10:03
  • 1
    Note that referencing `pkgsMusl` or any package inside of it causes a massive build that runs for hours, thus limiting its usability. Some packages don't even build without some overrides (or at least in pkgsStatic space). But it seems to be the only way to get MUSL clang if you need to build with clang using MUSL library for static compilation. :( – LB2 Feb 29 '20 at 02:11