at 23.11-beta 117 lines 3.5 kB view raw
1{ lib 2, stdenv 3, fetchFromGitHub 4, fetchpatch 5, curl 6, makeWrapper 7, which 8, unzip 9, lua 10, file 11, nix-prefetch-git 12 # for 'luarocks pack' 13, zip 14, nix-update-script 15 # some packages need to be compiled with cmake 16, cmake 17, installShellFiles 18}: 19 20stdenv.mkDerivation (finalAttrs: { 21 pname = "luarocks"; 22 version = "3.9.1"; 23 24 src = fetchFromGitHub { 25 owner = "luarocks"; 26 repo = "luarocks"; 27 rev = "v${finalAttrs.version}"; 28 sha256 = "sha256-G6HDap3pspeQtGDBq+ukN7kftDaT/CozMVdYM60F6HI="; 29 }; 30 31 patches = [ 32 ./darwin-3.7.0.patch 33 # follow standard environmental variables 34 # https://github.com/luarocks/luarocks/pull/1433 35 (fetchpatch { 36 url = "https://github.com/luarocks/luarocks/commit/d719541577a89909185aa8de7a33cf73b7a63ac3.diff"; 37 sha256 = "sha256-rMnhZFqLEul0wnsxvw9nl6JXVanC5QgOZ+I/HJ0vRCM="; 38 }) 39 ]; 40 41 postPatch = lib.optionalString stdenv.targetPlatform.isDarwin '' 42 substituteInPlace src/luarocks/core/cfg.lua --subst-var-by 'darwinMinVersion' '${stdenv.targetPlatform.darwinMinVersion}' 43 ''; 44 45 # Manually written ./configure does not support --build= or --host=: 46 # Error: Unknown flag: --build=x86_64-unknown-linux-gnu 47 configurePlatforms = [ ]; 48 49 preConfigure = '' 50 lua -e "" || { 51 luajit -e "" && { 52 export LUA_SUFFIX=jit 53 configureFlags="$configureFlags --lua-suffix=$LUA_SUFFIX" 54 } 55 } 56 lua_inc="$(echo "${lua}/include"/*/)" 57 if test -n "$lua_inc"; then 58 configureFlags="$configureFlags --with-lua-include=$lua_inc" 59 fi 60 ''; 61 62 nativeBuildInputs = [ makeWrapper installShellFiles lua unzip ]; 63 64 buildInputs = [ curl which ]; 65 66 postInstall = '' 67 sed -e "1s@.*@#! ${lua}/bin/lua$LUA_SUFFIX@" -i "$out"/bin/* 68 substituteInPlace $out/etc/luarocks/* \ 69 --replace '${lua.luaOnBuild}' '${lua}' 70 71 for i in "$out"/bin/*; do 72 test -L "$i" || { 73 wrapProgram "$i" \ 74 --suffix LUA_PATH ";" "$(echo "$out"/share/lua/*/)?.lua" \ 75 --suffix LUA_PATH ";" "$(echo "$out"/share/lua/*/)?/init.lua" \ 76 --suffix LUA_CPATH ";" "$(echo "$out"/lib/lua/*/)?.so" \ 77 --suffix LUA_CPATH ";" "$(echo "$out"/share/lua/*/)?/init.lua" \ 78 --suffix PATH : ${lib.makeBinPath ([ unzip ] ++ 79 lib.optionals (finalAttrs.pname == "luarocks-nix") [ file nix-prefetch-git ])} 80 } 81 done 82 '' + lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) '' 83 installShellCompletion --cmd luarocks \ 84 --bash <($out/bin/luarocks completion bash) \ 85 --fish <($out/bin/luarocks completion fish) \ 86 --zsh <($out/bin/luarocks completion zsh) 87 ''; 88 89 propagatedBuildInputs = [ zip unzip cmake ]; 90 91 # unpack hook for src.rock and rockspec files 92 setupHook = ./setup-hook.sh; 93 94 # cmake is just to compile packages with "cmake" buildType, not luarocks itself 95 dontUseCmakeConfigure = true; 96 97 shellHook = '' 98 export PATH="src/bin:''${PATH:-}" 99 export LUA_PATH="src/?.lua;''${LUA_PATH:-}" 100 ''; 101 102 disallowedReferences = lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ 103 lua.luaOnBuild 104 ]; 105 106 passthru = { 107 updateScript = nix-update-script { }; 108 }; 109 110 meta = with lib; { 111 description = "A package manager for Lua"; 112 license = licenses.mit; 113 maintainers = with maintainers; [ raskin teto ]; 114 platforms = platforms.linux ++ platforms.darwin; 115 downloadPage = "http://luarocks.org/releases/"; 116 }; 117})