diff options
author | Alyssa Ross <hi@alyssa.is> | 2019-02-07 15:19:21 +0000 |
---|---|---|
committer | Alyssa Ross <hi@alyssa.is> | 2019-02-07 23:35:47 +0000 |
commit | e5013c05a2f845255debf94318ab38ecef1c186b (patch) | |
tree | bec11a0bd31d3432a16899e5539f1098f1c168a4 /nixpkgs/pkgs/development/interpreters/lua-5 | |
parent | 4fc07c92ec07cafcf6d56143ea7334693143ef88 (diff) | |
parent | 2d2f10475138b7206572dc3ec288184df2be022e (diff) | |
download | nixlib-e5013c05a2f845255debf94318ab38ecef1c186b.tar nixlib-e5013c05a2f845255debf94318ab38ecef1c186b.tar.gz nixlib-e5013c05a2f845255debf94318ab38ecef1c186b.tar.bz2 nixlib-e5013c05a2f845255debf94318ab38ecef1c186b.tar.lz nixlib-e5013c05a2f845255debf94318ab38ecef1c186b.tar.xz nixlib-e5013c05a2f845255debf94318ab38ecef1c186b.tar.zst nixlib-e5013c05a2f845255debf94318ab38ecef1c186b.zip |
Merge commit '2d2f10475138b7206572dc3ec288184df2be022e'
Diffstat (limited to 'nixpkgs/pkgs/development/interpreters/lua-5')
12 files changed, 507 insertions, 4 deletions
diff --git a/nixpkgs/pkgs/development/interpreters/lua-5/5.1.nix b/nixpkgs/pkgs/development/interpreters/lua-5/5.1.nix index 09af492490cf..b2948b392d5e 100644 --- a/nixpkgs/pkgs/development/interpreters/lua-5/5.1.nix +++ b/nixpkgs/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/nixpkgs/pkgs/development/interpreters/lua-5/5.2.nix b/nixpkgs/pkgs/development/interpreters/lua-5/5.2.nix index a8badf647c0c..e89a2cbece6d 100644 --- a/nixpkgs/pkgs/development/interpreters/lua-5/5.2.nix +++ b/nixpkgs/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/nixpkgs/pkgs/development/interpreters/lua-5/5.3.nix b/nixpkgs/pkgs/development/interpreters/lua-5/5.3.nix index eb34391e1993..c1fdc0fd9904 100644 --- a/nixpkgs/pkgs/development/interpreters/lua-5/5.3.nix +++ b/nixpkgs/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/nixpkgs/pkgs/development/interpreters/lua-5/build-lua-package.nix b/nixpkgs/pkgs/development/interpreters/lua-5/build-lua-package.nix new file mode 100644 index 000000000000..0bed5efe4f79 --- /dev/null +++ b/nixpkgs/pkgs/development/interpreters/lua-5/build-lua-package.nix @@ -0,0 +1,182 @@ +# Generic builder for lua packages +{ lib +, lua +, stdenv +, wrapLua +, unzip +, writeText +# Whether the derivation provides a lua module or not. +, toLuaModule +}: + +{ +name ? "${attrs.pname}-${attrs.version}" + +, version + +# by default prefix `name` e.g. "lua5.2-${name}" +, namePrefix ? "lua" + lua.luaversion + "-" + +# Dependencies for building the package +, buildInputs ? [] + +# Dependencies needed for running the checkPhase. +# These are added to buildInputs when doCheck = true. +, checkInputs ? [] + +# propagate build dependencies so in case we have A -> B -> C, +# C can import package A propagated by B +, propagatedBuildInputs ? [] +, propagatedNativeBuildInputs ? [] + +# used to disable derivation, useful for specific lua versions +, disabled ? false + +# Additional arguments to pass to the makeWrapper function, which wraps +# generated binaries. +, makeWrapperArgs ? [] +, external_deps ? propagatedBuildInputs ++ buildInputs + +# Skip wrapping of lua programs altogether +, dontWrapLuaPrograms ? false + +, meta ? {} + +, passthru ? {} +, doCheck ? false + +# appended to the luarocks generated config +# in peculiar variables like { EVENT_INCDIR } can be useful to work around +# luarocks limitations, ie, luarocks consider include/lib folders to be subfolders of the same package in external_deps_dirs +# as explained in https://github.com/luarocks/luarocks/issues/766 +, extraConfig ? "" + +# relative to srcRoot, path to the rockspec to use when using rocks +, rockspecFilename ? "../*.rockspec" + +# must be set for packages that don't have a rock +, knownRockspec ? null + +, ... } @ attrs: + + +# Keep extra attributes from `attrs`, e.g., `patchPhase', etc. +if disabled +then throw "${name} not supported for interpreter ${lua}" +else + +let + + deps_dirs= lib.concatStringsSep ", " ( + map (x: "\"${builtins.toString x}\"") external_deps + ); + + # TODO + # - add rocktrees (look at torch-distro.nix/https://github.com/luarocks/luarocks/wiki/Config-file-format) + # - silence warnings + luarocks_config = "luarocksConfig"; + luarocks_content = '' + local_cache = "" + -- array of strings + external_deps_dirs = { + ${deps_dirs} + } + rocks_trees = { + } + ${extraConfig} + ''; +in +toLuaModule ( lua.stdenv.mkDerivation ( +builtins.removeAttrs attrs ["disabled" "checkInputs"] // { + + name = namePrefix + name; + + buildInputs = [ wrapLua lua.pkgs.luarocks ] + ++ buildInputs + ++ lib.optionals doCheck checkInputs + ; + + # propagate lua to active setup-hook in nix-shell + propagatedBuildInputs = propagatedBuildInputs ++ [ lua ]; + doCheck = false; + + # enabled only for src.rock + setSourceRoot= let + name_only=(builtins.parseDrvName name).name; + in + lib.optionalString (knownRockspec == null) '' + # format is rockspec_basename/source_basename + # rockspec can set it via spec.source.dir + folder=$(find . -mindepth 2 -maxdepth 2 -type d -path '*${name_only}*/*'|head -n1) + sourceRoot="$folder" + ''; + + configurePhase = '' + runHook preConfigure + + cat > ${luarocks_config} <<EOF + ${luarocks_content} + EOF + export LUAROCKS_CONFIG=$PWD/${luarocks_config}; + '' + + lib.optionalString (knownRockspec != null) '' + + # prevents the following type of error: + # Inconsistency between rockspec filename (42fm1b3d7iv6fcbhgm9674as3jh6y2sh-luv-1.22.0-1.rockspec) and its contents (luv-1.22.0-1.rockspec) + rockspecFilename="$TMP/$(stripHash ''${knownRockspec})" + cp ''${knownRockspec} $rockspecFilename + runHook postConfigure + ''; + + buildPhase = '' + runHook preBuild + + nix_debug "Using LUAROCKS_CONFIG=$LUAROCKS_CONFIG" + + LUAROCKS=luarocks + if (( ''${NIX_DEBUG:-0} >= 1 )); then + LUAROCKS="$LUAROCKS --verbose" + fi + + patchShebangs . + + runHook postBuild + ''; + + postFixup = lib.optionalString (!dontWrapLuaPrograms) '' + wrapLuaPrograms + '' + attrs.postFixup or ''''; + + installPhase = attrs.installPhase or '' + runHook preInstall + + # luarocks make assumes sources are available in cwd + # After the build is complete, it also installs the rock. + # If no argument is given, it looks for a rockspec in the current directory + # but some packages have several rockspecs in their source directory so + # we force the use of the upper level since it is + # the sole rockspec in that folder + # maybe we could reestablish dependency checking via passing --rock-trees + + nix_debug "ROCKSPEC $rockspecFilename" + nix_debug "cwd: $PWD" + $LUAROCKS make --deps-mode=none --tree $out ''${rockspecFilename} + + # to prevent collisions when creating environments + # also added -f as it doesn't always exist + # don't remove the whole directory as + rm -rf $out/lib/luarocks/rocks/manifest + + runHook postInstall + ''; + + passthru = { + inherit lua; # The lua interpreter + } // passthru; + + meta = with lib.maintainers; { + platforms = lua.meta.platforms; + # add extra maintainer(s) to every package + maintainers = (meta.maintainers or []) ++ [ ]; + } // meta; +})) diff --git a/nixpkgs/pkgs/development/interpreters/lua-5/build-rocks.nix b/nixpkgs/pkgs/development/interpreters/lua-5/build-rocks.nix new file mode 100644 index 000000000000..e69de29bb2d1 --- /dev/null +++ b/nixpkgs/pkgs/development/interpreters/lua-5/build-rocks.nix diff --git a/nixpkgs/pkgs/development/interpreters/lua-5/build-rockspec.nix b/nixpkgs/pkgs/development/interpreters/lua-5/build-rockspec.nix new file mode 100644 index 000000000000..e69de29bb2d1 --- /dev/null +++ b/nixpkgs/pkgs/development/interpreters/lua-5/build-rockspec.nix diff --git a/nixpkgs/pkgs/development/interpreters/lua-5/setup-hook.nix b/nixpkgs/pkgs/development/interpreters/lua-5/setup-hook.nix new file mode 100644 index 000000000000..62caffd8d8a0 --- /dev/null +++ b/nixpkgs/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/nixpkgs/pkgs/development/interpreters/lua-5/setup-hook.sh b/nixpkgs/pkgs/development/interpreters/lua-5/setup-hook.sh new file mode 100644 index 000000000000..3989bedffdb1 --- /dev/null +++ b/nixpkgs/pkgs/development/interpreters/lua-5/setup-hook.sh @@ -0,0 +1,47 @@ +# set -e + +nix_print() { + if [ ${NIX_DEBUG:-0} -ge $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 NIX_LUA_PATH "$PWD/$pattern" + done + + # LUA_CPATH + for pattern in @luacpathsearchpaths@; + do + addToLuaSearchPathWithCustomDelimiter NIX_LUA_CPATH "$PWD/$pattern" + done + cd - >/dev/null +} + +addEnvHooks "$hostOffset" addToLuaPath + diff --git a/nixpkgs/pkgs/development/interpreters/lua-5/with-packages.nix b/nixpkgs/pkgs/development/interpreters/lua-5/with-packages.nix new file mode 100644 index 000000000000..0e0fbd397358 --- /dev/null +++ b/nixpkgs/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/nixpkgs/pkgs/development/interpreters/lua-5/wrap-lua.nix b/nixpkgs/pkgs/development/interpreters/lua-5/wrap-lua.nix new file mode 100644 index 000000000000..f00e0d5ac336 --- /dev/null +++ b/nixpkgs/pkgs/development/interpreters/lua-5/wrap-lua.nix @@ -0,0 +1,19 @@ +{ lib +, lua +, makeSetupHook +, makeWrapper +}: + +with lib; + +# defined in trivial-builders.nix +# imported as wrapLua in lua-packages.nix and passed to build-lua-derivation to be used as buildInput +makeSetupHook { + deps = makeWrapper; + substitutions.executable = lua.interpreter; + substitutions.lua = lua; + substitutions.LuaPathSearchPaths = lib.escapeShellArgs lua.LuaPathSearchPaths; + substitutions.LuaCPathSearchPaths = lib.escapeShellArgs lua.LuaPathSearchPaths; + +} ./wrap.sh + diff --git a/nixpkgs/pkgs/development/interpreters/lua-5/wrap.sh b/nixpkgs/pkgs/development/interpreters/lua-5/wrap.sh new file mode 100644 index 000000000000..545a0ae271c4 --- /dev/null +++ b/nixpkgs/pkgs/development/interpreters/lua-5/wrap.sh @@ -0,0 +1,99 @@ +# Inspired by python/wrapper.nix +# Wrapper around wrapLuaProgramsIn, below. The $luaPath +# variable is passed in from the buildLuarocksPackage function. +set -e + +wrapLuaPrograms() { + wrapLuaProgramsIn "$out/bin" "$out $luaPath" +} + +# Builds environment variables like LUA_PATH and PATH walking through closure +# of dependencies. +buildLuaPath() { + local luaPath="$1" + local path + + # Create an empty table of paths (see doc on loadFromPropagatedInputs + # for how this is used). Build up the program_PATH and program_LUA_PATH + # variables. + declare -A luaPathsSeen=() + program_PATH= + luaPathsSeen["@lua@"]=1 + addToSearchPath program_PATH @lua@/bin + for path in $luaPath; do + addToLuaPath "$path" + done +} + + +# with an executable shell script which will set some environment variables +# and then call into the original binary (which has been given a .wrapped suffix). +# luaPath is a list of directories +wrapLuaProgramsIn() { + local dir="$1" + local luaPath="$2" + local f + + buildLuaPath "$luaPath" + + if [ ! -d "$dir" ]; then + nix_debug "$dir not a directory" + return + fi + + nix_debug "wrapping programs in [$dir]" + + # Find all regular files in the output directory that are executable. + find "$dir" -type f -perm -0100 -print0 | while read -d "" f; do + # Rewrite "#! .../env lua" to "#! /nix/store/.../lua". + # Strip suffix, like "3" or "2.7m" -- we don't have any choice on which + # Lua to use besides one with this hook anyway. + if head -n1 "$f" | grep -q '#!.*/env.*\(lua\)'; then + sed -i "$f" -e "1 s^.*/env[ ]*\(lua\)[^ ]*^#! @executable@^" + fi + + # wrapProgram creates the executable shell script described + # above. The script will set LUA_(C)PATH and PATH variables! + # (see pkgs/build-support/setup-hooks/make-wrapper.sh) + local -a wrap_args=("$f" + --prefix PATH ':' "$program_PATH" + --prefix LUA_PATH ';' "$NIX_LUA_PATH" + --prefix LUA_CPATH ';' "$NIX_LUA_CPATH" + ) + + # Add any additional arguments provided by makeWrapperArgs + # argument to buildLuaPackage. + # makeWrapperArgs + local -a user_args="($makeWrapperArgs)" + local -a wrapProgramArgs=("${wrap_args[@]}" "${user_args[@]}") + + # see setup-hooks/make-wrapper.sh + wrapProgram "${wrapProgramArgs[@]}" + + done +} + +# Adds the lib and bin directories to the LUA_PATH and PATH variables, +# respectively. Recurses on any paths declared in +# `propagated-native-build-inputs`, while avoiding duplicating paths by +# flagging the directories it has visited in `luaPathsSeen`. +loadFromPropagatedInputs() { + local dir="$1" + # Stop if we've already visited here. + if [ -n "${luaPathsSeen[$dir]}" ]; then + return; + fi + luaPathsSeen[$dir]=1 + + addToLuaPath "$dir" + addToSearchPath program_PATH $dir/bin + + # Inspect the propagated inputs (if they exist) and recur on them. + local prop="$dir/nix-support/propagated-native-build-inputs" + if [ -e "$prop" ]; then + local new_path + for new_path in $(cat $prop); do + loadFromPropagatedInputs "$new_path" + done + fi +} diff --git a/nixpkgs/pkgs/development/interpreters/lua-5/wrapper.nix b/nixpkgs/pkgs/development/interpreters/lua-5/wrapper.nix new file mode 100644 index 000000000000..7f584c0f0aff --- /dev/null +++ b/nixpkgs/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 ';' "$NIX_LUA_PATH" --suffix LUA_CPATH ';' "$NIX_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 |