From c2d8689dc4b7693f3950f40b3ec2409c2a1fa017 Mon Sep 17 00:00:00 2001 From: Antoine Viallon Date: Sun, 27 Mar 2022 01:17:06 +0100 Subject: [PATCH] [Packages/Overlays] Greatly tune and improve package automatic optimization --- overlays.nix | 36 ++++++++++++++++++++++++++++++++---- packages.nix | 18 +++++++++++++++++- 2 files changed, 49 insertions(+), 5 deletions(-) diff --git a/overlays.nix b/overlays.nix index 8c69d33..08f5f97 100644 --- a/overlays.nix +++ b/overlays.nix @@ -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; }; diff --git a/packages.nix b/packages.nix index 8b81614..7624e37 100644 --- a/packages.nix +++ b/packages.nix @@ -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;