Custom build flags build failure

I am trying to build a specific package which requires the best possible performance, so I want to pass flags like -march and -mtune. I found this wiki page about build flags. So I’m trying to build the example from that page for my CPU:

let
  pkgs = import <nixpkgs> {
    localSystem = {
      gcc.arch = "znver3";
      gcc.tune = "znver3";
      system = "x86_64-linux";
    };
  };
in
  pkgs.openssl

I’m building this with the following command:

sudo nix-build test.nix --option system-features gccarch-znver3

But even this simple package fails to build.

Edit: I guess I’m just running in to this issue: Build failure · Issue #162 · besser82/libxcrypt · GitHub. Using <nixos-unstable> seems to work better. Let me try that with the thing I really wanted to build.

By the way, is there a way to only build the package itself with these options and not the build tools like gcc and perl?

That would be cross-building (from “generic x86-64” to “znver3”).