Nix CPU global CPU flags

It used to be that setting

{ config, pkgs, lib, ... }:
{
    nixpkgs.localSystem = {
      gcc.arch = "cpufamily";
      gcc.tune = "cpufamily";
      system = "x86_64-linux";
    };
}

within configuration.nix would enable CPU optimization for the whole system. It however isn’t the case anymore, gcc.arch and gcc.tune have been, from as far as I can tell, discontinued.

How would one set CPU flags for the C compiler within NixOS 22.11? From reading about it I think

    nixpkgs.localSystem = {
      cpu = "cpufamily";
      system = "x86_64-linux";
    };
}

Would work but I can’t quite tell.

Can you please confirm the information I have found?

Thank you for your aid.

3 Likes

I have struggled with something similar. I wanted to do a build optimized for the x86-64-v3 feature level. Here is what didn’t work for me.

I started with just this:

  nixpkgs.localSystem = {
    gcc.arch = "x86-64-v3";
    gcc.tune = "generic";
    system = "x86_64-linux";
  };

This complained about nix system features, and so I had to add gccarch feature:

nix.settings.system-features = [ "nixos-test" "benchmark" "big-parallel" "kvm" "gccarch-x86-64-v3" ];

This then complained about the architecture not being valid, so I tried again targeting skylake instead:

  nix.settings.system-features = [ "nixos-test" "benchmark" "big-parallel" "kvm" "gccarch-skylake" ];
  nixpkgs.localSystem = {
    gcc.arch = "skylake";
    gcc.tune = "skylake";
    system = "x86_64-linux";
  };

With these flags the build did start to run, but from what I could see with ps none of the invocations of gcc actually had the march or mtune flags set as I’d expect. I interrupted the build and have given up on this for the time being.


I would be very interested to hear if you figure out a solution to this, especially if you get the micro-architecture feature level build working.

2 Likes