diff --git a/lib/nix.nix b/lib/nix.nix new file mode 100644 index 00000000..c7f3455 --- /dev/null +++ b/lib/nix.nix @@ -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}; +} diff --git a/modules/simd.nix b/modules/simd.nix new file mode 100644 index 00000000..264f6e0 --- /dev/null +++ b/modules/simd.nix @@ -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; + }; + }; +}