Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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?

like image 633
Julian Stecklina Avatar asked Nov 13 '18 00:11

Julian Stecklina


People also ask

What is Nixpkg?

Overview of Nixpkgs. The Nix Packages collection (Nixpkgs) is a set of thousands of packages for the Nix package manager, released under a permissive MIT/X11 license. Packages are available for several platforms, and can be used with the Nix package manager on most GNU/Linux distributions as well as NixOS.

Where is Nixpkgs located?

Nix store. Packages built by Nix are placed in the read-only Nix store, normally found in /nix/store . Each package is given a unique address specified by a cryptographic hash followed by the package name and version, for example /nix/store/nawl092prjblbhvv16kxxbk6j9gkgcqm-git-2.14.

What is a Nix derivation?

Derivations are the building blocks of a Nix system, from a file system view point. The Nix language is used to describe such derivations.

What does Nix build do?

nix . nix-build is essentially a wrapper around nix-instantiate (to translate a high-level Nix expression to a low-level store derivation) and nix-store --realise (to build the store derivation). The result of the build is automatically registered as a root of the Nix garbage collector.


1 Answers

Try the pkgsMusl convenience attribute (source)

rec {
  pkgs = (import <nixpkgs> {}).pkgsMusl;
  # ...
}
like image 182
Robert Hensing Avatar answered Nov 15 '22 05:11

Robert Hensing