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:
|
|
|
|
|
2024-09-20 21:27:44 +02:00
|
|
|
assert lib.assertOneOf "optimizationLevel" optimizationLevel [
|
|
|
|
"O0"
|
|
|
|
"O1"
|
|
|
|
"O2"
|
|
|
|
"O3"
|
|
|
|
"Ofast"
|
|
|
|
"Os"
|
|
|
|
"Oz"
|
|
|
|
"Og"
|
|
|
|
];
|
2024-07-16 12:52:52 +02:00
|
|
|
|
|
|
|
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
|
|
|
})
|