How can I override the stdenv to be gcc11Stdenv with optimisations

I’m trying to test the effect of -march by compiling Nix packages and benchmarking them.

This is what I’m trying to use:

{ }:

let
  pkgs = import <nixpkgs> {
    overlays = [
      (self: super: {
        stdenv = super.stdenvAdapters.impureUseNativeOptimizations super.gcc11Stdenv;
      })
    ];
  };
in pkgs.mkShell {
  packages = with pkgs; [ zstd ];
}

I get infinite recursion though. What am I doing wrong?

Try something along the lines of this:

{ }:

let
  pkgs = import <nixpkgs> {
    config.replaceStdenv = { pkgs }: pkgs.gcc11Stdenv;
  };
in pkgs.mkShell {
  packages = with pkgs; [ zstd ];
}

Have not tested it but I expect it to work

1 Like

With nixpkgs-unstable, this patch is needed to avoid infinite recursion using replaceStdenv
https://github.com/NixOS/nixpkgs/pull/144747