I have just discovered NixOS. As a Gentoo user I really would like to globally declare the optimization flags.
I tried reading the Nix manuals to search for a solution. Unfortunaly they are so large, but still software optimization is suspiciously missing from them. I don’t have the time nor skills to reverse engineer the sources to achieve this goal.
Is there a hope for me? Could I ask for help on how to get what I want?
Unfortunately, for someone new, like me, this is useless in current form.
Do I paste it directly into the configuration file?
Also, what about other languages? I am thinking of Gentoo’s CXXFLAGS and similar other counterparts. I hope NIX_CFLAGS_COMPILE is simply injected everywhere and the “C” part is just a misunderstanding.
I did try a leap of faith by simply entering the expression from the other topic, but it fails. This is what I have in configuration.nix:
If I were to move it into a separate file, would I have to open it with a { pkgs, ... }: pattern? I am still not familiar with how function patterns work.
EDIT:
I am happy to report, that gcc just complained about wrong znver2 being a wrong march. This means, that the expression seems to be correct.
The drawback of this method is that it overrides the mkDerivation attributes that exist in packages already. And many nixpkgs packages do in fact utilize NIX_CFLAGS_COMPILE and NIX_LDFLAGS.
But it isn’t elegant as you cannot turn such flags off for individual packages or even in nix-shell. They become part of the compiler wrapper itself.
Does anyone know a better method?
Did you ever figure it out? I am having the same issue - I want to apply global linker flags to all packages through an overlay.
For example: LDFLAGS=“-rtlib=compiler-rt -unwindlib=libunwind -stdlib=libc++ -lc++abi -Oz -flto=thin -fsanitize=cfi -fvisibility=hidden” with a full llvm toolchain.