summary refs log tree commit diff
path: root/pkgs/development/interpreters/lua-5
diff options
context:
space:
mode:
authorMatthieu Coudron <coudron@iij.ad.jp>2019-01-30 23:13:15 +0900
committerMichael Raskin <7c6f434c@mail.ru>2019-01-30 14:13:15 +0000
commitc4519cf8a6bfdb21ced8b053953d2a8fa68c615c (patch)
tree3ea0dac7056b81a28f024d1db2df0ce97354a240 /pkgs/development/interpreters/lua-5
parent16ab34c37b7ead2266ae24ebcf5d6e9f5cd5ab59 (diff)
downloadnixpkgs-c4519cf8a6bfdb21ced8b053953d2a8fa68c615c.tar
nixpkgs-c4519cf8a6bfdb21ced8b053953d2a8fa68c615c.tar.gz
nixpkgs-c4519cf8a6bfdb21ced8b053953d2a8fa68c615c.tar.bz2
nixpkgs-c4519cf8a6bfdb21ced8b053953d2a8fa68c615c.tar.lz
nixpkgs-c4519cf8a6bfdb21ced8b053953d2a8fa68c615c.tar.xz
nixpkgs-c4519cf8a6bfdb21ced8b053953d2a8fa68c615c.tar.zst
nixpkgs-c4519cf8a6bfdb21ced8b053953d2a8fa68c615c.zip
lua: add withPackages function (#54460)
* lua: add withPackages function

First step towards more automation similar to the haskell backend.
Follow up of https://github.com/NixOS/nixpkgs/pull/33903
Diffstat (limited to 'pkgs/development/interpreters/lua-5')
-rw-r--r--pkgs/development/interpreters/lua-5/5.1.nix22
-rw-r--r--pkgs/development/interpreters/lua-5/5.2.nix26
-rw-r--r--pkgs/development/interpreters/lua-5/5.3.nix24
-rw-r--r--pkgs/development/interpreters/lua-5/build-rocks.nix0
-rw-r--r--pkgs/development/interpreters/lua-5/build-rockspec.nix0
-rw-r--r--pkgs/development/interpreters/lua-5/setup-hook.nix15
-rw-r--r--pkgs/development/interpreters/lua-5/setup-hook.sh47
-rw-r--r--pkgs/development/interpreters/lua-5/with-packages.nix4
-rw-r--r--pkgs/development/interpreters/lua-5/wrapper.nix73
9 files changed, 207 insertions, 4 deletions
diff --git a/pkgs/development/interpreters/lua-5/5.1.nix b/pkgs/development/interpreters/lua-5/5.1.nix
index 09af492490c..b2948b392d5 100644
--- a/pkgs/development/interpreters/lua-5/5.1.nix
+++ b/pkgs/development/interpreters/lua-5/5.1.nix
@@ -1,4 +1,8 @@
-{ stdenv, fetchurl, readline }:
+{ stdenv, fetchurl, readline
+, self
+, callPackage
+, packageOverrides ? (self: super: {})
+}:
 
 let
   dsoPatch = fetchurl {
@@ -6,6 +10,7 @@ let
     sha256 = "11fcyb4q55p4p7kdb8yp85xlw8imy14kzamp2khvcyxss4vw8ipw";
     name = "lua-arch.patch";
   };
+  luaPackages = callPackage ../../lua-modules {lua=self; overrides=packageOverrides;};
 in
 stdenv.mkDerivation rec {
   name = "lua-${version}";
@@ -17,6 +22,10 @@ stdenv.mkDerivation rec {
     sha256 = "2640fc56a795f29d28ef15e13c34a47e223960b0240e8cb0a82d9b0738695333";
   };
 
+  LuaPathSearchPaths    = luaPackages.getLuaPathList luaversion;
+  LuaCPathSearchPaths   = luaPackages.getLuaCPathList luaversion;
+  setupHook = luaPackages.lua-setup-hook LuaPathSearchPaths LuaCPathSearchPaths;
+
   buildInputs = [ readline ];
 
   patches = (if stdenv.isDarwin then [ ./5.1.darwin.patch ] else [ dsoPatch ])
@@ -39,6 +48,16 @@ stdenv.mkDerivation rec {
     rmdir $out/{share,lib}/lua/5.1 $out/{share,lib}/lua
   '';
 
+  passthru = rec {
+    buildEnv = callPackage ./wrapper.nix {
+      lua=self;
+      inherit (luaPackages) requiredLuaModules;
+    };
+    withPackages = import ./with-packages.nix { inherit buildEnv luaPackages;};
+    pkgs = luaPackages;
+    interpreter = "${self}/bin/lua";
+  };
+
   meta = {
     homepage = http://www.lua.org;
     description = "Powerful, fast, lightweight, embeddable scripting language";
@@ -51,6 +70,7 @@ stdenv.mkDerivation rec {
       for configuration, scripting, and rapid prototyping.
     '';
     license = stdenv.lib.licenses.mit;
+    platforms = with stdenv.lib.platforms; linux ++ darwin;
     hydraPlatforms = stdenv.lib.platforms.linux;
   };
 }
diff --git a/pkgs/development/interpreters/lua-5/5.2.nix b/pkgs/development/interpreters/lua-5/5.2.nix
index a8badf647c0..e89a2cbece6 100644
--- a/pkgs/development/interpreters/lua-5/5.2.nix
+++ b/pkgs/development/interpreters/lua-5/5.2.nix
@@ -1,4 +1,10 @@
-{ stdenv, fetchurl, readline, compat ? false }:
+{ stdenv, fetchurl, readline
+# compiles compatibility layer with lua5.1
+, compat ? false
+, callPackage
+, self
+, packageOverrides ? (self: super: {})
+}:
 
 let
   dsoPatch = fetchurl {
@@ -6,12 +12,17 @@ let
     sha256 = "1by1dy4ql61f5c6njq9ibf9kaqm3y633g2q8j54iyjr4cxvqwqz9";
     name = "lua-arch.patch";
   };
+  luaPackages = callPackage ../../lua-modules {lua=self; overrides=packageOverrides;};
 in
 stdenv.mkDerivation rec {
   name = "lua-${version}";
   luaversion = "5.2";
   version = "${luaversion}.4";
 
+  LuaPathSearchPaths    = luaPackages.getLuaPathList luaversion;
+  LuaCPathSearchPaths   = luaPackages.getLuaCPathList luaversion;
+  setupHook = luaPackages.lua-setup-hook LuaPathSearchPaths LuaCPathSearchPaths;
+
   src = fetchurl {
     url = "https://www.lua.org/ftp/${name}.tar.gz";
     sha256 = "0jwznq0l8qg9wh5grwg07b5cy3lzngvl5m2nl1ikp6vqssmf9qmr";
@@ -21,6 +32,19 @@ stdenv.mkDerivation rec {
 
   patches = if stdenv.isDarwin then [ ./5.2.darwin.patch ] else [ dsoPatch ];
 
+
+  passthru = rec {
+    buildEnv = callPackage ./wrapper.nix {
+      lua = self;
+      inherit (luaPackages) requiredLuaModules;
+    };
+    withPackages = import ./with-packages.nix { inherit buildEnv luaPackages;};
+    pkgs = luaPackages;
+    interpreter = "${self}/bin/lua";
+  };
+
+  enableParallelBuilding = true;
+
   configurePhase =
     if stdenv.isDarwin
     then ''
diff --git a/pkgs/development/interpreters/lua-5/5.3.nix b/pkgs/development/interpreters/lua-5/5.3.nix
index eb34391e199..c1fdc0fd990 100644
--- a/pkgs/development/interpreters/lua-5/5.3.nix
+++ b/pkgs/development/interpreters/lua-5/5.3.nix
@@ -1,5 +1,11 @@
-{ stdenv, fetchurl, readline, compat ? false }:
-
+{ stdenv, fetchurl, readline, compat ? false
+, callPackage
+, self
+, packageOverrides ? (self: super: {})
+}:
+let
+  luaPackages = callPackage ../../lua-modules {lua=self; overrides=packageOverrides;};
+in
 stdenv.mkDerivation rec {
   name = "lua-${version}";
   luaversion = "5.3";
@@ -10,6 +16,10 @@ stdenv.mkDerivation rec {
     sha256 = "0c2eed3f960446e1a3e4b9a1ca2f3ff893b6ce41942cf54d5dd59ab4b3b058ac";
   };
 
+  LuaPathSearchPaths    = luaPackages.getLuaPathList luaversion;
+  LuaCPathSearchPaths   = luaPackages.getLuaCPathList luaversion;
+  setupHook = luaPackages.lua-setup-hook LuaPathSearchPaths LuaCPathSearchPaths;
+
   buildInputs = [ readline ];
 
   patches = if stdenv.isDarwin then [ ./5.2.darwin.patch ] else [];
@@ -54,6 +64,16 @@ stdenv.mkDerivation rec {
     ln -s "$out/lib/pkgconfig/lua.pc" "$out/lib/pkgconfig/lua${luaversion}.pc"
   '';
 
+  passthru = rec {
+    buildEnv = callPackage ./wrapper.nix {
+      lua = self;
+      inherit (luaPackages) requiredLuaModules;
+    };
+    withPackages = import ./with-packages.nix { inherit buildEnv luaPackages;};
+    pkgs = luaPackages;
+    interpreter = "${self}/bin/lua";
+  };
+
   meta = {
     homepage = http://www.lua.org;
     description = "Powerful, fast, lightweight, embeddable scripting language";
diff --git a/pkgs/development/interpreters/lua-5/build-rocks.nix b/pkgs/development/interpreters/lua-5/build-rocks.nix
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/pkgs/development/interpreters/lua-5/build-rocks.nix
diff --git a/pkgs/development/interpreters/lua-5/build-rockspec.nix b/pkgs/development/interpreters/lua-5/build-rockspec.nix
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/pkgs/development/interpreters/lua-5/build-rockspec.nix
diff --git a/pkgs/development/interpreters/lua-5/setup-hook.nix b/pkgs/development/interpreters/lua-5/setup-hook.nix
new file mode 100644
index 00000000000..62caffd8d8a
--- /dev/null
+++ b/pkgs/development/interpreters/lua-5/setup-hook.nix
@@ -0,0 +1,15 @@
+{ runCommand, lib, }:
+
+LuaPathSearchPaths: LuaCPathSearchPaths:
+
+let
+  hook = ./setup-hook.sh;
+in runCommand "lua-setup-hook.sh" {
+  # hum doesn't seem to like caps !! BUG ?
+  luapathsearchpaths=lib.escapeShellArgs LuaPathSearchPaths;
+  luacpathsearchpaths=lib.escapeShellArgs LuaCPathSearchPaths;
+} ''
+  cp ${hook} hook.sh
+  substituteAllInPlace hook.sh
+  mv hook.sh $out
+''
diff --git a/pkgs/development/interpreters/lua-5/setup-hook.sh b/pkgs/development/interpreters/lua-5/setup-hook.sh
new file mode 100644
index 00000000000..a015f35e7ce
--- /dev/null
+++ b/pkgs/development/interpreters/lua-5/setup-hook.sh
@@ -0,0 +1,47 @@
+# set -e
+
+nix_print() {
+    if (( "${NIX_DEBUG:-0}" >= $1 )); then
+        echo "$2"
+    fi
+}
+
+nix_debug() {
+    nix_print 3 "$1"
+}
+
+addToLuaSearchPathWithCustomDelimiter() {
+    local varName="$1"
+    local absPattern="$2"
+    # delete longest match starting from the lua placeholder '?'
+    local topDir="${absPattern%%\?*}"
+
+    # export only if the folder exists else LUA_PATH grows too big
+    if  [ ! -d "$topDir" ]; then return; fi
+
+    export "${varName}=${!varName:+${!varName};}${absPattern}"
+}
+
+addToLuaPath() {
+    local dir="$1"
+
+    if [[ ! -d "$dir" ]]; then
+        nix_debug "$dir not a directory abort"
+        return 0
+    fi
+    cd "$dir"
+    for pattern in @luapathsearchpaths@;
+    do
+        addToLuaSearchPathWithCustomDelimiter LUA_PATH "$PWD/$pattern"
+    done
+
+    # LUA_CPATH
+    for pattern in @luacpathsearchpaths@;
+    do
+        addToLuaSearchPathWithCustomDelimiter LUA_CPATH "$PWD/$pattern"
+    done
+    cd -
+}
+
+addEnvHooks "$hostOffset" addToLuaPath
+
diff --git a/pkgs/development/interpreters/lua-5/with-packages.nix b/pkgs/development/interpreters/lua-5/with-packages.nix
new file mode 100644
index 00000000000..0e0fbd39735
--- /dev/null
+++ b/pkgs/development/interpreters/lua-5/with-packages.nix
@@ -0,0 +1,4 @@
+{ buildEnv, luaPackages }:
+
+# this is a function that returns a function that returns an environment
+f: let packages = f luaPackages; in buildEnv.override { extraLibs = packages; }
diff --git a/pkgs/development/interpreters/lua-5/wrapper.nix b/pkgs/development/interpreters/lua-5/wrapper.nix
new file mode 100644
index 00000000000..9abbd77d575
--- /dev/null
+++ b/pkgs/development/interpreters/lua-5/wrapper.nix
@@ -0,0 +1,73 @@
+{ stdenv, lua, buildEnv, makeWrapper
+, extraLibs ? []
+, extraOutputsToInstall ? []
+, postBuild ? ""
+, ignoreCollisions ? false
+, lib
+, requiredLuaModules
+, makeWrapperArgs ? []
+}:
+
+# Create a lua executable that knows about additional packages.
+let
+  env = let
+    paths =  requiredLuaModules (extraLibs ++ [ lua ] );
+  in buildEnv {
+    name = "${lua.name}-env";
+
+    inherit paths;
+    inherit ignoreCollisions;
+    extraOutputsToInstall = [ "out" ] ++ extraOutputsToInstall;
+
+    # we create wrapper for the binaries in the different packages
+    postBuild = ''
+
+      . "${makeWrapper}/nix-support/setup-hook"
+
+      # get access to lua functions
+      . ${lua}/nix-support/setup-hook
+
+      if [ -L "$out/bin" ]; then
+          unlink "$out/bin"
+      fi
+      mkdir -p "$out/bin"
+
+      addToLuaPath "$out"
+
+      # take every binary from lua packages and put them into the env
+      for path in ${stdenv.lib.concatStringsSep " " paths}; do
+        nix_debug "looking for binaries in path = $path"
+        if [ -d "$path/bin" ]; then
+          cd "$path/bin"
+          for prg in *; do
+            if [ -f "$prg" ]; then
+              rm -f "$out/bin/$prg"
+              if [ -x "$prg" ]; then
+                nix_debug "Making wrapper $prg"
+                makeWrapper "$path/bin/$prg" "$out/bin/$prg" --suffix LUA_PATH ';' "$LUA_PATH"   --suffix LUA_CPATH ';' "$LUA_CPATH" ${stdenv.lib.concatStringsSep " " makeWrapperArgs}
+              fi
+            fi
+          done
+        fi
+      done
+    '' + postBuild;
+
+    inherit (lua) meta;
+
+    passthru = lua.passthru // {
+      interpreter = "${env}/bin/lua";
+      inherit lua;
+      env = stdenv.mkDerivation {
+        name = "interactive-${lua.name}-environment";
+        nativeBuildInputs = [ env ];
+
+        buildCommand = ''
+          echo >&2 ""
+          echo >&2 "*** lua 'env' attributes are intended for interactive nix-shell sessions, not for building! ***"
+          echo >&2 ""
+          exit 1
+        '';
+    };
+    };
+  };
+in env