Hi List, I try to add the support for Lua modules. I fail with postInstall & fixupPhase.
First, there are no standard way to build a Lua module (like with Perl or Python). The interpreter Lua uses 2 environments variables : - LUA_PATH for Lua files - LUA_CPATH for shared libraries There format is different of PATH or PYTHONPATH one. See http://www.lua.org/manual/5.1/manual.html#pdf-package.loaders, http://www.lua.org/manual/5.1/manual.html#pdf-package.cpath, http://www.lua.org/manual/5.1/manual.html#pdf-package.path. The interpreter Lua has no option -I But Lua script could be wrapped like following : #! /nix/store/...lua-5.1.4/bin/lua package.cpath = "... content of $LUA_CPATH ..." package.path = " ... content of $LUA_PATH ..." -- end of wrapping I start with small modules which represent various cases : - Coat : pure Lua modules, depends of TestMore, has a script bin/coat2uml - lfs : native extension (without test) - lpeg : native extension - socket : native extensions + Lua modules (without out) - random : native extension - TestLongString : pure Lua module, depends of TestMore - TestMore : pure Lua module after install, it's easy to check paths with the option -l, for example : $ lua -l lfs $ lua -l Test.More François Perrad
From cd9fd9d6f48ef056d5760281fe3c2fd7097f1fb6 Mon Sep 17 00:00:00 2001 From: fperrad <[email protected]> Date: Mon, 29 Mar 2010 11:55:28 +0200 Subject: [PATCH] first Lua modules --- pkgs/development/lua-modules/generic/default.nix | 57 +++++++ pkgs/top-level/all-packages.nix | 12 ++ pkgs/top-level/lua-packages.nix | 194 ++++++++++++++++++++++ 3 files changed, 263 insertions(+), 0 deletions(-) create mode 100644 pkgs/development/lua-modules/generic/default.nix create mode 100644 pkgs/top-level/lua-packages.nix diff --git a/pkgs/development/lua-modules/generic/default.nix b/pkgs/development/lua-modules/generic/default.nix new file mode 100644 index 0000000..2fc558b --- /dev/null +++ b/pkgs/development/lua-modules/generic/default.nix @@ -0,0 +1,57 @@ +{ lua5, lib }: + +{ name, namePrefix ? "lua-", src, meta, patches ? [] +, ... } @ attrs: + +let + # Return the list of recursively propagated build inputs of PKG. + recursiveBuildInputs = + pkg: + [ pkg ] ++ + (if pkg ? propagatedBuildNativeInputs + then lib.concatLists (map recursiveBuildInputs + pkg.propagatedBuildNativeInputs) + else []); + +in + +lua5.stdenv.mkDerivation ( + # Keep extra attributes from ATTR, e.g., `patchPhase', etc. + attrs + + // + + (rec { + inherit src meta patches; + + name = namePrefix + attrs.name; + + buildInputs = [ lua5 ] ++ + (if attrs ? buildInputs then attrs.buildInputs else []); + + propagatedBuildInputs = (if attrs ? propagatedBuildInputs then attrs.propagatedBuildInputs else []); + + postFixup = '' + # Wrap scripts that are under `{s,}bin/' so that they get the right + # package.path & package.cpath. + for i in "$out/bin/"* "$out/sbin/"* + do + if head -n1 "$i" | grep -q "${lua5}" + then + echo "wrapping \`$i'..." + + echo "TODO" + fi + done + + # If a user installs a Lua package, she probably also wants its + # dependencies in the user environment (since Lua modules don't + # have something like an RPATH, so the only way to find the + # dependencies is to have them in the LUA_PATH & LUA_CPATH variables). + if test -e $out/nix-support/propagated-build-inputs; then + ln -s $out/nix-support/propagated-build-inputs $out/nix-support/propagated-user-env-packages + fi + ''; + +})) + diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index d43741c..972e74a 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -5288,6 +5288,18 @@ let }; + ### DEVELOPMENT / LUA MODULES + + buildLuaPackage = + import ../development/lua-modules/generic { + inherit lua5 lib; + }; + + luaPackages = recurseIntoAttrs (import ./lua-packages.nix { + inherit pkgs; + }); + + ### DEVELOPMENT / PERL MODULES buildPerlPackage = import ../development/perl-modules/generic perl; diff --git a/pkgs/top-level/lua-packages.nix b/pkgs/top-level/lua-packages.nix new file mode 100644 index 0000000..9972c6f --- /dev/null +++ b/pkgs/top-level/lua-packages.nix @@ -0,0 +1,194 @@ +{ pkgs }: + +rec { + inherit (pkgs) fetchurl stdenv lua5 buildLuaPackage; + + Coat = buildLuaPackage rec { + name = "Coat-0.8.2"; + src = fetchurl { + url = http://github.com/downloads/fperrad/lua-Coat/lua-coat-0.8.2.tar.gz; + sha256 = "3a4a6dbdd2c25a8a763ea906aba4ca12ee906b0f261f999f90163f1d8e74db0c"; + }; + buildInputs = [ TestMore pkgs.perl ]; + + phases = "unpackPhase checkPhase installPhase fixupPhase"; + doCheck = true; + installFlags = "install DESTDIR=\${out}"; + postInstall = '' + export LUA_PATH="$out/share/lua/5.1/?.lua;$LUA_PATH" + ''; + + meta = { + description = "Yet Another Lua Object-Oriented Model"; + homepage = http://luacoat.luaforge.net/; + license = "MIT"; + }; + }; + + lfs = buildLuaPackage rec { + name = "lfs-1.5.0"; + src = fetchurl { + url = http://cloud.github.com/downloads/keplerproject/luafilesystem/luafilesystem-1.5.0.tar.gz; + sha256 = "00f6e1dc1e1da7f0fa77e375f0a04908ec4241a4c5e8d98031614f4a4a50c7cb"; + }; + + installFlags = "install LUA_LIBDIR=\${out}/lib/lua/5.1"; + postInstall = '' + export LUA_CPATH="$out/lib/lua/5.1/?.so;$LUA_CPATH" + ''; + + meta = { + description = "File System Library for the Lua Programming Language"; + longDescription = '' + LuaFileSystem is a Lua library developed to complement the set of + functions related to file systems offered by the standard Lua + distribution. LuaFileSystem offers a portable way to access the + underlying directory structure and file attributes. + ''; + homepage = http://www.keplerproject.org/; + license = "MIT"; + }; + }; + + lpeg = buildLuaPackage rec { + name = "lpeg-0.9"; + src = fetchurl { + url = http://www.inf.puc-rio.br/~roberto/lpeg/lpeg-0.9.tar.gz; + sha256 = "561304afbb64521d103dfe1af2ba91f7fd0cd0cf4171f8fd4b3eb112b8e55dc3"; + }; + + doCheck = true; + checkPhase = "lua test.lua"; + installPhase = '' + ensureDir $out/share/lua/5.1 + ensureDir $out/lib/lua/5.1 + cp re.lua $out/share/lua/5.1 + cp lpeg.so $out/lib/lua/5.1 + ${postInstall} + ''; + postInstall = '' + export LUA_PATH="$out/share/lua/5.1/?.lua;$LUA_PATH" + export LUA_CPATH="$out/lib/lua/5.1/?.so;$LUA_CPATH" + ''; + + meta = { + description = "Parsing Expression Grammars For Lua"; + longDescription = '' + LPeg is a new pattern-matching library for Lua, based on Parsing + Expression Grammars (PEGs). The nice thing about PEGs is that it + has a formal basis (instead of being an ad-hoc set of features), + allows an efficient and simple implementation, and does most things + we expect from a pattern-matching library (and more, as we can + define entire grammars). + ''; + homepage = http://www.inf.puc-rio.br/~roberto/lpeg/lpeg.html; + license = "MIT"; + }; + }; + + + random = buildLuaPackage rec { + name = "random"; + src = fetchurl { + url = http://www.tecgraf.puc-rio.br/~lhf/ftp/lua/5.1/lrandom.tar.gz; + sha256 = "b923cd94e8653e27800778c2f8784555b231d1ce235198ba9a06845d77a2b6d9"; + }; + + buildPhase = '' + gcc -O2 -c -o lrandom.o lrandom.c + gcc -shared -o random.so lrandom.o + ''; + doCheck = true; + checkPhase = "lua test.lua"; + installPhase = '' + ensureDir $out/lib/lua/5.1 + cp random.so $out/lib/lua/5.1 + ${postInstall} + ''; + postInstall = '' + export LUA_CPATH="$out/lib/lua/5.1/?.so;$LUA_CPATH" + ''; + + meta = { + description = "A library for generating random numbers"; + longDescription = '' + A library for generating random numbers based on the Mersenne Twister, + a pseudorandom number generating algorithm developped by Makoto Matsumoto + and Takuji Nishimura (alphabetical order) in 1996/1997. + ''; + homepage = http://www.tecgraf.puc-rio.br/~lhf/ftp/lua/; + license = "Public Domain"; + }; + }; + + socket = buildLuaPackage rec { + name = "socket-2.0.2"; + src = fetchurl { + url = http://luaforge.net/frs/download.php/2664/luasocket-2.0.2.tar.gz; + sha256 = "4fd9c775cfd98841299851e29b30176caf289370fea1ff1e00bb67c2d6842ca6"; + }; + + installFlags = "install INSTALL_TOP_LIB=\${out}/lib/lua/5.1 INSTALL_TOP_SHARE=\${out}/share/lua/5.1"; + postInstall = '' + export LUA_PATH="$out/share/lua/5.1/?.lua;$LUA_PATH" + export LUA_CPATH="$out/lib/lua/5.1/?/core.so;$LUA_CPATH" + ''; + + meta = { + description = "Network support for the Lua language"; + longDescription = '' + LuaSocket is a Lua extension library that is composed by two parts: a C core + that provides support for the TCP and UDP transport layers, and a set of Lua + modules that add support for functionality commonly needed by applications + that deal with the Internet. + ''; + homepage = http://www.tecgraf.puc-rio.br/~diego/professional/luasocket/; + license = "MIT"; + }; + }; + + TestLongString = buildLuaPackage rec { + name = "TestLongString-0.1.2"; + src = fetchurl { + url = http://github.com/downloads/fperrad/lua-TestLongString/lua-testlongstring-0.1.2.tar.gz; + sha256 = "087c6c26dec86c8104f3ab2fe25553979bcf77d10a6fab4aaaf234a69f6499c8"; + }; + buildInputs = [ pkgs.perl ]; + propagatedBuildInputs = [ TestMore ]; + + phases = "unpackPhase checkPhase installPhase fixupPhase"; + doCheck = true; + installFlags = "install DESTDIR=\${out}"; + postInstall = '' + export LUA_PATH="$out/share/lua/5.1/?.lua;$LUA_PATH" + ''; + + meta = { + description = "a lua-TestMore extension"; + homepage = http://testlongstring.luaforge.net/; + license = "MIT"; + }; + }; + + TestMore = buildLuaPackage rec { + name = "TestMore-0.2.1"; + src = fetchurl { + url = http://github.com/downloads/fperrad/lua-TestMore/lua-testmore-0.2.1.tar.gz; + sha256 = "b72c60f2413d75f4383c35d71937a2d9cc991fcfd94e783e332e3bf595c7444c"; + }; + buildInputs = [ pkgs.perl ]; + + phases = "unpackPhase checkPhase installPhase fixupPhase"; + doCheck = true; + installFlags = "install DESTDIR=\${out}"; + postInstall = '' + export LUA_PATH="$out/share/lua/5.1/?.lua;$LUA_PATH" + ''; + + meta = { + description = "an Unit Testing Framework"; + homepage = http://testmore.luaforge.net/; + license = "MIT"; + }; + }; +} -- 1.6.3.3
_______________________________________________ nix-dev mailing list [email protected] https://mail.cs.uu.nl/mailman/listinfo/nix-dev
