[Nix-dev] lua-related nix-expressions

Ilya Cassina ilya.cassina at gmail.com
Wed Oct 6 23:43:36 CEST 2010


Hello, I wrote some nix-expressionf for installing

luasocket-2.0.2 (socket support for lua)
luasec-0-4 (ssl support for lua)

and wrote a luaAggregationFun (similar to the one for texLive)

attached the relevant nix expression files, here what goes to top-
level/all-packages.nix:


--[snip]--

  luasec = callPackage ../development/libraries/luasec {
    lua = lua5;
  };

  luasocket = callPackage ../development/libraries/luasocket {
    lua = lua5;
  };

  luaAggregationFun = 
    (builderDefsPackage (import 
../development/interpreters/lua-5/aggregate.nix));

--[snip]--

I don't know how to add some environment variables (resulting from applying 
luaAggregationFun with the relevant paths sets) to the user's environment.

One should have:

 LUA_PATH=";;$out/share/lua/5.1/?.lua"
 LUA_CPATH=";;$out/lib/lua/5.1/?.so"

exported (where $out is the luaAggregationFun call's built FSO), so that 
one can require any lua modules provided by the components passed to that 
function. It should probably go in the environment construction, but I did 
not look into it yet.

Any idea would be appreciated :)

Here an example of calling luaAggregationFun from withing 
environment.sysPackages list in /etc/nixos/configuration.nix:

--[snip]--

 (let myLua = pkgs.luaAggregationFun {
      lua = pkgs.lua5;
      paths = [ pkgs.luasocket pkgs.luasec pkgs.splayd ];
   };  
  in myLua)

--[snip]--

(splayd is a lua module for distributed protocol development/testing, 
requiring both luasocket and luasec, when i polish down the nix-expression 
for build it i will send it here)

That's all for today :)

good night,

--
imc
-------------- next part --------------
{stdenv, fetchurl, lua}:

stdenv.mkDerivation {
    name = "luasocket-2.0.2";

    src = fetchurl {
        url = http://luaforge.net/frs/download.php/2664/luasocket-2.0.2.tar.gz;
        sha256 = "4fd9c775cfd98841299851e29b30176caf289370fea1ff1e00bb67c2d6842ca6";

    };

    buildInputs = [ lua ];

    phases = "unpackPhase patchPhase buildPhase installPhase";

    patchPhase = ''
        sed -i config -e "s,/usr/local/share/lua/5.1,$out/share/lua/5.1,g" \
                      -e "s,/usr/local/lib/lua/5.1,$out/lib/lua/5.1,g"
    '';
}
-------------- next part --------------
{stdenv, fetchurl, lua, openssl}:

stdenv.mkDerivation {
    name = "luasec-0.4";

    src = fetchurl {
        url = http://www.inf.puc-rio.br/~brunoos/luasec/download/luasec-0.4.tar.gz;
        sha256 = "111732f0e646120a701d33e7d3a613a9a901c11c0a01d0805d73ef90c3f0abd5";

    };

    buildInputs = [ lua openssl ];

    phases = "unpackPhase patchPhase buildPhase installPhase";

    patchPhase = ''
        sed -i Makefile -e "s,/usr/local/share/lua/5.1,$out/share/lua/5.1,g" \
                        -e "s,/usr/local/lib/lua/5.1,$out/lib/lua/5.1,g" \
                        -e "s,^\#INCDIR=.*,INCDIR=-I${lua}/include -I${openssl}/include,g" \
                        -e "s,^\#LIBDIR=.*,LIBDIR=-L${lua}/lib -R${openssl}/lib,g"
    '';

    buildPhase = ''
        make linux
        mkdir -p $out/lib/lua/5.1
    '';
}
-------------- next part --------------
args : with args;
rec {
  phaseNames = ["doAggregate"];
  name = "lua-5.1-linkdir";

  inherit lua;

  buildInputs = lib.closePropagation paths;

  doAggregate = fullDepEntry (''

    LUA_PATH=$out/share/lua/5.1
    LUA_CPATH=$out/lib/lua/5.1

    ensureDir $LUA_PATH
    ensureDir $LUA_CPATH

    for currentPath in ${lib.concatStringsSep " " buildInputs}; do
        if [ -d $currentPath/share/lua/5.1 ]; then
            echo Symlinking "$currentPath"
            cd $LUA_PATH
            for l in $currentPath/share/lua/5.1/*; do
                d=`basename $l`
                ln -sf $l $d
            done
            cd $LUA_CPATH
            for l in $currentPath/lib/lua/5.1/*; do
                d=`basename $l`
                ln -sf $l $d
            done
        fi
    done
    ensureDir "$out/bin"
    cd $out/bin
    for b in ${lua}/bin/*; do
        d=`basename $b`
        ln -sf $b $d
    done


    echo 
    echo "Now you only need to add the following to your shell's login script:"
    echo "export LUA_PATH=\"$LUA_PATH\""
    echo "export LUA_CPATH=\"$LUA_CPATH\""
    echo 
  '') ["minInit" "defEnsureDir" "addInputs"];

  meta = {
    description = "Lua 5.1 directory";
    longDescription = ''
      Here all the files from different lua-related 
      packages are collected in one directory.
    '';
  };
}


More information about the nix-dev mailing list