From b0c0e0d7eb099a61479b2ca6b390d3b0809a5519 Mon Sep 17 00:00:00 2001 From: matthewcroughan Date: Tue, 24 Aug 2021 10:17:22 +0100 Subject: [PATCH] stdenv: introduce withCFlags Adds an easy method of appending compiler flags to your stdenv via a list. Co-authored-by: tomberek Co-authored-by: Gytis Ivaskevicius Co-authored-by: sternenseemann --- pkgs/stdenv/adapters.nix | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/pkgs/stdenv/adapters.nix b/pkgs/stdenv/adapters.nix index 971be95e935d..9884c219ff60 100644 --- a/pkgs/stdenv/adapters.nix +++ b/pkgs/stdenv/adapters.nix @@ -270,4 +270,25 @@ rec { allowSubstitutes = false; }); }); + + + /* Modify a stdenv so that it builds binaries with the specified list of + compilerFlags appended and passed to the compiler. + + This example would recompile every derivation on the system with + -funroll-loops and -O3 passed to each gcc invocation. + + Example: + nixpkgs.overlays = [ + (self: super: { + stdenv = super.withCFlags [ "-funroll-loops" "-O3" ] super.stdenv; + }) + ]; + */ + withCFlags = compilerFlags: stdenv: + stdenv.override (old: { + mkDerivationFromStdenv = extendMkDerivationArgs old (args: { + NIX_CFLAGS_COMPILE = toString (args.NIX_CFLAGS_COMPILE or "") + " ${toString compilerFlags}"; + }); + }); }