Move CPU optimizations into their own role.
This is remove duplication between the individual hosts folders.
This commit is contained in:
147
nix/configuration/roles/optimized_build/default.nix
Normal file
147
nix/configuration/roles/optimized_build/default.nix
Normal file
@@ -0,0 +1,147 @@
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
pkgs-unoptimized,
|
||||
...
|
||||
}:
|
||||
|
||||
{
|
||||
imports = [ ];
|
||||
|
||||
options.me = {
|
||||
optimizations.enable = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = false;
|
||||
example = true;
|
||||
description = "Whether we want to enable CPU optimizations (will trigger a rebuild from source).";
|
||||
};
|
||||
|
||||
optimizations.arch = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = null;
|
||||
example = "znver4";
|
||||
description = "The CPU arch for which programs should be optimized.";
|
||||
};
|
||||
|
||||
optimizations.system_features = lib.mkOption {
|
||||
type = lib.types.listOf lib.types.str;
|
||||
default = [ ];
|
||||
example = [
|
||||
"gccarch-znver4"
|
||||
"gccarch-znver5"
|
||||
"gccarch-skylake"
|
||||
# "gccarch-alderlake" missing WAITPKG
|
||||
"gccarch-x86-64-v3"
|
||||
"gccarch-x86-64-v4"
|
||||
"benchmark"
|
||||
"big-parallel"
|
||||
"kvm"
|
||||
"nixos-test"
|
||||
];
|
||||
description = "The list of CPU features that should be enabled on this machine.";
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.mkMerge [
|
||||
(lib.mkIf (!config.me.optimizations.enable) (
|
||||
lib.mkMerge [
|
||||
{
|
||||
boot.kernelPackages = pkgs.linuxPackagesFor pkgs.linux_6_14;
|
||||
}
|
||||
]
|
||||
))
|
||||
(lib.mkIf config.me.optimizations.enable (
|
||||
lib.mkMerge [
|
||||
{
|
||||
boot.kernelPackages = pkgs.linuxPackagesFor pkgs.linux_me;
|
||||
|
||||
nixpkgs.hostPlatform = {
|
||||
gcc.arch = config.me.optimizations.arch;
|
||||
gcc.tune = config.me.optimizations.arch;
|
||||
system = "x86_64-linux";
|
||||
};
|
||||
|
||||
# Uncomment on of these to enable cross compiling:
|
||||
# nixpkgs.buildPlatform = builtins.currentSystem;
|
||||
# nixpkgs.buildPlatform = {
|
||||
# gcc.arch = "znver4";
|
||||
# gcc.tune = "znver4";
|
||||
# system = "x86_64-linux";
|
||||
# };
|
||||
|
||||
nixpkgs.overlays = [
|
||||
(
|
||||
final: prev:
|
||||
let
|
||||
addConfig =
|
||||
additionalConfig: pkg:
|
||||
pkg.override (oldconfig: {
|
||||
structuredExtraConfig = pkg.structuredExtraConfig // additionalConfig;
|
||||
});
|
||||
in
|
||||
{
|
||||
linux_me = addConfig {
|
||||
# Full preemption
|
||||
PREEMPT = lib.mkOverride 60 lib.kernel.yes;
|
||||
PREEMPT_VOLUNTARY = lib.mkOverride 60 lib.kernel.no;
|
||||
|
||||
# Google's BBRv3 TCP congestion Control
|
||||
TCP_CONG_BBR = lib.kernel.yes;
|
||||
DEFAULT_BBR = lib.kernel.yes;
|
||||
|
||||
# Preemptive Full Tickless Kernel at 300Hz
|
||||
HZ = lib.kernel.freeform "300";
|
||||
HZ_300 = lib.kernel.yes;
|
||||
HZ_1000 = lib.kernel.no;
|
||||
} prev.linux_6_14;
|
||||
}
|
||||
)
|
||||
(final: prev: {
|
||||
haskellPackages = prev.haskellPackages.extend (
|
||||
final': prev': {
|
||||
inherit (pkgs-unoptimized.haskellPackages)
|
||||
crypto-token
|
||||
crypton
|
||||
crypton-connection
|
||||
crypton-x509
|
||||
crypton-x509-store
|
||||
crypton-x509-system
|
||||
crypton-x509-validation
|
||||
hspec-wai
|
||||
http-client-tls
|
||||
http2
|
||||
pandoc
|
||||
pandoc-cli
|
||||
pandoc-lua-engine
|
||||
pandoc-server
|
||||
servant-server
|
||||
tls
|
||||
wai-app-static
|
||||
wai-extra
|
||||
warp
|
||||
;
|
||||
}
|
||||
);
|
||||
})
|
||||
(final: prev: {
|
||||
inherit (pkgs-unoptimized)
|
||||
gsl
|
||||
redis
|
||||
valkey
|
||||
;
|
||||
})
|
||||
];
|
||||
}
|
||||
]
|
||||
))
|
||||
(lib.mkIf (config.me.optimizations.system_features != [ ]) (
|
||||
lib.mkMerge [
|
||||
{
|
||||
nix.settings.system-features = lib.mkForce config.me.optimizations.system_features;
|
||||
}
|
||||
]
|
||||
))
|
||||
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user