1/*
2 This is a minimal/manual luarocks derivation used by `buildLuarocksPackage` to install lua packages.
3
4 As a nix user, you should use the generated lua.pkgs.luarocks that contains a luarocks manifest
5 which makes it recognizable to luarocks.
6 Generating the manifest for luarocks_bootstrap seemed too hackish, which is why we end up
7 with two "luarocks" derivations.
8*/
9{
10 lib,
11 stdenv,
12 fetchFromGitHub,
13 curl,
14 makeWrapper,
15 which,
16 unzip,
17 lua,
18 versionCheckHook,
19 # for 'luarocks pack'
20 zip,
21 nix-update-script,
22 # some packages need to be compiled with cmake
23 cmake,
24 installShellFiles,
25}:
26
27stdenv.mkDerivation (finalAttrs: {
28 pname = "luarocks_bootstrap";
29 version = "3.12.2";
30
31 src = fetchFromGitHub {
32 owner = "luarocks";
33 repo = "luarocks";
34 tag = "v${finalAttrs.version}";
35 hash = "sha256-hQysstYGUcZnnEXL+9ECS0sBViYggeDIMgo6LpUexBA=";
36 };
37
38 patches = [
39 ./darwin-3.7.0.patch
40 ];
41
42 postPatch = lib.optionalString stdenv.targetPlatform.isDarwin ''
43 substituteInPlace src/luarocks/core/cfg.lua --subst-var-by 'darwinMinVersion' '${stdenv.targetPlatform.darwinMinVersion}'
44 '';
45
46 # Manually written ./configure does not support --build= or --host=:
47 # Error: Unknown flag: --build=x86_64-unknown-linux-gnu
48 configurePlatforms = [ ];
49
50 preConfigure = ''
51 lua -e "" || {
52 luajit -e "" && {
53 export LUA_SUFFIX=jit
54 appendToVar configureFlags "--lua-suffix=$LUA_SUFFIX"
55 }
56 }
57 lua_inc="$(echo "${lua}/include"/*/)"
58 if test -n "$lua_inc"; then
59 appendToVar configureFlags "--with-lua-include=$lua_inc"
60 fi
61 '';
62
63 nativeBuildInputs = [
64 makeWrapper
65 installShellFiles
66 lua
67 unzip
68 versionCheckHook
69 ];
70
71 buildInputs = [
72 curl
73 which
74 ];
75
76 postInstall = ''
77 sed -e "1s@.*@#! ${lua}/bin/lua$LUA_SUFFIX@" -i "$out"/bin/*
78 substituteInPlace $out/etc/luarocks/* \
79 --replace-quiet '${lua.luaOnBuild}' '${lua}'
80 ''
81 + lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) ''
82 installShellCompletion --cmd luarocks \
83 --bash <($out/bin/luarocks completion bash) \
84 --fish <($out/bin/luarocks completion fish) \
85 --zsh <($out/bin/luarocks completion zsh)
86
87 installShellCompletion --cmd luarocks-admin \
88 --bash <($out/bin/luarocks-admin completion bash) \
89 --fish <($out/bin/luarocks-admin completion fish) \
90 --zsh <($out/bin/luarocks-admin completion zsh)
91 ''
92 + ''
93 for i in "$out"/bin/*; do
94 test -L "$i" || {
95 wrapProgram "$i" \
96 --suffix LUA_PATH ";" "$(echo "$out"/share/lua/*/)?.lua" \
97 --suffix LUA_PATH ";" "$(echo "$out"/share/lua/*/)?/init.lua" \
98 --suffix LUA_CPATH ";" "$(echo "$out"/lib/lua/*/)?.so" \
99 --suffix LUA_CPATH ";" "$(echo "$out"/share/lua/*/)?/init.lua" \
100 --suffix PATH : ${lib.makeBinPath finalAttrs.propagatedNativeBuildInputs}
101 }
102 done
103 '';
104
105 propagatedNativeBuildInputs = [
106 zip
107 unzip
108 cmake
109 ];
110
111 doInstallCheck = true;
112 versionCheckProgram = "${placeholder "out"}/bin/luarocks";
113 versionCheckProgramArg = "--version";
114
115 # unpack hook for src.rock and rockspec files
116 setupHook = ./setup-hook.sh;
117
118 # cmake is just to compile packages with "cmake" buildType, not luarocks itself
119 dontUseCmakeConfigure = true;
120
121 shellHook = ''
122 export PATH="src/bin:''${PATH:-}"
123 export LUA_PATH="src/?.lua;''${LUA_PATH:-}"
124 '';
125
126 disallowedReferences = lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
127 lua.luaOnBuild
128 ];
129
130 passthru = {
131 updateScript = nix-update-script { };
132 };
133
134 meta = with lib; {
135 description = "Package manager for Lua";
136 license = licenses.mit;
137 maintainers = with maintainers; [
138 raskin
139 teto
140 ];
141 mainProgram = "luarocks";
142 platforms = platforms.linux ++ platforms.darwin;
143 downloadPage = "http://luarocks.org/releases/";
144 };
145})