about summary refs log tree commit diff
path: root/lib/strings.nix
diff options
context:
space:
mode:
Diffstat (limited to 'lib/strings.nix')
-rw-r--r--lib/strings.nix20
1 files changed, 17 insertions, 3 deletions
diff --git a/lib/strings.nix b/lib/strings.nix
index 01a6f181d0389..bda96fb32da02 100644
--- a/lib/strings.nix
+++ b/lib/strings.nix
@@ -88,6 +88,16 @@ rec {
   makeSearchPath = subDir: packages:
     concatStringsSep ":" (map (path: path + "/" + subDir) packages);
 
+  /* Construct a Unix-style search path, given trying outputs in order.
+     If no output is found, fallback to `.out` and then to the default.
+
+     Example:
+       makeSearchPathOutputs "bin" ["bin"] [ pkgs.openssl pkgs.zlib ]
+       => "/nix/store/9rz8gxhzf8sw4kf2j2f1grr49w8zx5vj-openssl-1.0.1r-bin/bin:/nix/store/wwh7mhwh269sfjkm6k5665b5kgp7jrk2-zlib-1.2.8/bin"
+  */
+  makeSearchPathOutputs = subDir: outputs: pkgs:
+    makeSearchPath subDir (map (pkg: if pkg.outputUnspecified or false then lib.tryAttrs (outputs ++ ["out"]) pkg else pkg) pkgs);
+
   /* Construct a library search path (such as RPATH) containing the
      libraries for a set of packages
 
@@ -98,7 +108,9 @@ rec {
        makeLibraryPath [ pkgs.openssl pkgs.zlib ]
        => "/nix/store/9rz8gxhzf8sw4kf2j2f1grr49w8zx5vj-openssl-1.0.1r/lib:/nix/store/wwh7mhwh269sfjkm6k5665b5kgp7jrk2-zlib-1.2.8/lib"
   */
-  makeLibraryPath = makeSearchPath "lib";
+  makeLibraryPath = pkgs: makeSearchPath "lib"
+    # try to guess the right output of each pkg
+    (map (pkg: if pkg.outputUnspecified or false then pkg.lib or (pkg.out or pkg) else pkg) pkgs);
 
   /* Construct a binary search path (such as $PATH) containing the
      binaries for a set of packages.
@@ -107,7 +119,8 @@ rec {
        makeBinPath ["/root" "/usr" "/usr/local"]
        => "/root/bin:/usr/bin:/usr/local/bin"
   */
-  makeBinPath = makeSearchPath "bin";
+  makeBinPath = pkgs: makeSearchPath "bin"
+    (map (pkg: if pkg.outputUnspecified or false then pkg.bin or (pkg.out or pkg) else pkg) pkgs);
 
 
   /* Construct a perl search path (such as $PERL5LIB)
@@ -119,7 +132,8 @@ rec {
        makePerlPath [ pkgs.perlPackages.NetSMTP ]
        => "/nix/store/n0m1fk9c960d8wlrs62sncnadygqqc6y-perl-Net-SMTP-1.25/lib/perl5/site_perl"
   */
-  makePerlPath = makeSearchPath "lib/perl5/site_perl";
+  makePerlPath = pkgs: makeSearchPath "lib/perl5/site_perl"
+    (map (pkg: if pkg.outputUnspecified or false then pkg.lib or (pkg.out or pkg) else pkg) pkgs);
 
   /* Dependening on the boolean `cond', return either the given string
      or the empty string. Useful to contatenate against a bigger string.