If you want to apply this to any build, you can also leverage https://github.com/NixOS/nixpkgs/pull/61019 and add this to your ~/.config/nixpkgs/config.nix
(I have a 3900X, so a zen2 architecture)
{
platform.gcc.arch = "znver2";
}
or pass it as the config argument
nix-repl> :l
Added 12685 variables.
nix-repl> hostPlatform.avxSupport
false
nix-repl> archPkgs = import ./. { config = { platform.gcc.arch = "znver2"; }; }
nix-repl> archPkgs.hostPlatform.avxSupport
true
available options:
nix-repl> lib.attrNames lib.systems.architectures.features
[ "armv5te" "armv6" "armv7-a" "armv8-a" "bdver1" "bdver2" "bdver3" "bdver4" "broadwell" "btver1" "btver2" "default" "haswell" "ivybridge" "loongson2f" "mips32" "sandybridge" "skylake" "skylake-avx512" "westmere" "znver1" "znver2" ]
NOTE: these options default to false in normal nixpkgs, so any package which listens for these optimizations will cause rebuilds.