Add simd module

This commit is contained in:
Sandro - 2023-01-02 22:23:00 +01:00
parent 91775e2b63
commit aa98422210
Signed by: sandro
GPG Key ID: 3AF5A43A3EECC2E5
2 changed files with 35 additions and 0 deletions

8
lib/nix.nix Normal file
View File

@ -0,0 +1,8 @@
{ lib, ... }:
{
# taken from https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/services/misc/nix-daemon.nix#L828-L832
# a builder can run code for `gcc.arch` and inferior architectures
gcc-system-features = arch: [ "gccarch-${arch}" ]
++ map (x: "gccarch-${x}") lib.systems.architectures.inferiors.${arch};
}

27
modules/simd.nix Normal file
View File

@ -0,0 +1,27 @@
{ config, lib, libS, ... }:
let
cfg = config.simd;
in
{
options.simd = {
enable = lib.mkEnableOption "optimized builds with simd instructions";
arch = lib.mkOption {
type = with lib.types; nullOr str;
default = null;
description = ''
Microarchitecture string for nixpkgs.hostPlatform.gcc.march and to generate system-features.
Can be determined with: ``gcc -march=native -Q --help=target | grep march``
'';
};
};
config = {
nix.settings.system-features = lib.mkIf (cfg.arch != null) (libS.nix.gcc-system-features config.simd.arch);
nixpkgs.hostPlatform = lib.mkIf cfg.enable {
gcc.arch = config.sandro.simd.arch;
inherit (config.nixpkgs) system;
};
};
}