Make default config an argument default instead of using null check

Thanks @Mathnerd314 for this idea
This commit is contained in:
John Ericson 2016-06-22 01:33:53 -07:00
parent 125ffff089
commit 29de9cedad

View File

@ -22,43 +22,37 @@
, # Allow a configuration attribute set to be passed in as an , # Allow a configuration attribute set to be passed in as an
# argument. Otherwise, it's read from $NIXPKGS_CONFIG or # argument. Otherwise, it's read from $NIXPKGS_CONFIG or
# ~/.nixpkgs/config.nix. # ~/.nixpkgs/config.nix.
config ? null #
# [For NixOS (nixos-rebuild), use nixpkgs.config option to set.]
config ? let
inherit (builtins) getEnv pathExists;
configFile = getEnv "NIXPKGS_CONFIG";
homeDir = getEnv "HOME";
configFile2 = homeDir + "/.nixpkgs/config.nix";
in
if configFile != "" && pathExists configFile then import configFile
else if homeDir != "" && pathExists configFile2 then import configFile2
else {}
, crossSystem ? null , crossSystem ? null
, platform ? null , platform ? null
}: }:
let config_ = config; platform_ = platform; in # rename the function arguments let configExpr = config; platform_ = platform; in # rename the function arguments
let let
lib = import ../../lib; lib = import ../../lib;
# The contents of the configuration file found at $NIXPKGS_CONFIG or # Allow both:
# $HOME/.nixpkgs/config.nix. # { /* the config */ } and
# for NIXOS (nixos-rebuild): use nixpkgs.config option # { pkgs, ... } : { /* the config */ }
config = config =
let if builtins.isFunction configExpr
inherit (builtins) getEnv pathExists; then configExpr { inherit pkgs; }
else configExpr;
configFile = getEnv "NIXPKGS_CONFIG";
homeDir = getEnv "HOME";
configFile2 = homeDir + "/.nixpkgs/config.nix";
configExpr =
if config_ != null then config_
else if configFile != "" && pathExists configFile then import configFile
else if homeDir != "" && pathExists configFile2 then import configFile2
else {};
in
# allow both:
# { /* the config */ } and
# { pkgs, ... } : { /* the config */ }
if builtins.isFunction configExpr
then configExpr { inherit pkgs; }
else configExpr;
# Allow setting the platform in the config file. Otherwise, let's use a reasonable default (pc) # Allow setting the platform in the config file. Otherwise, let's use a reasonable default (pc)