Skip to content
2 changes: 1 addition & 1 deletion lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ let
inherit (self.strings) concatStrings concatMapStrings concatImapStrings
intersperse concatStringsSep concatMapStringsSep
concatImapStringsSep concatLines makeSearchPath makeSearchPathOutput
makeLibraryPath makeBinPath optionalString
makeLibraryPath makeIncludePath makeBinPath optionalString
hasInfix hasPrefix hasSuffix stringToCharacters stringAsChars escape
escapeShellArg escapeShellArgs
isStorePath isStringLike
Expand Down
12 changes: 12 additions & 0 deletions lib/strings.nix
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,18 @@ rec {
*/
makeLibraryPath = makeSearchPathOutput "lib" "lib";

/* Construct an include search path (such as C_INCLUDE_PATH) containing the
header files for a set of packages or paths.

Example:
makeIncludePath [ "/usr" "/usr/local" ]
=> "/usr/include:/usr/local/include"
pkgs = import <nixpkgs> { }
makeIncludePath [ pkgs.openssl pkgs.zlib ]
=> "/nix/store/9rz8gxhzf8sw4kf2j2f1grr49w8zx5vj-openssl-1.0.1r-dev/include:/nix/store/wwh7mhwh269sfjkm6k5665b5kgp7jrk2-zlib-1.2.8-dev/include"
*/
makeIncludePath = makeSearchPathOutput "dev" "include";

/* Construct a binary search path (such as $PATH) containing the
binaries for a set of packages.

Expand Down
25 changes: 25 additions & 0 deletions lib/tests/misc.nix
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ let
lists
listToAttrs
makeExtensible
makeIncludePath
makeOverridable
mapAttrs
matchAttrs
Expand Down Expand Up @@ -296,6 +297,30 @@ runTests {
expected = "a\nb\nc\n";
};

testMakeIncludePathWithPkgs = {
expr = (makeIncludePath [
{ dev = "/nix/store/bash"; }
# lib.getOutput "dev" return out if "dev" is not found
{ out = "/nix/store/openssl"; }
Comment thread
mrdev023 marked this conversation as resolved.
Outdated
]);
expected = "/nix/store/bash/include:/nix/store/openssl/include";
};

testMakeIncludePathWithEmptyList = {
expr = (makeIncludePath [ ]);
expected = "";
};

testMakeIncludePathWithOneString = {
expr = (makeIncludePath [ "/usr" ]);
expected = "/usr/include";
};

testMakeIncludePathWithManyString = {
expr = (makeIncludePath [ "/usr" "/usr/local" ]);
expected = "/usr/include:/usr/local/include";
};

testReplicateString = {
expr = strings.replicate 5 "hello";
expected = "hellohellohellohellohello";
Expand Down