[Packages/Overlays] Greatly tune and improve package automatic optimization

This commit is contained in:
Antoine Viallon 2022-03-27 01:17:06 +01:00
parent a3f7ca24b8
commit c2d8689dc4
Signed by: aviallon
GPG key ID: 186FC35EDEB25716
2 changed files with 49 additions and 5 deletions

View file

@ -3,13 +3,29 @@ with lib;
let
cfg = config.aviallon.overlays;
unstable = import (builtins.fetchTarball "https://github.com/NixOS/nixpkgs/archive/nixos-unstable.tar.gz") { config = config.nixpkgs.config; };
optimizeWithFlag = pkg: flag:
optimizeWithFlags = pkg: flags:
pkg.overrideAttrs (attrs: {
NIX_CFLAGS_COMPILE = (attrs.NIX_CFLAGS_COMPILE or "") + " ${flag}";
NIX_CFLAGS_COMPILE = toString ([ (attrs.NIX_CFLAGS_COMPILE or "") ] ++ flags);
doCheck = false;
});
optimizeForThisHost = pkg:
pkg.overrideAttrs (attrs: let
cflags = [ (attrs.NIX_CFLAGS_COMPILE or "") ] ++ config.aviallon.programs.compileFlags;
cxxflags = [ (attrs.CXXFLAGS or "") ] ++ config.aviallon.programs.compileFlags;
rustflags = [ (attrs.RUSTFLAGS or "") "-C target-cpu=${config.aviallon.general.cpuArch}" ];
pkgname = getName pkg;
cmakeflags = [ (attrs.cmakeFlags or "") ] ++ [ "-DCMAKE_CXX_FLAGS=\"${toString cxxflags}\"" ];
mytrace = name: value: builtins.trace "${pkgname}: ${name}: ${toString value}" (toString value);
in {
NIX_CFLAGS_COMPILE = mytrace "CFLAGS" cflags;
CXXFLAGS = mytrace "CXXFLAGS" cxxflags;
RUSTFLAGS = mytrace "RUSTFLAGS" rustflags;
configureFlags = mytrace "configureFlags" ([ (attrs.configureFlags or "") ] ++ [
"--enable-lto" "--enable-offload-targets=nvptx-none" "--disable-libunwind-exceptions"
]);
cmakeFlags = mytrace "cmakeFlags" cmakeflags;
doCheck = false;
});
optimizeWithFlags = pkg: flags: pkgs.lib.foldl' (pkg: flag: optimizeWithFlag pkg flag) pkg flags;
optimizeForThisHost = pkg: optimizeWithFlags pkg (builtins.trace "${getName pkg}: ${toString config.aviallon.programs.compileFlags}" config.aviallon.programs.compileFlags);
in
{
options.aviallon.overlays = {
@ -43,6 +59,16 @@ in
]);
}));
})
(self: super: {
libsForQt5 = super.libsForQt5.overrideScope' (mself: msuper: {
kwin = optimizeForThisHost msuper.kwin;
dolphin = optimizeForThisHost (msuper.dolphin.overrideAttrs (old: {
propagatedBuildInputs = old.propagatedBuildInputs ++ (with super; [
kio-fuse
]);
}));
});
})
(self: super: {
opensshOptimized = optimizeForThisHost super.openssh;
rsyncOptimized = optimizeForThisHost super.rsync;
@ -63,6 +89,8 @@ in
hwloc
]);
}));
mesa = optimizeForThisHost super.mesa;
xorgserver = optimizeForThisHost super.xorg.xorgserver;
steam = super.steam.override {
withJava = true;
};

View file

@ -22,7 +22,23 @@ in
type = types.bool;
};
compileFlags = mkOption {
default = [ "-O3" "-march=${generalCfg.cpuArch}" "-mtune=${generalCfg.cpuTune}" ];
default = [
"-O3" "-march=${generalCfg.cpuArch}" "-mtune=${generalCfg.cpuTune}"
"-feliminate-unused-debug-types" "--param=ssp-buffer-size=32"
# "-Wl,--copy-dt-needed-entries-m64-fasynchronous-unwind-tables"
"-fasynchronous-unwind-tables"
"-fno-semantic-interposition"
"-ffat-lto-objects"
"-fno-signed-zeros"
"-fno-trapping-math"
"-fassociative-math"
"-fexceptions"
"-ftree-loop-distribute-patterns"
"-Wl,-sort-common"
"-fno-semantic-interposition"
"-fipa-pta"
"-fdevirtualize-at-ltrans"
];
example = [ "-O2" "-mavx" ];
description = "Add specific compile flags";
type = types.listOf types.str;