82 lines
2.0 KiB
Nix
82 lines
2.0 KiB
Nix
{
|
|
config,
|
|
lib,
|
|
...
|
|
}:
|
|
|
|
{
|
|
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.build_arch = lib.mkOption {
|
|
type = lib.types.nullOr 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-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 [
|
|
{
|
|
nixpkgs.hostPlatform = {
|
|
gcc.arch = config.me.optimizations.arch;
|
|
gcc.tune = config.me.optimizations.arch;
|
|
};
|
|
}
|
|
]
|
|
))
|
|
(lib.mkIf (config.me.optimizations.build_arch != null) (
|
|
lib.mkMerge [
|
|
{
|
|
# Enable cross-compiling
|
|
nixpkgs.buildPlatform = {
|
|
gcc.arch = config.me.optimizations.build_arch;
|
|
gcc.tune = "generic";
|
|
system = "x86_64-linux";
|
|
};
|
|
}
|
|
]
|
|
))
|
|
(lib.mkIf (config.me.optimizations.system_features != [ ]) (
|
|
lib.mkMerge [
|
|
{
|
|
nix.settings.system-features = lib.mkForce config.me.optimizations.system_features;
|
|
}
|
|
]
|
|
))
|
|
];
|
|
}
|