Managing nixpkgs with build flages like gentoo emerge

I think made a mistake in where to post…so I am posting in the help section

I am going to a grad student in the near future, and for legal reasons, I refuse to use university resources to build my stuff. For this reason, I am trying to squeeze as much as possible performance out of my computer.

I used to use gentoo, but it has a few issues like rollback isn’t is easy as NixOS. And if I had to reinstall NixOS i could just easily do it with flake. I also dont want to switch to Gentoo getting updates from github pkgs is so much easier. It is also so much easier to maintain pkgs with patches, for example.

Nevertheless, instead of using substituters and I would like to build nixpkgs on my local machine.

So far, after some help from other ppl I added system-features to nix.conf , specifically gccarch-native and then added nixpkgs.hostPlatform.gcc.arch = “native” to hardware-configuration.nix . So far with sudo nixos-rebuild boot --flake '.#workstation'--upgrade --offline , nixos is rebuilding all the packages.

So I have a few questions. First, is gccarch-native the correct feature to add that is similar to -march=native in gentoo? And my second question would be, how do I pass -02 -pipe whenever packages are built or is it native to nixos anyways? And is there anything else I can do to optimize gcc?

I was looking at NixOS’s discourd channel and there was post where someone applied flags
like this

self: super: {
  optimizeWithFlags = pkg: flags:
    pkg.overrideAttrs (old: {
      NIX_CFLAGS_COMPILE = [ (old.NIX_CFLAGS_COMPILE or "") ] ++ flags;

  optimizeForThisHost = pkg:
    self.optimizeWithFlags pkg [ "-O3" "-march=native" "-fPIC" ];

  openssl = self.optimizeForThisHost super.openssl;

Here is the link to that post: How to recompile a package with flags?

What I was wondering if this can applied for the whole system? or the toolchain?

Although I have been using NixOS for the past month or so, I am still a noob when it comes to the stuff I mentioned before.

Any help would be greatly appreciated


Hosted by Flying Circus.