One-off devshell in which `cc` uses musl libc?

What’s the most straightforward way to spin up a throwaway shell environment in which a C compiler and all the usual shell utilities are available (~ equivalent to Debian’s build-essential), and the C compiler uses musl libc as its C library?

I don’t need any other compiled-code languages besides C.

By “throwaway shell environment” I mean I’m looking for a “nix-shell” command line, or similar, not stuff to put in a package.nix.

2 Likes

with disclosure that I just asked a model:

nix-shell --expr "let pkgs = import <nixpkgs> {}; in pkgs.mkShell.override { stdenv = pkgs.pkgsMusl.stdenv; } {}"

but did a quick personal check and it seems to work:

$ gcc -dumpmachine
x86_64-unknown-linux-musl
2 Likes

That does seem to work well enough for what I’m trying to do right now. Thanks. I’ll leave the question open for a few days in case someone knows a less cryptic way to do it, or a way that works in more cases.

1 Like

The easiest is probably to just straight up use pkgsMusl.mkShell instead of regular mkShell

1 Like

did you test this? when I tried earlier there was no pkgsMusl.mkShell. I’d be curious to know if I missed it somehow :slight_smile:

What system did you test that on? Because pkgsMusl won’t eval outside of Linux. On my Linux boxes however pkgsMusl.mkShell works fine. (Same goes for all the other variants)

ahah! my bad - looked back at my nix repl history and realized I had tried pkgs.pkgsMusl.stdenv.mkShell instead of of pkgs.pkgsMusl.mkShell