summary refs log tree commit diff
path: root/lib/attrsets.nix
diff options
context:
space:
mode:
authorNikolay Amiantov <ab@fmap.me>2016-04-14 18:13:50 +0300
committerNikolay Amiantov <ab@fmap.me>2016-04-25 13:22:41 +0300
commit7d3e75827bc20d50a3b9172ed8891e5bffb30c93 (patch)
treea778c5829a8e3945dec00cbc570bc6c204c11855 /lib/attrsets.nix
parent5f3987f44f81d2ca7bae266cdb1b26bd6d50b6c8 (diff)
downloadnixlib-7d3e75827bc20d50a3b9172ed8891e5bffb30c93.tar
nixlib-7d3e75827bc20d50a3b9172ed8891e5bffb30c93.tar.gz
nixlib-7d3e75827bc20d50a3b9172ed8891e5bffb30c93.tar.bz2
nixlib-7d3e75827bc20d50a3b9172ed8891e5bffb30c93.tar.lz
nixlib-7d3e75827bc20d50a3b9172ed8891e5bffb30c93.tar.xz
nixlib-7d3e75827bc20d50a3b9172ed8891e5bffb30c93.tar.zst
nixlib-7d3e75827bc20d50a3b9172ed8891e5bffb30c93.zip
getOutput function: init
Diffstat (limited to 'lib/attrsets.nix')
-rw-r--r--lib/attrsets.nix12
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/attrsets.nix b/lib/attrsets.nix
index 4161fa546c8f..9104ff35d194 100644
--- a/lib/attrsets.nix
+++ b/lib/attrsets.nix
@@ -438,6 +438,18 @@ rec {
   overrideExisting = old: new:
     old // listToAttrs (map (attr: nameValuePair attr (attrByPath [attr] old.${attr} new)) (attrNames old));
 
+  /* Get a package output.
+     If no output is found, fallback to `.out` and then to the default.
+
+     Example:
+       getOutput "dev" pkgs.openssl
+       => "/nix/store/9rz8gxhzf8sw4kf2j2f1grr49w8zx5vj-openssl-1.0.1r-dev"
+  */
+  getOutput = output: pkg:
+    if pkg.outputUnspecified or false
+      then pkg.${output} or pkg.out or pkg
+      else pkg;
+
 
   /*** deprecated stuff ***/