2024-07-16 12:52:52 +02:00
|
|
|
{ lib }:
|
|
|
|
|
|
|
|
{
|
2024-07-16 13:29:47 +02:00
|
|
|
optimizationLevel ? "O3",
|
|
|
|
enableLTO ? true,
|
|
|
|
enableNativeOptimizations ? true,
|
|
|
|
additionalFlags ? []
|
2024-07-16 12:52:52 +02:00
|
|
|
}:
|
|
|
|
|
|
|
|
pkg:
|
|
|
|
|
|
|
|
assert builtins.elem optimizationLevel [ "O0" "O1" "O2" "O3" "Ofast" "Os" "Oz" "Og" ];
|
|
|
|
|
|
|
|
let
|
2024-07-16 13:29:47 +02:00
|
|
|
flags = [ "-${optimizationLevel}" ]
|
|
|
|
++ lib.optional enableLTO "-flto"
|
|
|
|
++ lib.optional enableNativeOptimizations "-march=native"
|
|
|
|
++ additionalFlags;
|
2024-07-16 12:52:52 +02:00
|
|
|
in
|
|
|
|
pkg.overrideAttrs (prevAttrs: {
|
2024-07-16 13:29:47 +02:00
|
|
|
env.NIX_CFLAGS_COMPILE = (prevAttrs.env.NIX_CFLAGS_COMPILE or "")
|
|
|
|
+ lib.strings.concatStringsSep " " flags;
|
2024-07-16 12:52:52 +02:00
|
|
|
})
|