Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at flake-libs 88 lines 2.4 kB view raw
1{ 2 lib, 3 stdenv, 4 lua, 5 buildEnv, 6 makeWrapper, 7 extraLibs ? [ ], 8 extraOutputsToInstall ? [ ], 9 postBuild ? "", 10 ignoreCollisions ? false, 11 requiredLuaModules, 12 makeWrapperArgs ? [ ], 13}: 14 15# Create a lua executable that knows about additional packages. 16let 17 env = 18 let 19 paths = [ lua ] ++ requiredLuaModules extraLibs; 20 in 21 buildEnv { 22 name = "${lua.name}-env"; 23 24 inherit paths; 25 inherit ignoreCollisions; 26 extraOutputsToInstall = [ "out" ] ++ extraOutputsToInstall; 27 28 nativeBuildInputs = [ 29 makeWrapper 30 ]; 31 32 # we create wrapper for the binaries in the different packages 33 postBuild = 34 '' 35 source ${lua}/nix-support/utils.sh 36 if [ -L "$out/bin" ]; then 37 unlink "$out/bin" 38 fi 39 mkdir -p "$out/bin" 40 41 buildLuaPath "$out" 42 43 # take every binary from lua packages and put them into the env 44 for path in ${lib.concatStringsSep " " paths}; do 45 nix_debug "looking for binaries in path = $path" 46 if [ -d "$path/bin" ]; then 47 cd "$path/bin" 48 for prg in *; do 49 if [ -f "$prg" ]; then 50 rm -f "$out/bin/$prg" 51 if [ -x "$prg" ]; then 52 nix_debug "Making wrapper $prg" 53 makeWrapper "$path/bin/$prg" "$out/bin/$prg" \ 54 --set-default LUA_PATH ";;" \ 55 --suffix LUA_PATH ';' "$LUA_PATH" \ 56 --set-default LUA_CPATH ";;" \ 57 --suffix LUA_CPATH ';' "$LUA_CPATH" \ 58 ${lib.concatStringsSep " " makeWrapperArgs} 59 fi 60 fi 61 done 62 fi 63 done 64 '' 65 + postBuild; 66 67 inherit (lua) meta; 68 69 passthru = lua.passthru // { 70 interpreter = "${env}/bin/lua"; 71 inherit lua; 72 luaPath = lua.pkgs.luaLib.genLuaPathAbsStr env; 73 luaCpath = lua.pkgs.luaLib.genLuaCPathAbsStr env; 74 env = stdenv.mkDerivation { 75 name = "interactive-${lua.name}-environment"; 76 nativeBuildInputs = [ env ]; 77 78 buildCommand = '' 79 echo >&2 "" 80 echo >&2 "*** lua 'env' attributes are intended for interactive nix-shell sessions, not for building! ***" 81 echo >&2 "" 82 exit 1 83 ''; 84 }; 85 }; 86 }; 87in 88env