about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2012-12-28 16:36:09 +0100
committerEelco Dolstra <eelco.dolstra@logicblox.com>2012-12-28 16:36:09 +0100
commitcf8daf63120adedbeaf5bc8c2f396be2496a741e (patch)
tree74930a51b68976b616f8c7a7a9c1c07e191ed39c
parent6fd4f635300303906fd4b068b196b8e1310b9e6d (diff)
Add an option ‘stdenv.userHook’ to set a global stdenv setup hook
This allows various applications.  It allows users to set global
optimisation flags, e.g.

  stdenv.userHook = ''NIX_CFLAGS_COMPILE+=" -funroll-loops"'';

But the impetus is as an alternative to issue #229, allowing impure
stdenv setup for people who want to use distcc:

  stdenv.userHook = "source /my/impure/setup-script.sh";

This is probably a bad idea, but at least now it's a bad idea in
people's configuration and not in Nixpkgs. :-)
-rw-r--r--pkgs/stdenv/default.nix7
-rw-r--r--pkgs/stdenv/generic/default.nix3
-rw-r--r--pkgs/stdenv/generic/setup.sh6
-rw-r--r--pkgs/stdenv/linux/default.nix6
-rw-r--r--pkgs/stdenv/native/default.nix4
-rw-r--r--pkgs/stdenv/nix/default.nix4
-rw-r--r--pkgs/top-level/all-packages.nix2
7 files changed, 21 insertions, 11 deletions
diff --git a/pkgs/stdenv/default.nix b/pkgs/stdenv/default.nix
index 8e0da288eec70..67000670cd1b6 100644
--- a/pkgs/stdenv/default.nix
+++ b/pkgs/stdenv/default.nix
@@ -10,7 +10,7 @@
 # system, e.g., cygwin and mingw builds on i686-cygwin.  Most people
 # can ignore it.
 
-{system, stdenvType ? system, allPackages ? import ../.., platform}:
+{ system, stdenvType ? system, allPackages ? import ../.., platform, config }:
 
 assert system != "i686-cygwin" -> system == stdenvType;
 
@@ -24,7 +24,7 @@ rec {
   # be used with care, since many Nix packages will not build properly
   # with it (e.g., because they require GNU Make).
   stdenvNative = (import ./native {
-    inherit system allPackages;
+    inherit system allPackages config;
   }).stdenv;
 
   stdenvNativePkgs = allPackages {
@@ -35,13 +35,14 @@ rec {
 
   # The Nix build environment.
   stdenvNix = import ./nix {
+    inherit config;
     stdenv = stdenvNative;
     pkgs = stdenvNativePkgs;
   };
 
 
   # Linux standard environment.
-  stdenvLinux = (import ./linux {inherit system allPackages platform;}).stdenvLinux;
+  stdenvLinux = (import ./linux { inherit system allPackages platform config;}).stdenvLinux;
 
 
   # MinGW/MSYS standard environment.
diff --git a/pkgs/stdenv/generic/default.nix b/pkgs/stdenv/generic/default.nix
index 20cbb1b455ca1..311f66241c825 100644
--- a/pkgs/stdenv/generic/default.nix
+++ b/pkgs/stdenv/generic/default.nix
@@ -1,5 +1,5 @@
 { system, name ? "stdenv", preHook ? "", initialPath, gcc, shell
-, extraAttrs ? {}, overrides ? (pkgs: {})
+, extraAttrs ? {}, overrides ? (pkgs: {}), config
 
 , # The `fetchurl' to use for downloading curl and its dependencies
   # (see all-packages.nix).
@@ -58,6 +58,7 @@ let
               args = attrs.args or ["-e" (attrs.builder or ./default-builder.sh)];
               stdenv = result;
               system = result.system;
+              userHook = config.stdenv.userHook or null;
 
               # Inputs built by the cross compiler.
               buildInputs = lib.optionals (crossConfig != null) buildInputs;
diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh
index a9f9aa2af2f5d..d697fcb7c4fd4 100644
--- a/pkgs/stdenv/generic/setup.sh
+++ b/pkgs/stdenv/generic/setup.sh
@@ -869,4 +869,10 @@ genericBuild() {
 runHook postHook
 
 
+# Execute the global user hook (defined through the Nixpkgs
+# configuration option ‘stdenv.userHook’).  This can be used to set
+# global compiler optimisation flags, for instance.
+runHook userHook
+
+
 dumpVars
diff --git a/pkgs/stdenv/linux/default.nix b/pkgs/stdenv/linux/default.nix
index 3105e76f81778..777b2cf6a328f 100644
--- a/pkgs/stdenv/linux/default.nix
+++ b/pkgs/stdenv/linux/default.nix
@@ -7,7 +7,7 @@
 # The function defaults are for easy testing.
 { system ? builtins.currentSystem
 , allPackages ? import ../../top-level/all-packages.nix
-, platform ? null }:
+, platform ? null, config }:
 
 rec {
 
@@ -81,7 +81,7 @@ rec {
     {gcc, extraAttrs ? {}, overrides ? (pkgs: {}), extraPath ? [], fetchurl}:
 
     import ../generic {
-      inherit system;
+      inherit system config;
       name = "stdenv-linux-boot";
       preHook =
         ''
@@ -261,7 +261,7 @@ rec {
   #     dependency (`nix-store -qR') on bootstrapTools or the
   #     first binutils built.
   stdenvLinux = import ../generic rec {
-    inherit system;
+    inherit system config;
     
     preHook = commonPreHook;
     
diff --git a/pkgs/stdenv/native/default.nix b/pkgs/stdenv/native/default.nix
index a33a46c8512d4..524b2a53337b5 100644
--- a/pkgs/stdenv/native/default.nix
+++ b/pkgs/stdenv/native/default.nix
@@ -1,4 +1,4 @@
-{ system, allPackages ? import ../../.. }:
+{ system, allPackages ? import ../../.., config }:
 
 rec {
 
@@ -98,7 +98,7 @@ rec {
 
       fetchurlBoot = fetchurl;
 
-      inherit system shell gcc overrides;
+      inherit system shell gcc overrides config;
     };
 
 
diff --git a/pkgs/stdenv/nix/default.nix b/pkgs/stdenv/nix/default.nix
index 5e242b6e3a1c7..668bac5f0ae8e 100644
--- a/pkgs/stdenv/nix/default.nix
+++ b/pkgs/stdenv/nix/default.nix
@@ -1,6 +1,8 @@
-{ stdenv, pkgs }:
+{ stdenv, pkgs, config }:
 
 import ../generic rec {
+  inherit config;
+
   preHook =
     ''
       export NIX_ENFORCE_PURITY=1
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index 895d9db36c10b..e4001c63258c4 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -196,7 +196,7 @@ let
 
 
   allStdenvs = import ../stdenv {
-    inherit system stdenvType platform;
+    inherit system stdenvType platform config;
     allPackages = args: import ./all-packages.nix ({ inherit config system; } // args);
   };