How do I override the libc in a Nix package to be musl?

2.6k Views Asked by At

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?

1

There are 1 best solutions below

2
On BEST ANSWER

Try the pkgsMusl convenience attribute (source)

rec {
  pkgs = (import <nixpkgs> {}).pkgsMusl;
  # ...
}