summary refs log tree commit diff
path: root/pkgs/top-level/impure.nix
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2017-02-01 15:56:02 +0100
committerEelco Dolstra <edolstra@gmail.com>2017-02-01 16:07:54 +0100
commit7dacca324d9e86fe7f7fad450ec833c746f21415 (patch)
tree8eff1f6e5df8473361140b73b6171b3ffafb4edb /pkgs/top-level/impure.nix
parent86fe7a40acc0e68e60905798b2d692c2e9a6c33e (diff)
downloadnixpkgs-7dacca324d9e86fe7f7fad450ec833c746f21415.tar
nixpkgs-7dacca324d9e86fe7f7fad450ec833c746f21415.tar.gz
nixpkgs-7dacca324d9e86fe7f7fad450ec833c746f21415.tar.bz2
nixpkgs-7dacca324d9e86fe7f7fad450ec833c746f21415.tar.lz
nixpkgs-7dacca324d9e86fe7f7fad450ec833c746f21415.tar.xz
nixpkgs-7dacca324d9e86fe7f7fad450ec833c746f21415.tar.zst
nixpkgs-7dacca324d9e86fe7f7fad450ec833c746f21415.zip
$NIXPKGS_OVERLAYS -> <nixpkgs-overlays>
The Nix search path is the established mechanism for specifying the
location of Nix expressions, so let's use it instead of adding another
environment variable.
Diffstat (limited to 'pkgs/top-level/impure.nix')
-rw-r--r--pkgs/top-level/impure.nix27
1 files changed, 16 insertions, 11 deletions
diff --git a/pkgs/top-level/impure.nix b/pkgs/top-level/impure.nix
index d8201a3569f..d1a28b9b15e 100644
--- a/pkgs/top-level/impure.nix
+++ b/pkgs/top-level/impure.nix
@@ -1,6 +1,17 @@
 /* Impure default args for `pkgs/top-level/default.nix`. See that file
    for the meaning of each argument. */
 
+with builtins;
+
+let
+
+  homeDir = builtins.getEnv "HOME";
+
+  # Return ‘x’ if it evaluates, or ‘def’ if it throws an exception.
+  try = x: def: let res = tryEval x; in if res.success then res.value else def;
+
+in
+
 { # Fallback: Assume we are building packages for the current (host, in GNU
   # Autotools parlance) system.
   system ? builtins.currentSystem
@@ -8,10 +19,7 @@
 , # Fallback: The contents of the configuration file found at $NIXPKGS_CONFIG or
   # $HOME/.nixpkgs/config.nix.
   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
@@ -22,20 +30,17 @@
   # collections of packages.  These collection of packages are part of the
   # fix-point made by Nixpkgs.
   overlays ? let
-      inherit (builtins) getEnv pathExists readDir attrNames map sort
-        lessThan;
-      dirEnv = getEnv "NIXPKGS_OVERLAYS";
-      dirHome = (getEnv "HOME") + "/.nixpkgs/overlays";
+      dirPath = try (if pathExists <nixpkgs-overlays> then <nixpkgs-overlays> else "") "";
+      dirHome = homeDir + "/.nixpkgs/overlays";
       dirCheck = dir: dir != "" && pathExists (dir + "/.");
       overlays = dir:
         let content = readDir dir; in
-        map (n: import "${dir}/${n}")
+        map (n: import (dir + ("/" + n)))
           (builtins.filter (n: builtins.match ".*\.nix" n != null)
             (sort lessThan (attrNames content)));
     in
-      if dirEnv != "" then
-        if dirCheck dirEnv then overlays dirEnv
-        else throw "The environment variable NIXPKGS_OVERLAYS does not name a valid directory."
+      if dirPath != "" then
+        overlays dirPath
       else if dirCheck dirHome then overlays dirHome
       else []