Enabling march and mtune for kernel builds

Hello! I’m fairly new to nix and I’m having a fantastic experience except for struggling to replicate one aspect of my arch system. I’m trying build linux-xanmod with march and mtune set and I’m running to the following error relating to bootstrapping glibc on the build.

  boot.kernelPackages = pkgs.linuxPackages_xanmod_latest;
  nixpkgs.localSystem = {
    gcc.arch = "znver2";
    gcc.tune = "znver2";
    system = "x86_64-linux";
error: a 'x86_64-linux' with features {gccarch-znver2} is required to build '/nix/store/rbnjbsshwxiv7ax29wphsxbsrgsc7mkd-bootstrap-stage0-glibc-bootstrap.drv', but I am a 'x86_64-linux' with features {benchmark, big-parallel, kvm, nixos-test}

I’ve attempted adding:

features = [ "gccarch-znver2" ];

to nixpkgs.localSystem, but there is no apparent change in build output.

GCC w/ march and mtune set works on the running systems as shown here:

gcc -march=znver2 -mtune=znver2 /dev/null

/nix/store/rq6bh3qfrqnyqwik0w3q6w180zg3w2pa-binutils-2.38/bin/ld: cannot open output file a.out: Permission denied
collect2: error: ld returned 1 exit status

Note that without nixpkgs.localSystem set the build works fine, but I’m then not getting the optimizations I’m looking for.

Addition Resources:
Issue #49765

1 Like

Nixpkgs needs to set requiredFeatures in order to guarantee that the machine that builds your system can really do so. This is necessary because we’ve had problems with cpu extensions on the NixOS build farm. You could either configure your NixOS machine to have this feature, in the nix.settings.supported-features option (nix.conf), or you could use cross compilation to allow your system config to be built on any x86_64-linux host, including ones with other cpus.

You might want to hold off on that Benchmarking The Linux 5.19 Kernel Built With "-O3 -march=native" - Phoronix