mirror of
https://github.com/aviallon/nixos-lib.git
synced 2026-04-05 17:27:50 +00:00
[Packages/Optimizations] Move all optimization logic in a dedicated file
This commit is contained in:
parent
852b544a57
commit
a2c29a7c84
4 changed files with 129 additions and 132 deletions
|
|
@ -14,6 +14,7 @@
|
|||
./hardware.nix
|
||||
./laptop.nix
|
||||
./overlays.nix
|
||||
./optimizations.nix
|
||||
./non-persistence.nix
|
||||
];
|
||||
}
|
||||
|
|
|
|||
70
optimizations.nix
Normal file
70
optimizations.nix
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
{ config, pkgs, lib, myLib, ... }:
|
||||
with lib;
|
||||
let
|
||||
cfg = config.aviallon.optimizations;
|
||||
desktopCfg = config.aviallon.desktop;
|
||||
generalCfg = config.aviallon.general;
|
||||
|
||||
_optimizeAttrs = level:
|
||||
traceValSeq ((myLib.optimizations.makeOptimizationFlags {
|
||||
inherit level;
|
||||
cpuArch = generalCfg.cpuArch;
|
||||
extraCFlags = cfg.extraCompileFlags;
|
||||
}) // {
|
||||
preConfigure = ''
|
||||
cmakeFlagsArray+=(
|
||||
"-DCMAKE_CXX_FLAGS=$CXXFLAGS"
|
||||
"-DCMAKE_C_FLAGS=$CFLAGS"
|
||||
)
|
||||
'';
|
||||
doCheck = false;
|
||||
doInstallCheck = false;
|
||||
});
|
||||
optimizedStdenv = pkgs.addAttrsToDerivation _optimizeAttrs pkgs.fastStdenv;
|
||||
|
||||
optimizePkg = {level ? "normal" }: pkg:
|
||||
(
|
||||
if (hasAttr "stdenv" pkg.override.__functionArgs) then
|
||||
trace "Optimized ${getName pkg} with stdenv" pkg.override {
|
||||
stdenv = pkgs.addAttrsToDerivation (_optimizeAttrs level) pkgs.fastStdenv;
|
||||
}
|
||||
else
|
||||
warn "Can't optimize ${getName pkg}" pkg
|
||||
);
|
||||
in
|
||||
{
|
||||
options.aviallon.optimizations = {
|
||||
enable = mkOption {
|
||||
default = true;
|
||||
example = false;
|
||||
description = "Enable aviallon's optimizations";
|
||||
type = types.bool;
|
||||
};
|
||||
lto = mkEnableOption "enable LTO for some packages";
|
||||
extraCompileFlags = mkOption {
|
||||
default = [ "-mtune=${generalCfg.cpuTune}" ];
|
||||
example = [ "-O2" "-mavx" ];
|
||||
description = "Add specific compile flags";
|
||||
type = types.listOf types.str;
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
nixpkgs.overlays = mkBefore [
|
||||
(self: super: {
|
||||
htop = optimizePkg {} super.htop;
|
||||
nano = optimizePkg {level = "unsafe";} super.nano;
|
||||
virtmanager = optimizePkg {} super.virtmanager;
|
||||
libsForQt5 = super.libsForQt5.overrideScope' (mself: msuper: {
|
||||
kwin = optimizePkg {} msuper.kwin;
|
||||
dolphin = optimizePkg {} msuper.dolphin;
|
||||
});
|
||||
libsForQt514 = super.libsForQt514.overrideScope' (mself: msuper: {
|
||||
kwin = optimizePkg {level = "unsafe"; } msuper.kwin;
|
||||
dolphin = optimizePkg {} msuper.dolphin;
|
||||
});
|
||||
#wayland = optimizePkg super.wayland;
|
||||
})
|
||||
];
|
||||
};
|
||||
}
|
||||
117
overlays.nix
117
overlays.nix
|
|
@ -11,36 +11,6 @@ let
|
|||
overlays = config.nixpkgs.overlays;
|
||||
};
|
||||
nur = import (builtins.fetchTarball "https://github.com/nix-community/NUR/archive/master.tar.gz") { inherit pkgs; };
|
||||
optimizeWithFlags = pkg: flags:
|
||||
pkg.overrideAttrs (attrs: {
|
||||
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 = mytrace "cmakeflags" "-DCMAKE_CXX_FLAGS=${toString cxxflags}";
|
||||
configureflags = [ (attrs.configureFlags or "") ] ++ [
|
||||
"--enable-lto" "--enable-offload-targets=nvptx-none" "--disable-libunwind-exceptions"
|
||||
];
|
||||
mytrace = name: value: builtins.trace "${pkgname}: ${name}: ${toString value}" (toString value);
|
||||
in {
|
||||
stdenv = pkgs.fastStdenv;
|
||||
NIX_CFLAGS_COMPILE = mytrace "CFLAGS" cflags;
|
||||
CXXFLAGS = mytrace "CXXFLAGS" cxxflags;
|
||||
RUSTFLAGS = mytrace "RUSTFLAGS" rustflags;
|
||||
configureFlags = mytrace "configureFlags" configureflags;
|
||||
preConfigure = ''
|
||||
cmakeFlagsArray+=(
|
||||
"${cmakeflags}"
|
||||
)
|
||||
'';
|
||||
doCheck = false;
|
||||
});
|
||||
optimizeForThisHost = if (cfg.optimizations) then (pkg: _optimizeForThisHost pkg) else (pkg: pkg);
|
||||
in
|
||||
{
|
||||
options.aviallon.overlays = {
|
||||
|
|
@ -72,28 +42,7 @@ in
|
|||
inherit nur;
|
||||
})
|
||||
(self: super: {
|
||||
nextcloud-client = optimizeForThisHost (super.nextcloud-client.overrideAttrs (old: {
|
||||
nativeBuildInputs = old.nativeBuildInputs ++ (with super; [
|
||||
extra-cmake-modules
|
||||
]);
|
||||
buildInputs = old.buildInputs ++ (with super; with libsForQt5; [
|
||||
kio
|
||||
]);
|
||||
}));
|
||||
})
|
||||
# KDE packages
|
||||
(self: super: {
|
||||
libsForQt5 = super.libsForQt5.overrideScope' (mself: msuper: {
|
||||
kwin = optimizeForThisHost msuper.kwin;
|
||||
dolphin = optimizeForThisHost msuper.dolphin;
|
||||
});
|
||||
})
|
||||
(self: super: {
|
||||
opensshOptimized = optimizeForThisHost super.openssh;
|
||||
rsyncOptimized = optimizeForThisHost super.rsync;
|
||||
nano = optimizeForThisHost super.nano;
|
||||
veracrypt = optimizeForThisHost super.veracrypt;
|
||||
htop = optimizeForThisHost (super.htop.overrideAttrs (old: {
|
||||
htop = super.htop.overrideAttrs (old: {
|
||||
configureFlags = old.configureFlags ++ [
|
||||
"--enable-hwloc"
|
||||
];
|
||||
|
|
@ -107,26 +56,60 @@ in
|
|||
libnl
|
||||
hwloc
|
||||
]);
|
||||
}));
|
||||
# mesa = optimizeForThisHost super.mesa;
|
||||
#xorg = super.xorg.overrideScope' (mself: msuper: {
|
||||
# xorgserver = optimizeForThisHost msuper.xorgserver;
|
||||
#});
|
||||
});
|
||||
steam = super.steam.override {
|
||||
withJava = true;
|
||||
};
|
||||
ark = optimizeForThisHost (super.ark.override {
|
||||
ark = super.ark.override {
|
||||
unfreeEnableUnrar = true;
|
||||
});
|
||||
};
|
||||
ungoogled-chromium = super.ungoogled-chromium.override {
|
||||
enableWideVine = true;
|
||||
};
|
||||
chromium = super.chromium.override {
|
||||
enableWideVine = true;
|
||||
};
|
||||
|
||||
scribus = super.scribus.overrideAttrs (old: rec {
|
||||
version = "1.5.8";
|
||||
sha256 = "sha256-R4Fuj89tBXiP8WqkSZ+X/yJDHHd6d4kUmwqItFHha3Q=";
|
||||
src = super.fetchurl {
|
||||
url = "mirror://sourceforge/${old.pname}/${old.pname}-devel/${old.pname}-${version}.tar.xz";
|
||||
inherit sha256;
|
||||
};
|
||||
patches = with super; [
|
||||
# For Poppler 22.02
|
||||
(fetchpatch {
|
||||
url = "https://github.com/scribusproject/scribus/commit/85c0dff3422fa3c26fbc2e8d8561f597ec24bd92.patch";
|
||||
sha256 = "YR0ii09EVU8Qazz6b8KAIWsUMTwPIwO8JuQPymAWKdw=";
|
||||
})
|
||||
(fetchpatch {
|
||||
url = "https://github.com/scribusproject/scribus/commit/f19410ac3b27e33dd62105746784e61e85b90a1d.patch";
|
||||
sha256 = "JHdgntYcioYatPeqpmym3c9dORahj0CinGOzbGtA4ds=";
|
||||
})
|
||||
(fetchpatch {
|
||||
url = "https://github.com/scribusproject/scribus/commit/e013e8126d2100e8e56dea5b836ad43275429389.patch";
|
||||
sha256 = "+siPNtJq9Is9V2PgADeQJB+b4lkl5g8uk6zKBu10Jqw=";
|
||||
})
|
||||
(fetchpatch {
|
||||
url = "https://github.com/scribusproject/scribus/commit/48263954a7dee0be815b00f417ae365ab26cdd85.patch";
|
||||
sha256 = "1WE9kALFw79bQH88NUafXaZ1Y/vJEKTIWxlk5c+opsQ=";
|
||||
})
|
||||
(fetchpatch {
|
||||
url = "https://github.com/scribusproject/scribus/commit/f2237b8f0b5cf7690e864a22ef7a63a6d769fa36.patch";
|
||||
sha256 = "FXpLoX/a2Jy3GcfzrUUyVUfEAp5wAy2UfzfVA5lhwJw=";
|
||||
})
|
||||
];
|
||||
});
|
||||
# chromium = self.ungoogled-chromium;
|
||||
|
||||
myFirefox = (import ./packages/firefox.nix { pkgs = self; inherit lib; });
|
||||
xwayland = super.xwayland.overrideAttrs (old: {
|
||||
buildInputs = old.buildInputs or [] ++ [ super.makeWrapper ];
|
||||
postInstall = old.postInstall or "" + ''
|
||||
# Force EGL Stream support
|
||||
wrapProgram $out/bin/Xwayland --add-flags "-eglstream"
|
||||
'';
|
||||
});
|
||||
|
||||
ffmpeg-full = let
|
||||
withLto = super.ffmpeg-full.override { enableLto = false; rav1e = self.rav1e; };
|
||||
|
|
@ -137,7 +120,21 @@ in
|
|||
configureFlags = (old.configureFlags or []) ++ [ "--enable-libtensorflow" ];
|
||||
});
|
||||
in withTensorflow;
|
||||
|
||||
|
||||
myFirefox = (import ./packages/firefox.nix { pkgs = self; inherit lib; });
|
||||
})
|
||||
(self: super: {
|
||||
nextcloud-client = super.nextcloud-client.overrideAttrs (old: {
|
||||
nativeBuildInputs = old.nativeBuildInputs ++ (with super; [
|
||||
extra-cmake-modules
|
||||
]);
|
||||
buildInputs = old.buildInputs ++ (with super; with libsForQt5; [
|
||||
kio
|
||||
]);
|
||||
});
|
||||
})
|
||||
|
||||
];
|
||||
|
||||
aviallon.programs.allowUnfreeList = [
|
||||
|
|
|
|||
73
packages.nix
73
packages.nix
|
|
@ -12,6 +12,7 @@ in
|
|||
./programs/git.nix
|
||||
./programs/htop.nix
|
||||
./overlays.nix
|
||||
(mkRenamedOptionModule [ "aviallon" "programs" "compileFlags" ] [ "aviallon" "optimizations" "extraCompileFlags" ])
|
||||
];
|
||||
|
||||
options.aviallon.programs = {
|
||||
|
|
@ -21,78 +22,6 @@ in
|
|||
description = "Enable aviallon's programs";
|
||||
type = types.bool;
|
||||
};
|
||||
compileFlags = mkOption {
|
||||
default = [
|
||||
"-O3" "-march=${generalCfg.cpuArch}" "-mtune=${generalCfg.cpuTune}"
|
||||
"-feliminate-unused-debug-types"
|
||||
|
||||
# Pipe outputs instead of using intermediate files
|
||||
"-pipe"
|
||||
|
||||
"--param=ssp-buffer-size=32"
|
||||
|
||||
"-fasynchronous-unwind-tables"
|
||||
|
||||
# Use re-entrant libc functions whenever possible
|
||||
"-Wp,-D_REENTRANT"
|
||||
|
||||
# Fat LTO objects are object files that contain both the intermediate language and the object code. This makes them usable for both LTO linking and normal linking.
|
||||
# "-flto=auto" # Use -flto=auto to use GNU make’s job server, if available, or otherwise fall back to autodetection of the number of CPU threads present in your system.
|
||||
# "-ffat-lto-objects"
|
||||
|
||||
# Math optimizations leading to loss of precision
|
||||
"-fno-signed-zeros"
|
||||
"-fno-trapping-math"
|
||||
"-fassociative-math"
|
||||
|
||||
# Perform loop distribution of patterns that can be code generated with calls to a library (activated at O3 and more)
|
||||
"-ftree-loop-distribute-patterns"
|
||||
|
||||
"-Wl,-sort-common"
|
||||
|
||||
# The compiler assumes that if interposition happens for functions the overwriting function will have precisely the same semantics (and side effects)
|
||||
"-fno-semantic-interposition"
|
||||
|
||||
# Perform interprocedural pointer analysis and interprocedural modification and reference analysis. This option can cause excessive memory and compile-time usage on large compilation units.
|
||||
"-fipa-pta"
|
||||
|
||||
"-Wl,--enable-new-dtags"
|
||||
"-Wa,-mbranches-within-32B-boundaries"
|
||||
|
||||
# Stream extra information needed for aggressive devirtualization when running the link-time optimizer in local transformation mode.
|
||||
# "-fdevirtualize-at-ltrans"
|
||||
|
||||
##### Very aggressive and experimental options ######
|
||||
"-fmodulo-sched"
|
||||
"-fmodulo-sched-allow-regmoves"
|
||||
"-fgcse-sm" # "This pass attempts to move stores out of loops."
|
||||
"-fgcse-las" # "global common subexpression elimination pass eliminates redundant loads that come after stores to the same memory location"
|
||||
"-fdevirtualize-speculatively" # "Attempt to convert calls to virtual functions to speculative direct calls"
|
||||
|
||||
# Reduce code size, improving cache locality
|
||||
"-fira-hoist-pressure" # "Use IRA to evaluate register pressure in the code hoisting pass for decisions to hoist expressions. This option usually results in smaller code, but it can slow the compiler down."
|
||||
"-fira-loop-pressure" # "Use IRA to evaluate register pressure in loops for decisions to move loop invariants. This option usually results in generation of faster and smaller code on machines with large register files."
|
||||
"-flive-range-shrinkage" # "Attempt to decrease register pressure through register live range shrinkage. This is helpful for fast processors with small or moderate size register sets."
|
||||
"-fschedule-insns" # "If supported for the target machine, attempt to reorder instructions to eliminate execution stalls due to required data being unavailable."
|
||||
"-fsched-pressure" # "Enable register pressure sensitive insn scheduling before register allocation."
|
||||
"-fsched-spec-load" # "Allow speculative motion of some load instructions."
|
||||
"-fsched-stalled-insns=4" # Define how many insns (if any) can be moved prematurely from the queue of stalled insns into the ready list during the second scheduling pass"
|
||||
"-ftree-loop-ivcanon" # "Create a canonical counter for number of iterations in loops for which determining number of iterations requires complicated analysis."
|
||||
"-ftree-loop-im" # "Perform loop invariant motion on trees."
|
||||
"-ftree-vectorize" # "Perform vectorization on trees."
|
||||
|
||||
# Super experimental
|
||||
"-fgraphite-identity" # "Enable the identity transformation for graphite."
|
||||
"-floop-nest-optimize" # "Enable the isl based loop nest optimizer."
|
||||
"-floop-parallelize-all" # "Use the Graphite data dependence analysis to identify loops that can be parallelized."
|
||||
|
||||
## To be tested
|
||||
## "-ftree-parallelize-loops=N" : Parallelize loops, i.e., split their iteration space to run in n threads. This is only possible for loops whose iterations are independent and can be arbitrarily reordered.
|
||||
];
|
||||
example = [ "-O2" "-mavx" ];
|
||||
description = "Add specific compile flags";
|
||||
type = types.listOf types.str;
|
||||
};
|
||||
allowUnfreeList = mkOption {
|
||||
default = [ ];
|
||||
example = [ "nvidia-x11" "steam" ];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue