Search code examples
rustnixmusl

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


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?


Solution

  • Try the pkgsMusl convenience attribute (source)

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