summary refs log tree commit diff
path: root/pkgs/stdenv/generic
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2013-11-19 14:44:05 +0100
committerEelco Dolstra <eelco.dolstra@logicblox.com>2013-11-19 14:58:47 +0100
commit544475cb45d3dc38ff91f2f7cd28fd826d00a1a0 (patch)
tree0c46750c506baa50f10d114c364a5c2e4c17ed94 /pkgs/stdenv/generic
parent9fc575367d31455434295656725b1534c38aabbf (diff)
downloadnixlib-544475cb45d3dc38ff91f2f7cd28fd826d00a1a0.tar
nixlib-544475cb45d3dc38ff91f2f7cd28fd826d00a1a0.tar.gz
nixlib-544475cb45d3dc38ff91f2f7cd28fd826d00a1a0.tar.bz2
nixlib-544475cb45d3dc38ff91f2f7cd28fd826d00a1a0.tar.lz
nixlib-544475cb45d3dc38ff91f2f7cd28fd826d00a1a0.tar.xz
nixlib-544475cb45d3dc38ff91f2f7cd28fd826d00a1a0.tar.zst
nixlib-544475cb45d3dc38ff91f2f7cd28fd826d00a1a0.zip
mkDerivation: Set meta.position to the source file of the derivation
This requires Nix 1.7.
Diffstat (limited to 'pkgs/stdenv/generic')
-rw-r--r--pkgs/stdenv/generic/default.nix23
1 files changed, 18 insertions, 5 deletions
diff --git a/pkgs/stdenv/generic/default.nix b/pkgs/stdenv/generic/default.nix
index fcd7439e97e8..a139d47a8ccd 100644
--- a/pkgs/stdenv/generic/default.nix
+++ b/pkgs/stdenv/generic/default.nix
@@ -20,6 +20,8 @@ let
 
   allowBroken = builtins.getEnv "NIXPKGS_ALLOW_BROKEN" == "1";
 
+  unsafeGetAttrPos = builtins.unsafeGetAttrPos or (n: as: null);
+
   stdenvGenerator = setupScript: rec {
 
     # The stdenv that we are producing.
@@ -51,12 +53,20 @@ let
         # Add a utility function to produce derivations that use this
         # stdenv and its shell.
         mkDerivation = attrs:
+          let
+            pos =
+              if attrs.meta.description or null != null then
+                unsafeGetAttrPos "description" attrs.meta
+              else
+                unsafeGetAttrPos "name" attrs;
+            pos' = if pos != null then "‘" + pos.file + ":" + toString pos.line + "’" else "«unknown-file»";
+          in
           if !allowUnfree && (let l = lib.lists.toList attrs.meta.license or []; in lib.lists.elem "unfree" l || lib.lists.elem "unfree-redistributable" l) then
-            throw "package ‘${attrs.name}’ has an unfree license, refusing to evaluate"
+            throw "package ‘${attrs.name}’ in ${pos'} has an unfree license, refusing to evaluate"
           else if !allowBroken && attrs.meta.broken or false then
-            throw "you can't use package ‘${attrs.name}’ because it has been marked as broken"
+            throw "you can't use package ‘${attrs.name}’ in ${pos'} because it has been marked as broken"
           else if !allowBroken && attrs.meta.platforms or null != null && !lib.lists.elem result.system attrs.meta.platforms then
-            throw "the package ‘${attrs.name}’ is not supported on ‘${result.system}’"
+            throw "the package ‘${attrs.name}’ in ${pos'} is not supported on ‘${result.system}’"
           else
             lib.addPassthru (derivation (
               (removeAttrs attrs ["meta" "passthru" "crossAttrs"])
@@ -89,8 +99,11 @@ let
               # but it's not part of the actual derivation, i.e., it's not
               # passed to the builder and is not a dependency.  But since we
               # include it in the result, it *is* available to nix-env for
-              # queries.
-              meta = attrs.meta or {};
+              # queries.  We also a meta.position attribute here to
+              # identify the source location of the package.
+              meta = attrs.meta or {} // (if pos != null then {
+                position = pos.file + ":" + (toString pos.line);
+              } else {});
               passthru = attrs.passthru or {};
             } //
             # Pass through extra attributes that are not inputs, but