mirror of
https://github.com/aviallon/nixos-lib.git
synced 2026-04-06 01:38:06 +00:00
[Optimizations] Recursive optimizations (!)
This commit is contained in:
parent
b2c521273f
commit
52d7d35514
2 changed files with 81 additions and 21 deletions
|
|
@ -5,17 +5,19 @@ let
|
||||||
desktopCfg = config.aviallon.desktop;
|
desktopCfg = config.aviallon.desktop;
|
||||||
generalCfg = config.aviallon.general;
|
generalCfg = config.aviallon.general;
|
||||||
|
|
||||||
|
_trace = if cfg.trace then (traceValSeqN 2) else (x: x);
|
||||||
|
|
||||||
_optimizeAttrs =
|
_optimizeAttrs =
|
||||||
{
|
{
|
||||||
lto ? false ,
|
lto ? false ,
|
||||||
go ? false ,
|
go ? false ,
|
||||||
cmake ? true ,
|
cmake ? false ,
|
||||||
cpuArch ? generalCfg.cpuArch ,
|
cpuArch ? generalCfg.cpuArch ,
|
||||||
cpuTune ? generalCfg.cpuTune ,
|
cpuTune ? generalCfg.cpuTune ,
|
||||||
extraCFlags ? cfg.extraCompileFlags ,
|
extraCFlags ? cfg.extraCompileFlags ,
|
||||||
...
|
...
|
||||||
}@attrs:
|
}@attrs:
|
||||||
traceValSeq (
|
_trace (
|
||||||
(myLib.optimizations.makeOptimizationFlags ({
|
(myLib.optimizations.makeOptimizationFlags ({
|
||||||
inherit lto go cpuArch cpuTune extraCFlags;
|
inherit lto go cpuArch cpuTune extraCFlags;
|
||||||
} // attrs))
|
} // attrs))
|
||||||
|
|
@ -33,22 +35,69 @@ let
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
addAttrs = pkg: attrs: pkg.overrideAttrs (old: traceValSeqN 2 (myLib.attrsets.mergeAttrsRecursive old attrs) );
|
addAttrs = pkg: attrs: pkg.overrideAttrs (old: _trace (myLib.attrsets.mergeAttrsRecursive old attrs) );
|
||||||
|
|
||||||
optimizePkg = {level ? "normal", useAttrs ? false , ... }@attrs: pkg:
|
recurseOverrideCflags = pkg: { cflags ? compilerFlags, _depth ? 0 }:
|
||||||
let
|
let
|
||||||
optimizedAttrs = _optimizeAttrs (attrs // {inherit level; go = (hasAttr "GOARCH" pkg); });
|
deps = pkg.buildInputs or [];
|
||||||
optStdenv = pkgs.addAttrsToDerivation optimizedAttrs pkgs.fastStdenv;
|
depsOverriden = forEach deps (_pkg: recurseOverrideCflags _pkg {
|
||||||
in (
|
inherit cflags;
|
||||||
if (!useAttrs) && (hasAttr "stdenv" pkg.override.__functionArgs) then
|
_depth = _depth + 1;
|
||||||
trace "Optimized ${getName pkg} with stdenv at level '${level}'" pkg.override {
|
});
|
||||||
stdenv = optStdenv;
|
in if isNull pkg then
|
||||||
}
|
warn "pkg is null" pkg
|
||||||
else if (hasAttr "overrideAttrs" pkg) then
|
else if (hasAttr "overrideAttrs" pkg) then
|
||||||
trace "Optimized ${getName pkg} with overrideAttrs at level '${level}'" (addAttrs pkg optimizedAttrs)
|
info "Optimizing '${getName pkg}' at depth ${toString _depth}"
|
||||||
|
(pkg.overrideAttrs (old:
|
||||||
|
let
|
||||||
|
_cflags =
|
||||||
|
if (! hasAttr "CFLAGS" old) then
|
||||||
|
[]
|
||||||
|
else if isList old.CFLAGS then
|
||||||
|
old.CFLAGS
|
||||||
|
else
|
||||||
|
[ old.CFLAGS ]
|
||||||
|
;
|
||||||
|
in {
|
||||||
|
buildInputs = depsOverriden;
|
||||||
|
CFLAGS = _cflags ++ cflags;
|
||||||
|
}
|
||||||
|
))
|
||||||
else
|
else
|
||||||
warn "Can't optimize ${getName pkg}" pkg
|
warn "Couldn't optimize '${getName pkg}'" pkg
|
||||||
);
|
;
|
||||||
|
|
||||||
|
|
||||||
|
optimizePkg = {level ? "normal" , recursive ? 0 , _depth ? 0 , ... }@attrs: pkg:
|
||||||
|
if (hasAttr "overrideAttrs" pkg) then
|
||||||
|
let
|
||||||
|
optimizedAttrs = _optimizeAttrs (attrs // {inherit level; go = (hasAttr "GOARCH" pkg); });
|
||||||
|
_buildInputs = filter (p: ! isNull p ) (pkg.buildInputs or []);
|
||||||
|
_buildInputsOverriden = forEach _buildInputs (_pkg:
|
||||||
|
if (any (n: n == getName _pkg) cfg.blacklist) then
|
||||||
|
warn "Skipping blacklisted '${getName _pkg}'" _pkg
|
||||||
|
else optimizePkg ({}
|
||||||
|
// attrs
|
||||||
|
// {
|
||||||
|
inherit level recursive;
|
||||||
|
_depth = _depth + 1;
|
||||||
|
}) _pkg
|
||||||
|
);
|
||||||
|
_pkg =
|
||||||
|
if (recursive > _depth) then
|
||||||
|
pkg.overrideAttrs (old: {}
|
||||||
|
// {
|
||||||
|
buildInputs = _buildInputsOverriden;
|
||||||
|
}
|
||||||
|
// optionalAttrs (hasAttr "CFLAGS" old) {
|
||||||
|
CFLAGS = if (! isList old.CFLAGS ) then [ old.CFLAGS ] else old.CFLAGS;
|
||||||
|
}
|
||||||
|
)
|
||||||
|
else pkg;
|
||||||
|
in trace "Optimized ${getName pkg} with overrideAttrs at level '${level}' (depth: ${toString _depth})" (addAttrs _pkg optimizedAttrs)
|
||||||
|
else
|
||||||
|
warn "Can't optimize ${getName pkg} (depth: ${toString _depth})" pkg
|
||||||
|
;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options.aviallon.optimizations = {
|
options.aviallon.optimizations = {
|
||||||
|
|
@ -65,6 +114,13 @@ in
|
||||||
description = "Add specific compile flags";
|
description = "Add specific compile flags";
|
||||||
type = types.listOf types.str;
|
type = types.listOf types.str;
|
||||||
};
|
};
|
||||||
|
trace = mkEnableOption "trace attributes in overriden derivations";
|
||||||
|
blacklist = mkOption {
|
||||||
|
default = [ "cmocka" "libkrb5" "libidn2" "tpm2-tss" ];
|
||||||
|
example = [ "bash" ];
|
||||||
|
description = "Blacklist specific packages from optimizations";
|
||||||
|
type = types.listOf types.str;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
config = mkIf cfg.enable {
|
||||||
|
|
@ -90,10 +146,14 @@ in
|
||||||
})
|
})
|
||||||
|
|
||||||
(self: super: {
|
(self: super: {
|
||||||
opensshOptimized = optimizePkg { level = "very-unsafe"; lto = true; } super.openssh;
|
opensshOptimized = optimizePkg { level = "very-unsafe"; recursive = 0; lto = true; } super.openssh;
|
||||||
#libxslt = optimizePkg { level = "unsafe"; parallelize = generalCfg.cores; lto = true; } super.libxslt;
|
#libxslt = optimizePkg { level = "unsafe"; parallelize = generalCfg.cores; lto = true; } super.libxslt;
|
||||||
htop = optimizePkg {parallelize = generalCfg.cores; lto = true; } super.htop;
|
htop = optimizePkg {
|
||||||
nano = optimizePkg {level = "unsafe";} super.nano;
|
parallelize = generalCfg.cores;
|
||||||
|
lto = true;
|
||||||
|
recursive = 2;
|
||||||
|
} super.htop;
|
||||||
|
nano = optimizePkg {level = "unsafe"; recursive = 99; } super.nano;
|
||||||
virtmanager = optimizePkg {} super.virtmanager;
|
virtmanager = optimizePkg {} super.virtmanager;
|
||||||
libsForQt5 = super.libsForQt5.overrideScope' (mself: msuper: {
|
libsForQt5 = super.libsForQt5.overrideScope' (mself: msuper: {
|
||||||
plasma5 = msuper.plasma5.overrideScope' (mself: msuper: {
|
plasma5 = msuper.plasma5.overrideScope' (mself: msuper: {
|
||||||
|
|
|
||||||
|
|
@ -42,14 +42,14 @@ in
|
||||||
inherit unstable;
|
inherit unstable;
|
||||||
inherit nur;
|
inherit nur;
|
||||||
})]
|
})]
|
||||||
++ optional cfg.traceCallPackage [(self: super: {
|
++ optional cfg.traceCallPackage (self: super: {
|
||||||
callPackage = path: overrides:
|
callPackage = path: overrides:
|
||||||
let
|
let
|
||||||
_pkg = super.callPackage path overrides;
|
_pkg = super.callPackage path overrides;
|
||||||
_name = _pkg.name or _pkg.pname or "<unknown>";
|
_name = _pkg.name or _pkg.pname or "<unknown>";
|
||||||
in trace "callPackage ${_name}" _pkg
|
in trace "callPackage ${_name}" _pkg
|
||||||
;
|
;
|
||||||
})]
|
})
|
||||||
++ [(self: super: {
|
++ [(self: super: {
|
||||||
htop = super.htop.overrideAttrs (old: {
|
htop = super.htop.overrideAttrs (old: {
|
||||||
configureFlags = old.configureFlags ++ [
|
configureFlags = old.configureFlags ++ [
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue