* Allow the Nixpkgs config to be passed as a function argument (rather

than through ~/.nixpkgs/config.nix or $NIXPKGS_CONFIG).

svn path=/nixpkgs/trunk/; revision=16861
This commit is contained in:
Eelco Dolstra 2009-08-26 13:51:37 +00:00
parent 781a112230
commit 24487fa73e

View file

@ -29,9 +29,15 @@
, gccWithCC ? true , gccWithCC ? true
, gccWithProfiling ? true , gccWithProfiling ? true
, # Allow a configuration attribute set to be passed in as an
# argument. Otherwise, it's read from $NIXPKGS_CONFIG or
# ~/.nixpkgs/config.nix.
config ? null
}: }:
let config_ = config; in # rename the function argument
let let
lib = import ../lib; # see also libTests below lib = import ../lib; # see also libTests below
@ -39,7 +45,7 @@ let
# The contents of the configuration file found at $NIXPKGS_CONFIG or # The contents of the configuration file found at $NIXPKGS_CONFIG or
# $HOME/.nixpkgs/config.nix. # $HOME/.nixpkgs/config.nix.
config = config =
let { let
toPath = builtins.toPath; toPath = builtins.toPath;
getEnv = x: if builtins ? getEnv then builtins.getEnv x else ""; getEnv = x: if builtins ? getEnv then builtins.getEnv x else "";
pathExists = name: pathExists = name:
@ -50,19 +56,18 @@ let
configFile2 = homeDir + "/.nixpkgs/config.nix"; configFile2 = homeDir + "/.nixpkgs/config.nix";
configExpr = configExpr =
if configFile != "" && pathExists configFile if config_ != null then config_
then import (toPath configFile) else if configFile != "" && pathExists configFile then import (toPath configFile)
else if homeDir != "" && pathExists configFile2 else if homeDir != "" && pathExists configFile2 then import (toPath configFile2)
then import (toPath configFile2)
else {}; else {};
in
# allow both: # allow both:
# { /* the config */ } and # { /* the config */ } and
# { pkgsOrig, pkgs, ... } : { /* the config */ } # { pkgsOrig, pkgs, ... } : { /* the config */ }
body = if builtins.isFunction configExpr if builtins.isFunction configExpr
then configExpr { inherit pkgs pkgsOrig; } then configExpr { inherit pkgs pkgsOrig; }
else configExpr; else configExpr;
};
# Return an attribute from the Nixpkgs configuration file, or # Return an attribute from the Nixpkgs configuration file, or
# a default value if the attribute doesn't exist. # a default value if the attribute doesn't exist.
@ -200,7 +205,7 @@ let
allStdenvs = import ../stdenv { allStdenvs = import ../stdenv {
inherit system stdenvType; inherit system stdenvType;
allPackages = import ./all-packages.nix; allPackages = args: import ./all-packages.nix ({ inherit config; } // args);
}; };
defaultStdenv = allStdenvs.stdenv; defaultStdenv = allStdenvs.stdenv;
@ -1075,7 +1080,6 @@ let
inherit fetchurl stdenv; inherit fetchurl stdenv;
}; };
netpbm = import ../tools/graphics/netpbm { netpbm = import ../tools/graphics/netpbm {
inherit stdenv fetchsvn libjpeg libpng zlib flex perl libxml2; inherit stdenv fetchsvn libjpeg libpng zlib flex perl libxml2;
}; };