summary refs log tree commit diff
path: root/pkgs/top-level
diff options
context:
space:
mode:
authorzimbatm <zimbatm@zimbatm.com>2016-07-09 21:44:36 +0100
committerGitHub <noreply@github.com>2016-07-09 21:44:36 +0100
commit820cb25139ff054861ba2686a67bfc3b2965bea6 (patch)
tree4f19cbdd1ae9ca93dc2a0f03b1aeb09ecc58eab9 /pkgs/top-level
parent8a82798f976b92be03f42ea304e8e55a93239b48 (diff)
parent29de9cedadb6dc67433776a58f50642f650dca5a (diff)
downloadnixlib-820cb25139ff054861ba2686a67bfc3b2965bea6.tar
nixlib-820cb25139ff054861ba2686a67bfc3b2965bea6.tar.gz
nixlib-820cb25139ff054861ba2686a67bfc3b2965bea6.tar.bz2
nixlib-820cb25139ff054861ba2686a67bfc3b2965bea6.tar.lz
nixlib-820cb25139ff054861ba2686a67bfc3b2965bea6.tar.xz
nixlib-820cb25139ff054861ba2686a67bfc3b2965bea6.tar.zst
nixlib-820cb25139ff054861ba2686a67bfc3b2965bea6.zip
Merge pull request #16416 from Ericson2314/default-args
Make default config an argument default instead of using null check
Diffstat (limited to 'pkgs/top-level')
-rw-r--r--pkgs/top-level/default.nix44
1 files changed, 19 insertions, 25 deletions
diff --git a/pkgs/top-level/default.nix b/pkgs/top-level/default.nix
index cff8671b65d5..8913dc1ef59e 100644
--- a/pkgs/top-level/default.nix
+++ b/pkgs/top-level/default.nix
@@ -22,43 +22,37 @@
 , # 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
+  #
+  # [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
 , platform ? null
 }:
 
 
-let config_ = config; platform_ = platform; in # rename the function arguments
+let configExpr = config; platform_ = platform; in # rename the function arguments
 
 let
 
   lib = import ../../lib;
 
-  # The contents of the configuration file found at $NIXPKGS_CONFIG or
-  # $HOME/.nixpkgs/config.nix.
-  # for NIXOS (nixos-rebuild): use nixpkgs.config option
+  # Allow both:
+  # { /* the config */ } and
+  # { pkgs, ... } : { /* the config */ }
   config =
-    let
-      inherit (builtins) getEnv pathExists;
-
-      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;
+    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)