Nix: how to change stdenv in nixpkgs.mkShell

Viewed 1358

I'd like to override the stdenv for mkShell to use gcc10Stdenv. I've looked at https://nixos.wiki/wiki/Using_Clang_instead_of_GCC, which provides instructions for overriding stdenv, but it doesn't describe how to do it for mkShell when just making a shell without reference to any specific package (only for "Using Nix CLI on existing packages").

My question is whether it's possible to override stdenv for mkShell without an existing package? And if so, how?

1 Answers

Try:

pkgs.mkShell.override {stdenv = pkgs.gcc10Stdenv} {
  inputsFrom = ...;
  ...
}

This is the standard way to alter the inputs to packages (which are just functions) in nixpkgs. It should work in this case.

Alternately, you could just copy the mkShell implementation into ./mkShell.nix and import it, as Chris suggested.

let mkShell = import ./mkShell.nix;
in mkShell {
  lib = pkgs.lib; 
  stdenv = pkgs.gcc10Stdenv;
} { 
  inputsFrom = ...;
}

This is just a regular function, so we're calling it with two parameters.

Related