From 15bfee85f35231be92e439e7f3f02e9aba34dcdf Mon Sep 17 00:00:00 2001 From: Nikolay Amiantov Date: Thu, 22 Mar 2018 01:22:05 +0300 Subject: [PATCH] impureUseNativeOptimizations: add stdenv adapter This allows one to force a compiler to use native machine optimizations. This goes contrary to all the usual guarantees of Nix and so should be used only by end-user and only in specific cases when they know what are they doing. In my case this is needed to get a noticeable FPS boost in RPCS3 which is very CPU-hungry PlayStation 3 emulator. --- pkgs/stdenv/adapters.nix | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pkgs/stdenv/adapters.nix b/pkgs/stdenv/adapters.nix index 734119491a0b..d3f7e4e99331 100644 --- a/pkgs/stdenv/adapters.nix +++ b/pkgs/stdenv/adapters.nix @@ -210,4 +210,19 @@ rec { NIX_CFLAGS_LINK = toString (args.NIX_CFLAGS_LINK or "") + " -fuse-ld=gold"; }); }; + + + /* Modify a stdenv so that it builds binaries optimized specifically + for the machine they are built on. + + WARNING: this breaks purity! */ + impureUseNativeOptimizations = stdenv: stdenv // + { mkDerivation = args: stdenv.mkDerivation (args // { + NIX_CFLAGS_COMPILE = toString (args.NIX_CFLAGS_COMPILE or "") + " -march=native"; + NIX_ENFORCE_NO_NATIVE = false; + + preferLocalBuild = true; + allowSubstitutes = false; + }); + }; }