about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--maintainers/scripts/luarocks-packages.csv40
-rwxr-xr-xmaintainers/scripts/update-luarocks-packages105
-rw-r--r--maintainers/scripts/update-luarocks-shell.nix9
-rw-r--r--pkgs/applications/networking/browsers/luakit/default.nix25
-rw-r--r--pkgs/development/interpreters/lua-5/build-lua-package.nix113
-rw-r--r--pkgs/development/lua-modules/generated-packages.nix803
-rw-r--r--pkgs/development/lua-modules/luasql.patch37
-rw-r--r--pkgs/development/lua-modules/luuid.patch16
-rw-r--r--pkgs/development/lua-modules/overrides.nix299
-rw-r--r--pkgs/development/tools/misc/luarocks/darwin-3.0.x.patch (renamed from pkgs/development/tools/misc/luarocks/darwin.patch)0
-rw-r--r--pkgs/development/tools/misc/luarocks/darwin-3.1.3.patch24
-rw-r--r--pkgs/development/tools/misc/luarocks/default.nix6
-rw-r--r--pkgs/development/tools/misc/luarocks/luarocks-nix.nix7
-rw-r--r--pkgs/games/mudlet/default.nix8
-rw-r--r--pkgs/servers/dns/knot-resolver/default.nix2
-rw-r--r--pkgs/servers/xmpp/prosody/default.nix32
-rw-r--r--pkgs/top-level/all-packages.nix5
-rw-r--r--pkgs/top-level/lua-packages.nix432
18 files changed, 1061 insertions, 902 deletions
diff --git a/maintainers/scripts/luarocks-packages.csv b/maintainers/scripts/luarocks-packages.csv
index b958d2e72779..57d08b3649a1 100644
--- a/maintainers/scripts/luarocks-packages.csv
+++ b/maintainers/scripts/luarocks-packages.csv
@@ -3,10 +3,17 @@ ansicolors,,,,,
 argparse,,,,,
 basexx,,,,,
 binaryheap,,,,,vcunat
+bit32,,,,lua5_1,lblasc
+busted,,,,,
+cjson,lua-cjson,,,,
+compat53,,,,,vcunat
+coxpcall,,,1.17.0-1,,
+cqueues,,,,,vcunat
+cyrussasl,,,,,vcunat
 digestif,,http://luarocks.org/dev,,lua5_3,
 dkjson,,,,,
 fifo,,,,,
-http,,,,,
+http,,,,,vcunat
 inspect,,,,,
 ldoc,,,,,
 lgi,,,,,
@@ -15,35 +22,44 @@ lpeg_patterns,,,,,
 lpeglabel,,,,,
 lpty,,,,,
 lrexlib-gnu,,,,,
+lrexlib-pcre,,,,,vyp
 lrexlib-posix,,,,,
 ltermbox,,,,,
-cjson,lua-cjson,,,,
 lua-cmsgpack,,,,,
-lua_cliargs,,,,,
 lua-iconv,,,,,
 lua-lsp,,http://luarocks.org/dev,,,
 lua-messagepack,,,,,
 lua-term,,,,,
 lua-toml,,,,,
 lua-zlib,,,,,koral
+lua_cliargs,,,,,
 luabitop,,,,,
-luaevent,,,,,
 luacheck,,,,,
+luadbi,,,,,
+luadbi-mysql,,,,,
+luadbi-postgresql,,,,,
+luadbi-sqlite3,,,,,
+luaevent,,,,,
+luaexpat,,,,,flosse
 luaffi,,http://luarocks.org/dev,,,
+luafilesystem,,,1.7.0-2,,flosse vcunat
+luaossl,,,,lua5_1,vcunat
 luaposix,,,,,vyp lblasc
+luasec,,,,,flosse
+luasocket,,,,,
+luasql-sqlite3,,,,,vyp
+luassert,,,,,
+luasystem,,,,,
 luazip,,,,,
 luuid,,,,,
+luv,,,,,
 markdown,,,,,
+mediator_lua,,,,,
+mpack,,,,,
+nvim-client,,,,,
 penlight,,,,,
 rapidjson,,,,,
 say,,,,,
 std__debug,std._debug,,,,
 std_normalize,std.normalize,,,,
-luv,,,,,
-luasystem,,,,,
-mediator_lua,,http://luarocks.org/manifests/teto,,,
-mpack,,,,,
-nvim-client,,,,,
-busted,,http://luarocks.org/manifests/teto,,,
-luassert,,,,,
-coxpcall,,https://luarocks.org/manifests/hisham,1.17.0-1,,
+stdlib,,,,,vyp
diff --git a/maintainers/scripts/update-luarocks-packages b/maintainers/scripts/update-luarocks-packages
index e2f2cc6bbd2e..a8d67d208e38 100755
--- a/maintainers/scripts/update-luarocks-packages
+++ b/maintainers/scripts/update-luarocks-packages
@@ -1,5 +1,5 @@
 #!/usr/bin/env nix-shell
-#!nix-shell -p nix-prefetch-scripts luarocks-nix -i bash
+#!nix-shell update-luarocks-shell.nix -i bash
 
 # You'll likely want to use
 # ``
@@ -8,17 +8,21 @@
 # to update all libraries in that folder.
 # to debug, redirect stderr to stdout with 2>&1
 
-
 # stop the script upon C-C
 set -eu -o pipefail
 
 CSV_FILE="maintainers/scripts/luarocks-packages.csv"
 TMP_FILE="$(mktemp)"
+# Set in the update-luarocks-shell.nix
+NIXPKGS_PATH="$LUAROCKS_NIXPKGS_PATH"
 
-exit_trap()
-{
-  local lc="$BASH_COMMAND" rc=$?
-  test $rc -eq 0 || echo -e "*** error $rc: $lc.\nGenerated temporary file in $TMP_FILE" >&2
+# 10 is a pretty arbitrary number of simultaneous jobs, but it is generally
+# impolite to hit a webserver with *too* many simultaneous connections :)
+PARALLEL_JOBS=10
+
+exit_trap() {
+    local lc="$BASH_COMMAND" rc=$?
+    test $rc -eq 0 || echo -e "*** error $rc: $lc.\nGenerated temporary file in $TMP_FILE" >&2
 }
 
 print_help() {
@@ -37,19 +41,19 @@ fi
 trap exit_trap EXIT
 
 while getopts ":hc:" opt; do
-  case $opt in
+    case $opt in
     h)
-      print_help
-      ;;
+        print_help
+        ;;
     c)
-      echo "Loading package list from $OPTARG !" >&2
-      CSV_FILE="$OPTARG"
-      ;;
+        echo "Loading package list from $OPTARG !" >&2
+        CSV_FILE="$OPTARG"
+        ;;
     \?)
-      echo "Invalid option: -$OPTARG" >&2
-      ;;
-  esac
-  shift $((OPTIND-1))
+        echo "Invalid option: -$OPTARG" >&2
+        ;;
+    esac
+    shift $((OPTIND - 1))
 done
 
 GENERATED_NIXFILE="$1"
@@ -72,43 +76,60 @@ FOOTER="
 /* GENERATED */
 "
 
-
-function convert_pkg () {
+function convert_pkg() {
     nix_pkg_name="$1"
     lua_pkg_name="$2"
-    server="${3:+--only-server=$3}"
-    pkg_version="${4:-}"
-    lua_version="${5:+--lua-dir=$(nix path-info nixpkgs.$5)/bin}"
-
-    echo "looking at $lua_pkg_name (version $pkg_version) from server [$server]" >&2
-    cmd="luarocks nix $server $lua_version $lua_pkg_name $pkg_version"
-    echo "Running $cmd" >&2
-    drv="$nix_pkg_name = $($cmd)"
-    if [ $? -ne 0 ]; then
-        echo "Failed to convert $pkg" >&2
+    server="$3"
+    pkg_version="$4"
+    lua_version="$5"
+    maintainers="$6"
+
+    if [ "${nix_pkg_name:0:1}" == "#" ]; then
+        echo "Skipping comment ${*}" >&2
+        return
+    fi
+    if [ -z "$lua_pkg_name" ]; then
+        echo "Using nix_name as lua_pkg_name for '$nix_pkg_name'" >&2
+        lua_pkg_name="$nix_pkg_name"
+    fi
+
+    echo "Building expression for $lua_pkg_name (version $pkg_version) from server [$server]" >&2
+    luarocks_args=(nix)
+    if [[ -n $server ]]; then
+        luarocks_args+=("--only-server=$server")
+    fi
+    if [[ -n $maintainers ]]; then
+        luarocks_args+=("--maintainers=$maintainers")
+    fi
+    if [[ -n $lua_version ]]; then
+        lua_drv_path=$(nix-build --no-out-link "$NIXPKGS_PATH" -A "$lua_version")
+        luarocks_args+=("--lua-dir=$lua_drv_path/bin")
+    fi
+    luarocks_args+=("$lua_pkg_name")
+    if [[ -n $pkg_version ]]; then
+        luarocks_args+=("$pkg_version")
+    fi
+    echo "Running 'luarocks ${luarocks_args[*]}'" >&2
+    if drv="$nix_pkg_name = $(luarocks "${luarocks_args[@]}")"; then
+        echo "$drv"
     else
-        echo "$drv" | tee -a "$TMP_FILE"
+        echo "Failed to convert $nix_pkg_name" >&2
+        return 1
     fi
 }
 
 # params needed when called via callPackage
 echo "$HEADER" | tee "$TMP_FILE"
 
-# list of packages with format
-while IFS=, read -r nix_pkg_name lua_pkg_name server pkg_version luaversion
-do
-    if [ "${nix_pkg_name:0:1}" == "#" ]; then
-        echo "Skipping comment ${nix_pkg_name}" >&2
-        continue
-    fi
-    if [ -z "$lua_pkg_name" ]; then
-        echo "Using nix_name as lua_pkg_name" >&2
-        lua_pkg_name="$nix_pkg_name"
-    fi
-    convert_pkg "$nix_pkg_name" "$lua_pkg_name" "$server" "$pkg_version" "$luaversion"
-done < "$CSV_FILE"
+# Ensure parallel can run our bash function
+export -f convert_pkg
+export SHELL=bash
+# Read each line in the csv file and run convert_pkg for each, in parallel
+parallel --group --keep-order --halt now,fail=1 --jobs "$PARALLEL_JOBS" --colsep ',' convert_pkg {} <"$CSV_FILE" | tee -a "$TMP_FILE"
 
 # close the set
 echo "$FOOTER" | tee -a "$TMP_FILE"
 
 cp "$TMP_FILE" "$GENERATED_NIXFILE"
+
+# vim: set ts=4 sw=4 ft=sh:
diff --git a/maintainers/scripts/update-luarocks-shell.nix b/maintainers/scripts/update-luarocks-shell.nix
new file mode 100644
index 000000000000..23a940b3691b
--- /dev/null
+++ b/maintainers/scripts/update-luarocks-shell.nix
@@ -0,0 +1,9 @@
+{ nixpkgs ? import ../.. { }
+}:
+with nixpkgs;
+mkShell {
+  buildInputs = [
+    bash luarocks-nix nix-prefetch-scripts parallel
+  ];
+  LUAROCKS_NIXPKGS_PATH = toString nixpkgs.path;
+}
diff --git a/pkgs/applications/networking/browsers/luakit/default.nix b/pkgs/applications/networking/browsers/luakit/default.nix
index 60e9c603e29e..69beeb167590 100644
--- a/pkgs/applications/networking/browsers/luakit/default.nix
+++ b/pkgs/applications/networking/browsers/luakit/default.nix
@@ -1,17 +1,9 @@
 { stdenv, fetchFromGitHub, pkgconfig, wrapGAppsHook
-, help2man, lua5, luafilesystem, luajit, sqlite
+, help2man, luafilesystem, luajit, sqlite
 , webkitgtk, gtk3, gst_all_1, glib-networking
 }:
 
-let
-  lualibs = [luafilesystem];
-  getPath       = lib : type : "${lib}/lib/lua/${lua5.luaversion}/?.${type};${lib}/share/lua/${lua5.luaversion}/?.${type}";
-  getLuaPath    = lib : getPath lib "lua";
-  getLuaCPath   = lib : getPath lib "so";
-  luaPath       = stdenv.lib.concatStringsSep ";" (map getLuaPath lualibs);
-  luaCPath      = stdenv.lib.concatStringsSep ";" (map getLuaCPath lualibs);
-
-in stdenv.mkDerivation rec {
+stdenv.mkDerivation rec {
   pname = "luakit";
   version = "2.1";
 
@@ -27,7 +19,7 @@ in stdenv.mkDerivation rec {
   ];
 
   buildInputs = [
-    webkitgtk lua5 luafilesystem luajit sqlite gtk3
+    webkitgtk luafilesystem luajit sqlite gtk3
     gst_all_1.gstreamer gst_all_1.gst-plugins-base
     gst_all_1.gst-plugins-good gst_all_1.gst-plugins-bad gst_all_1.gst-plugins-ugly
     gst_all_1.gst-libav
@@ -36,8 +28,11 @@ in stdenv.mkDerivation rec {
 
   preBuild = ''
     # build-utils/docgen/gen.lua:2: module 'lib.lousy.util' not found
-    # TODO: why is not this the default?
-    LUA_PATH=?.lua
+    # TODO: why is not this the default? The test runner adds
+    # ';./lib/?.lua;./lib/?/init.lua' to package.path, but the build-utils
+    # scripts don't add an equivalent
+    export LUA_PATH="$NIX_LUA_PATH;./?.lua;./?/init.lua"
+    export LUA_CPATH="$NIX_LUA_CPATH"
   '';
 
   makeFlags = [
@@ -54,8 +49,8 @@ in stdenv.mkDerivation rec {
   in ''
     gappsWrapperArgs+=(
       --prefix XDG_CONFIG_DIRS : "$out/etc/xdg"
-      --set LUA_PATH '${luaKitPath};${luaPath};'
-      --set LUA_CPATH '${luaCPath};'
+      --prefix LUA_PATH ';' "${luaKitPath};$NIX_LUA_PATH"
+      --prefix LUA_CPATH ';' "$NIX_LUA_CPATH"
     )
   '';
 
diff --git a/pkgs/development/interpreters/lua-5/build-lua-package.nix b/pkgs/development/interpreters/lua-5/build-lua-package.nix
index f383c7283698..7133f54025b1 100644
--- a/pkgs/development/interpreters/lua-5/build-lua-package.nix
+++ b/pkgs/development/interpreters/lua-5/build-lua-package.nix
@@ -27,12 +27,13 @@ name ? "${attrs.pname}-${attrs.version}"
 , propagatedNativeBuildInputs ? []
 
 # used to disable derivation, useful for specific lua versions
+# TODO move from this setting meta.broken to a 'disabled' attribute on the
+# package, then use that to skip/include in each lua${ver}Packages set?
 , 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
@@ -42,11 +43,19 @@ name ? "${attrs.pname}-${attrs.version}"
 , 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
+# Non-Lua / system (e.g. C library) dependencies. Is a list of deps, where
+# each dep is either a derivation, or an attribute set like
+# { name = "rockspec external_dependencies key"; dep = derivation; }
+# The latter is used to work-around luarocks having a problem with
+# multiple-output derivations as external deps:
+# https://github.com/luarocks/luarocks/issues/766<Paste>
+, externalDeps ? lib.unique (lib.filter (drv: !drv ? luaModule) (propagatedBuildInputs ++ buildInputs))
+
+# Appended to the generated luarocks config
 , extraConfig ? ""
+# Inserted into the generated luarocks config in the "variables" table
+, extraVariables ? ""
+# The two above arguments have access to builder variables -- e.g. to $out
 
 # relative to srcRoot, path to the rockspec to use when using rocks
 , rockspecFilename ?  "../*.rockspec"
@@ -58,44 +67,95 @@ name ? "${attrs.pname}-${attrs.version}"
 
 
 # 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";
+  # TODO fix warnings "Couldn't load rockspec for ..." during manifest
+  # construction -- from initial investigation, appears it will require
+  # upstream luarocks changes to fix cleanly (during manifest construction,
+  # luarocks only looks for rockspecs in the default/system tree instead of all
+  # configured trees)
+  luarocks_config = "luarocks-config.lua";
   luarocks_content = ''
     local_cache = ""
-    -- array of strings
+    -- To prevent collisions when creating environments, we install the rock
+    -- files into per-package subdirectories
+    rocks_subdir = '${rocksSubdir}'
+    -- Then we need to tell luarocks where to find the rock files per
+    -- dependency
+    rocks_trees = {
+      ${lib.concatStringsSep "\n, " rocksTrees}
+    }
+  '' + lib.optionalString lua.pkgs.isLuaJIT ''
+    -- Luajit provides some additional functionality built-in; this exposes
+    -- that to luarock's dependency system
+    rocks_provided = {
+      jit='${lua.luaversion}-1';
+      ffi='${lua.luaversion}-1';
+      luaffi='${lua.luaversion}-1';
+      bit='${lua.luaversion}-1';
+    }
+  '' + ''
+    -- For single-output external dependencies
     external_deps_dirs = {
-    ${deps_dirs}
+      ${lib.concatStringsSep "\n, " externalDepsDirs}
     }
-    rocks_trees = {
+    variables = {
+      -- Some needed machinery to handle multiple-output external dependencies,
+      -- as per https://github.com/luarocks/luarocks/issues/766
+      ${lib.optionalString (lib.length depVariables > 0) ''
+      ${lib.concatStringsSep "\n  " depVariables}''}
+      ${extraVariables}
     }
     ${extraConfig}
   '';
+
+  rocksSubdir = "${attrs.pname}-${version}-rocks";
+
+  externalDepsDirs = map
+    (x: "'${builtins.toString x}'")
+    (lib.filter (lib.isDerivation) externalDeps);
+
+  rocksTrees = lib.imap0
+    (i: dep: "{ name = [[dep-${toString i}]], root = '${dep}', rocks_dir = '${dep}/${dep.rocksSubdir}' }")
+    requiredLuaRocks;
+
+  # Filter out the lua derivation itself from the Lua module dependency
+  # closure, as it doesn't have a rock tree :)
+  requiredLuaRocks = lib.filter (d: d ? luaModule)
+    (lua.pkgs.requiredLuaModules propagatedBuildInputs);
+
+  # Explicitly point luarocks to the relevant locations for multiple-output
+  # derivations that are external dependencies, to work around an issue it has
+  # (https://github.com/luarocks/luarocks/issues/766)
+  depVariables = lib.concatMap ({name, dep}: [
+    "${name}_INCDIR='${lib.getDev dep}/include';"
+    "${name}_LIBDIR='${lib.getLib dep}/lib';"
+    "${name}_BINDIR='${lib.getBin dep}/bin';"
+  ]) externalDeps';
+
+  # example externalDeps': [ { name = "CRYPTO"; dep = pkgs.openssl; } ]
+  externalDeps' = lib.filter (dep: !lib.isDerivation dep) externalDeps;
 in
 toLuaModule ( lua.stdenv.mkDerivation (
-builtins.removeAttrs attrs ["disabled" "checkInputs"] // {
+builtins.removeAttrs attrs ["disabled" "checkInputs" "externalDeps"] // {
 
   name = namePrefix + name;
 
   buildInputs = [ wrapLua lua.pkgs.luarocks ]
     ++ buildInputs
     ++ lib.optionals doCheck checkInputs
+    ++ (map (d: d.dep) externalDeps')
     ;
 
   # propagate lua to active setup-hook in nix-shell
   propagatedBuildInputs = propagatedBuildInputs ++ [ lua ];
-  doCheck = false;
+  inherit doCheck;
+
+  # @-patterns do not capture formal argument default values, so we need to
+  # explicitly inherit this for it to be available as a shell variable in the
+  # builder
+  inherit rockspecFilename;
+  inherit rocksSubdir;
 
   # enabled only for src.rock
   setSourceRoot= let
@@ -162,23 +222,20 @@ builtins.removeAttrs attrs ["disabled" "checkInputs"] // {
 
     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-${lua.luaversion}/manifest
+    $LUAROCKS make --deps-mode=all --tree=$out ''${rockspecFilename}
 
     runHook postInstall
   '';
 
   passthru = {
     inherit lua; # The lua interpreter
+    inherit externalDeps;
   } // passthru;
 
   meta = with lib.maintainers; {
     platforms = lua.meta.platforms;
     # add extra maintainer(s) to every package
     maintainers = (meta.maintainers or []) ++ [ ];
+    broken = disabled;
   } // meta;
 }))
diff --git a/pkgs/development/lua-modules/generated-packages.nix b/pkgs/development/lua-modules/generated-packages.nix
index d5641cf4ce21..6b6c82840c2e 100644
--- a/pkgs/development/lua-modules/generated-packages.nix
+++ b/pkgs/development/lua-modules/generated-packages.nix
@@ -21,7 +21,7 @@ ansicolors = buildLuarocksPackage {
   disabled = (luaOlder "5.1");
   propagatedBuildInputs = [ lua ];
 
-  meta = {
+  meta = with stdenv.lib; {
     homepage = "https://github.com/kikito/ansicolors.lua";
     description = "Library for color Manipulation.";
     license = {
@@ -34,13 +34,13 @@ argparse = buildLuarocksPackage {
   version = "0.6.0-1";
 
   src = fetchurl {
-    url    = https://luarocks.org/argparse-0.6.0-1.src.rock;
+    url    = https://raw.githubusercontent.com/rocks-moonscript-org/moonrocks-mirror/master/argparse-0.6.0-1.src.rock;
     sha256 = "10ic5wppyghd1lmgwgl0lb40pv8z9fi9i87080axxg8wsr19y0p4";
   };
   disabled = (luaOlder "5.1") || (luaAtLeast "5.4");
   propagatedBuildInputs = [ lua ];
 
-  meta = {
+  meta = with stdenv.lib; {
     homepage = "https://github.com/mpeterv/argparse";
     description = "A feature-rich command-line argument parser";
     license = {
@@ -65,7 +65,7 @@ basexx = buildLuarocksPackage {
   disabled = (luaOlder "5.1");
   propagatedBuildInputs = [ lua ];
 
-  meta = {
+  meta = with stdenv.lib; {
     homepage = "https://github.com/aiq/basexx";
     description = "A base2, base16, base32, base64 and base85 library for Lua";
     license = {
@@ -84,14 +84,166 @@ binaryheap = buildLuarocksPackage {
   disabled = (luaOlder "5.1");
   propagatedBuildInputs = [ lua ];
 
-  meta = {
+  meta = with stdenv.lib; {
     homepage = "https://github.com/Tieske/binaryheap.lua";
     description = "Binary heap implementation in pure Lua";
+    maintainers = with maintainers; [ vcunat ];
     license = {
       fullName = "MIT/X11";
     };
   };
 };
+bit32 = buildLuarocksPackage {
+  pname = "bit32";
+  version = "5.3.0-1";
+
+  src = fetchurl {
+    url    = https://luarocks.org/bit32-5.3.0-1.src.rock;
+    sha256 = "19i7kc2pfg9hc6qjq4kka43q6qk71bkl2rzvrjaks6283q6wfyzy";
+  };
+  disabled = (luaOlder "5.1");
+  propagatedBuildInputs = [ lua ];
+
+  meta = with stdenv.lib; {
+    homepage = "http://www.lua.org/manual/5.2/manual.html#6.7";
+    description = "Lua 5.2 bit manipulation library";
+    maintainers = with maintainers; [ lblasc ];
+    license = {
+      fullName = "MIT/X11";
+    };
+  };
+};
+busted = buildLuarocksPackage {
+  pname = "busted";
+  version = "2.0.rc13-0";
+
+  knownRockspec = (fetchurl {
+    url    = https://luarocks.org/busted-2.0.rc13-0.rockspec;
+    sha256 = "0hrvhg1324q5ra6cpjh1y3by6lrzs0ljah4jl48l8xlgw1z9z1q5";
+  }).outPath;
+
+  src = fetchurl {
+    url    = https://github.com/Olivine-Labs/busted/archive/v2.0.rc13-0.tar.gz;
+    sha256 = "0m72bldn1r6j94ahcfmpaq1mmysrshf9qi9fjas7hpal0jp8ivvl";
+  };
+
+  disabled = (luaOlder "5.1");
+  propagatedBuildInputs = [ lua lua_cliargs luafilesystem luasystem dkjson say luassert lua-term penlight mediator_lua ];
+
+  meta = with stdenv.lib; {
+    homepage = "http://olivinelabs.com/busted/";
+    description = "Elegant Lua unit testing.";
+    license = {
+      fullName = "MIT <http://opensource.org/licenses/MIT>";
+    };
+  };
+};
+cjson = buildLuarocksPackage {
+  pname = "lua-cjson";
+  version = "2.1.0.6-1";
+
+  src = fetchurl {
+    url    = https://luarocks.org/lua-cjson-2.1.0.6-1.src.rock;
+    sha256 = "0dqqkn0aygc780kiq2lbydb255r8is7raf7md0gxdjcagp8afps5";
+  };
+  disabled = (luaOlder "5.1");
+  propagatedBuildInputs = [ lua ];
+
+  meta = with stdenv.lib; {
+    homepage = "http://www.kyne.com.au/~mark/software/lua-cjson.php";
+    description = "A fast JSON encoding/parsing module";
+    license = {
+      fullName = "MIT";
+    };
+  };
+};
+compat53 = buildLuarocksPackage {
+  pname = "compat53";
+  version = "0.7-1";
+
+  src = fetchurl {
+    url    = https://luarocks.org/compat53-0.7-1.src.rock;
+    sha256 = "0kpaxbpgrwjn4jjlb17fn29a09w6lw732d21bi0302kqcaixqpyb";
+  };
+  disabled = (luaOlder "5.1") || (luaAtLeast "5.4");
+  propagatedBuildInputs = [ lua ];
+
+  meta = with stdenv.lib; {
+    homepage = "https://github.com/keplerproject/lua-compat-5.3";
+    description = "Compatibility module providing Lua-5.3-style APIs for Lua 5.2 and 5.1";
+    maintainers = with maintainers; [ vcunat ];
+    license = {
+      fullName = "MIT";
+    };
+  };
+};
+coxpcall = buildLuarocksPackage {
+  pname = "coxpcall";
+  version = "1.17.0-1";
+
+  src = fetchurl {
+    url    = https://luarocks.org/coxpcall-1.17.0-1.src.rock;
+    sha256 = "0n1jmda4g7x06458596bamhzhcsly6x0p31yp6q3jz4j11zv1zhi";
+  };
+
+  meta = with stdenv.lib; {
+    homepage = "http://keplerproject.github.io/coxpcall";
+    description = "Coroutine safe xpcall and pcall";
+    license = {
+      fullName = "MIT/X11";
+    };
+  };
+};
+cqueues = buildLuarocksPackage {
+  pname = "cqueues";
+  version = "20171014.52-0";
+
+  src = fetchurl {
+    url    = https://luarocks.org/cqueues-20171014.52-0.src.rock;
+    sha256 = "0q3iy1ja20nq2sn2n6badzhjq5kni86pfc09n5g2c46q9ja3vfzx";
+  };
+  disabled = (lua.luaversion != "5.2");
+  propagatedBuildInputs = [ lua ];
+
+  meta = with stdenv.lib; {
+    homepage = "http://25thandclement.com/~william/projects/cqueues.html";
+    description = "Continuation Queues: Embeddable asynchronous networking, threading, and notification framework for Lua on Unix.";
+    maintainers = with maintainers; [ vcunat ];
+    license = {
+      fullName = "MIT/X11";
+    };
+  };
+};
+cyrussasl = buildLuarocksPackage {
+  pname = "cyrussasl";
+  version = "1.1.0-1";
+
+  knownRockspec = (fetchurl {
+    url    = https://luarocks.org/cyrussasl-1.1.0-1.rockspec;
+    sha256 = "0zy9l00l7kr3sq8phdm52jqhlqy35vdv6rdmm8mhjihcbx1fsplc";
+  }).outPath;
+
+  src = fetchgit ( removeAttrs (builtins.fromJSON ''{
+  "url": "git://github.com/JorjBauer/lua-cyrussasl",
+  "rev": "78ceec610da76d745d0eff4e21a4fb24832aa72d",
+  "date": "2015-08-21T18:24:54-04:00",
+  "sha256": "14kzm3vk96k2i1m9f5zvpvq4pnzaf7s91h5g4h4x2bq1mynzw2s1",
+  "fetchSubmodules": true
+}
+ '') ["date"]) ;
+
+  disabled = (luaOlder "5.1");
+  propagatedBuildInputs = [ lua ];
+
+  meta = with stdenv.lib; {
+    homepage = "http://github.com/JorjBauer/lua-cyrussasl";
+    description = "Cyrus SASL library for Lua 5.1+";
+    maintainers = with maintainers; [ vcunat ];
+    license = {
+      fullName = "BSD";
+    };
+  };
+};
 digestif = buildLuarocksPackage {
   pname = "digestif";
   version = "scm-1";
@@ -103,9 +255,9 @@ digestif = buildLuarocksPackage {
 
   src = fetchgit ( removeAttrs (builtins.fromJSON ''{
   "url": "git://github.com/astoff/digestif",
-  "rev": "19442554ae18607707f09e6663d65bb8bb4ebb58",
-  "date": "2019-06-01T15:41:36+02:00",
-  "sha256": "1sglkgx2s1xc725h9b97jhfbi3scs32si83xss5m3n0xidwmlbzb",
+  "rev": "51c321f1b68b77f648fa6adf356de48925f69fe0",
+  "date": "2019-06-08T15:03:33+02:00",
+  "sha256": "1c9cl81vfzirc325wipdy992yn20b8xv8nqzl5mdhyz8zfp84hs7",
   "fetchSubmodules": true
 }
  '') ["date"]) ;
@@ -113,7 +265,7 @@ digestif = buildLuarocksPackage {
   disabled = (luaOlder "5.3");
   propagatedBuildInputs = [ lua lpeg dkjson ];
 
-  meta = {
+  meta = with stdenv.lib; {
     homepage = "https://github.com/astoff/digestif/";
     description = "Code analyzer for TeX.";
     license = {
@@ -132,7 +284,7 @@ dkjson = buildLuarocksPackage {
   disabled = (luaOlder "5.1") || (luaAtLeast "5.4");
   propagatedBuildInputs = [ lua ];
 
-  meta = {
+  meta = with stdenv.lib; {
     homepage = "http://dkolf.de/src/dkjson-lua.fsl/";
     description = "David Kolf's JSON module for Lua";
     license = {
@@ -150,7 +302,7 @@ fifo = buildLuarocksPackage {
   };
   propagatedBuildInputs = [ lua ];
 
-  meta = {
+  meta = with stdenv.lib; {
     homepage = "https://github.com/daurnimator/fifo.lua";
     description = "A lua library/'class' that implements a FIFO";
     license = {
@@ -169,9 +321,10 @@ http = buildLuarocksPackage {
   disabled = (luaOlder "5.1");
   propagatedBuildInputs = [ lua compat53 bit32 cqueues luaossl basexx lpeg lpeg_patterns binaryheap fifo ];
 
-  meta = {
+  meta = with stdenv.lib; {
     homepage = "https://github.com/daurnimator/lua-http";
     description = "HTTP library for Lua";
+    maintainers = with maintainers; [ vcunat ];
     license = {
       fullName = "MIT";
     };
@@ -188,7 +341,7 @@ inspect = buildLuarocksPackage {
   disabled = (luaOlder "5.1");
   propagatedBuildInputs = [ lua ];
 
-  meta = {
+  meta = with stdenv.lib; {
     homepage = "https://github.com/kikito/inspect.lua";
     description = "Lua table visualizer, ideal for debugging";
     license = {
@@ -212,7 +365,7 @@ ldoc = buildLuarocksPackage {
 
   propagatedBuildInputs = [ penlight markdown ];
 
-  meta = {
+  meta = with stdenv.lib; {
     homepage = "http://stevedonovan.github.com/ldoc";
     description = "A Lua Documentation Tool";
     license = {
@@ -231,7 +384,7 @@ lgi = buildLuarocksPackage {
   disabled = (luaOlder "5.1");
   propagatedBuildInputs = [ lua ];
 
-  meta = {
+  meta = with stdenv.lib; {
     homepage = "http://github.com/pavouk/lgi";
     description = "Lua bindings to GObject libraries";
     license = {
@@ -250,9 +403,10 @@ lpeg = buildLuarocksPackage {
   disabled = (luaOlder "5.1");
   propagatedBuildInputs = [ lua ];
 
-  meta = {
+  meta = with stdenv.lib; {
     homepage = "http://www.inf.puc-rio.br/~roberto/lpeg.html";
     description = "Parsing Expression Grammars For Lua";
+    maintainers = with maintainers; [ vyp ];
     license = {
       fullName = "MIT/X11";
     };
@@ -268,7 +422,7 @@ lpeg_patterns = buildLuarocksPackage {
   };
   propagatedBuildInputs = [ lua lpeg ];
 
-  meta = {
+  meta = with stdenv.lib; {
     homepage = "https://github.com/daurnimator/lpeg_patterns/archive/v0.5.zip";
     description = "a collection of LPEG patterns";
     license = {
@@ -281,13 +435,13 @@ lpeglabel = buildLuarocksPackage {
   version = "1.5.0-1";
 
   src = fetchurl {
-    url    = https://luarocks.org/lpeglabel-1.5.0-1.src.rock;
+    url    = https://raw.githubusercontent.com/rocks-moonscript-org/moonrocks-mirror/master/lpeglabel-1.5.0-1.src.rock;
     sha256 = "068mwvwwn5n69pdm04qnk354391w9mk34jsczxql0xi5qgmz6w8j";
   };
   disabled = (luaOlder "5.1");
   propagatedBuildInputs = [ lua ];
 
-  meta = {
+  meta = with stdenv.lib; {
     homepage = "https://github.com/sqmedeiros/lpeglabel/";
     description = "Parsing Expression Grammars For Lua with Labeled Failures";
     license = {
@@ -300,13 +454,13 @@ lpty = buildLuarocksPackage {
   version = "1.2.2-1";
 
   src = fetchurl {
-    url    = https://luarocks.org/lpty-1.2.2-1.src.rock;
+    url    = https://raw.githubusercontent.com/rocks-moonscript-org/moonrocks-mirror/master/lpty-1.2.2-1.src.rock;
     sha256 = "1vxvsjgjfirl6ranz6k4q4y2dnxqh72bndbk400if22x8lqbkxzm";
   };
   disabled = (luaOlder "5.1");
   propagatedBuildInputs = [ lua ];
 
-  meta = {
+  meta = with stdenv.lib; {
     homepage = "http://www.tset.de/lpty/";
     description = "A simple facility for lua to control other programs via PTYs.";
     license = {
@@ -319,13 +473,13 @@ lrexlib-gnu = buildLuarocksPackage {
   version = "2.9.0-1";
 
   src = fetchurl {
-    url    = https://luarocks.org/lrexlib-gnu-2.9.0-1.src.rock;
+    url    = https://raw.githubusercontent.com/rocks-moonscript-org/moonrocks-mirror/master/lrexlib-gnu-2.9.0-1.src.rock;
     sha256 = "036rda4rji1pbnbxk1nzjy5zmigdsiacqbzrbvciwq3lrxa2j5s2";
   };
   disabled = (luaOlder "5.1");
   propagatedBuildInputs = [ lua ];
 
-  meta = {
+  meta = with stdenv.lib; {
     homepage = "http://github.com/rrthomas/lrexlib";
     description = "Regular expression library binding (GNU flavour).";
     license = {
@@ -333,18 +487,38 @@ lrexlib-gnu = buildLuarocksPackage {
     };
   };
 };
+lrexlib-pcre = buildLuarocksPackage {
+  pname = "lrexlib-pcre";
+  version = "2.9.0-1";
+
+  src = fetchurl {
+    url    = https://raw.githubusercontent.com/rocks-moonscript-org/moonrocks-mirror/master/lrexlib-pcre-2.9.0-1.src.rock;
+    sha256 = "1nqai27lbd85mcjf5cb05dbdfg460vmp8cr0lmb8dd63ivk8cbvx";
+  };
+  disabled = (luaOlder "5.1");
+  propagatedBuildInputs = [ lua ];
+
+  meta = with stdenv.lib; {
+    homepage = "http://github.com/rrthomas/lrexlib";
+    description = "Regular expression library binding (PCRE flavour).";
+    maintainers = with maintainers; [ vyp ];
+    license = {
+      fullName = "MIT/X11";
+    };
+  };
+};
 lrexlib-posix = buildLuarocksPackage {
   pname = "lrexlib-posix";
   version = "2.9.0-1";
 
   src = fetchurl {
-    url    = https://luarocks.org/lrexlib-posix-2.9.0-1.src.rock;
+    url    = https://raw.githubusercontent.com/rocks-moonscript-org/moonrocks-mirror/master/lrexlib-posix-2.9.0-1.src.rock;
     sha256 = "0ifpybf4m94g1nk70l0f5m45gph0rbp5wrxrl1hnw8ibv3mc1b1r";
   };
   disabled = (luaOlder "5.1");
   propagatedBuildInputs = [ lua ];
 
-  meta = {
+  meta = with stdenv.lib; {
     homepage = "http://github.com/rrthomas/lrexlib";
     description = "Regular expression library binding (POSIX flavour).";
     license = {
@@ -357,13 +531,13 @@ ltermbox = buildLuarocksPackage {
   version = "0.2-1";
 
   src = fetchurl {
-    url    = https://luarocks.org/ltermbox-0.2-1.src.rock;
+    url    = https://raw.githubusercontent.com/rocks-moonscript-org/moonrocks-mirror/master/ltermbox-0.2-1.src.rock;
     sha256 = "08jqlmmskbi1ml1i34dlmg6hxcs60nlm32dahpxhcrgjnfihmyn8";
   };
   disabled = (luaOlder "5.1");
   propagatedBuildInputs = [ lua ];
 
-  meta = {
+  meta = with stdenv.lib; {
     homepage = "http://code.google.com/p/termbox";
     description = "A termbox library package";
     license = {
@@ -371,25 +545,6 @@ ltermbox = buildLuarocksPackage {
     };
   };
 };
-cjson = buildLuarocksPackage {
-  pname = "lua-cjson";
-  version = "2.1.0.6-1";
-
-  src = fetchurl {
-    url    = https://luarocks.org/lua-cjson-2.1.0.6-1.src.rock;
-    sha256 = "0dqqkn0aygc780kiq2lbydb255r8is7raf7md0gxdjcagp8afps5";
-  };
-  disabled = (luaOlder "5.1");
-  propagatedBuildInputs = [ lua ];
-
-  meta = {
-    homepage = "http://www.kyne.com.au/~mark/software/lua-cjson.php";
-    description = "A fast JSON encoding/parsing module";
-    license = {
-      fullName = "MIT";
-    };
-  };
-};
 lua-cmsgpack = buildLuarocksPackage {
   pname = "lua-cmsgpack";
   version = "0.4.0-0";
@@ -411,7 +566,7 @@ lua-cmsgpack = buildLuarocksPackage {
   disabled = (luaOlder "5.1");
   propagatedBuildInputs = [ lua ];
 
-  meta = {
+  meta = with stdenv.lib; {
     homepage = "http://github.com/antirez/lua-cmsgpack";
     description = "MessagePack C implementation and bindings for Lua 5.1/5.2/5.3";
     license = {
@@ -419,25 +574,6 @@ lua-cmsgpack = buildLuarocksPackage {
     };
   };
 };
-lua_cliargs = buildLuarocksPackage {
-  pname = "lua_cliargs";
-  version = "3.0-2";
-
-  src = fetchurl {
-    url    = https://luarocks.org/lua_cliargs-3.0-2.src.rock;
-    sha256 = "0qqdnw00r16xbyqn4w1xwwpg9i9ppc3c1dcypazjvdxaj899hy9w";
-  };
-  disabled = (luaOlder "5.1");
-  propagatedBuildInputs = [ lua ];
-
-  meta = {
-    homepage = "https://github.com/amireh/lua_cliargs";
-    description = "A command-line argument parser.";
-    license = {
-      fullName = "MIT <http://opensource.org/licenses/MIT>";
-    };
-  };
-};
 lua-iconv = buildLuarocksPackage {
   pname = "lua-iconv";
   version = "7-3";
@@ -449,7 +585,7 @@ lua-iconv = buildLuarocksPackage {
   disabled = (luaOlder "5.1");
   propagatedBuildInputs = [ lua ];
 
-  meta = {
+  meta = with stdenv.lib; {
     homepage = "http://ittner.github.com/lua-iconv/";
     description = "Lua binding to the iconv";
     license = {
@@ -478,7 +614,7 @@ lua-lsp = buildLuarocksPackage {
   disabled = (luaOlder "5.1") || (luaAtLeast "5.4");
   propagatedBuildInputs = [ lua dkjson lpeglabel inspect ];
 
-  meta = {
+  meta = with stdenv.lib; {
     homepage = "https://github.com/Alloyed/lua-lsp";
     description = "No summary";
     license = {
@@ -497,7 +633,7 @@ lua-messagepack = buildLuarocksPackage {
   disabled = (luaOlder "5.1");
   propagatedBuildInputs = [ lua ];
 
-  meta = {
+  meta = with stdenv.lib; {
     homepage = "http://fperrad.frama.io/lua-MessagePack/";
     description = "a pure Lua implementation of the MessagePack serialization format";
     license = {
@@ -520,7 +656,7 @@ lua-term = buildLuarocksPackage {
   };
 
 
-  meta = {
+  meta = with stdenv.lib; {
     homepage = "https://github.com/hoelzro/lua-term";
     description = "Terminal functions for Lua";
     license = {
@@ -539,7 +675,7 @@ lua-toml = buildLuarocksPackage {
   disabled = (luaOlder "5.1");
   propagatedBuildInputs = [ lua ];
 
-  meta = {
+  meta = with stdenv.lib; {
     homepage = "https://github.com/jonstoler/lua-toml";
     description = "toml decoder/encoder for Lua";
     license = {
@@ -552,26 +688,46 @@ lua-zlib = buildLuarocksPackage {
   version = "1.2-0";
 
   src = fetchurl {
-    url    = https://luarocks.org/lua-zlib-1.2-0.src.rock;
+    url    = https://raw.githubusercontent.com/rocks-moonscript-org/moonrocks-mirror/master/lua-zlib-1.2-0.src.rock;
     sha256 = "0qa0vnx45nxdj6fqag6fr627zsnd2bmrr9bdbm8jv6lcnyi6nhs2";
   };
   disabled = (luaOlder "5.1");
   propagatedBuildInputs = [ lua ];
 
-  meta = {
+  meta = with stdenv.lib; {
     homepage = "https://github.com/brimworks/lua-zlib";
     description = "Simple streaming interface to zlib for Lua.";
+    maintainers = with maintainers; [ koral ];
     license = {
       fullName = "MIT";
     };
   };
 };
+lua_cliargs = buildLuarocksPackage {
+  pname = "lua_cliargs";
+  version = "3.0-2";
+
+  src = fetchurl {
+    url    = https://raw.githubusercontent.com/rocks-moonscript-org/moonrocks-mirror/master/lua_cliargs-3.0-2.src.rock;
+    sha256 = "0qqdnw00r16xbyqn4w1xwwpg9i9ppc3c1dcypazjvdxaj899hy9w";
+  };
+  disabled = (luaOlder "5.1");
+  propagatedBuildInputs = [ lua ];
+
+  meta = with stdenv.lib; {
+    homepage = "https://github.com/amireh/lua_cliargs";
+    description = "A command-line argument parser.";
+    license = {
+      fullName = "MIT <http://opensource.org/licenses/MIT>";
+    };
+  };
+};
 luabitop = buildLuarocksPackage {
   pname = "luabitop";
   version = "1.0.2-3";
 
   knownRockspec = (fetchurl {
-    url    = https://luarocks.org/luabitop-1.0.2-3.rockspec;
+    url    = https://raw.githubusercontent.com/rocks-moonscript-org/moonrocks-mirror/master/luabitop-1.0.2-3.rockspec;
     sha256 = "07y2h11hbxmby7kyhy3mda64w83p4a6p7y7rzrjqgc0r56yjxhcc";
   }).outPath;
 
@@ -587,7 +743,7 @@ luabitop = buildLuarocksPackage {
   disabled = (luaOlder "5.1") || (luaAtLeast "5.3");
   propagatedBuildInputs = [ lua ];
 
-  meta = {
+  meta = with stdenv.lib; {
     homepage = "http://bitop.luajit.org/";
     description = "Lua Bit Operations Module";
     license = {
@@ -595,6 +751,101 @@ luabitop = buildLuarocksPackage {
     };
   };
 };
+luacheck = buildLuarocksPackage {
+  pname = "luacheck";
+  version = "0.23.0-1";
+
+  src = fetchurl {
+    url    = https://luarocks.org/luacheck-0.23.0-1.src.rock;
+    sha256 = "0akj61c7k1na2mggsckvfn9a3ljfp4agnmr9gp3mac4vin99a1cl";
+  };
+  disabled = (luaOlder "5.1") || (luaAtLeast "5.4");
+  propagatedBuildInputs = [ lua argparse luafilesystem ];
+
+  meta = with stdenv.lib; {
+    homepage = "https://github.com/mpeterv/luacheck";
+    description = "A static analyzer and a linter for Lua";
+    license = {
+      fullName = "MIT";
+    };
+  };
+};
+luadbi = buildLuarocksPackage {
+  pname = "luadbi";
+  version = "0.7.2-1";
+
+  src = fetchurl {
+    url    = https://luarocks.org/luadbi-0.7.2-1.src.rock;
+    sha256 = "0mj9ggyb05l03gs38ds508620mqaw4fkrzz9861n4j0zxbsbmfwy";
+  };
+  disabled = (luaOlder "5.1") || (luaAtLeast "5.4");
+  propagatedBuildInputs = [ lua ];
+
+  meta = with stdenv.lib; {
+    homepage = "https://github.com/mwild1/luadbi";
+    description = "Database abstraction layer";
+    license = {
+      fullName = "MIT/X11";
+    };
+  };
+};
+luadbi-mysql = buildLuarocksPackage {
+  pname = "luadbi-mysql";
+  version = "0.7.2-1";
+
+  src = fetchurl {
+    url    = https://luarocks.org/luadbi-mysql-0.7.2-1.src.rock;
+    sha256 = "1f8i5p66halws8qsa7g09110hwzg7pv29yi22mkqd8sjgjv42iq4";
+  };
+  disabled = (luaOlder "5.1") || (luaAtLeast "5.4");
+  propagatedBuildInputs = [ lua luadbi ];
+
+  meta = with stdenv.lib; {
+    homepage = "https://github.com/mwild1/luadbi";
+    description = "Database abstraction layer";
+    license = {
+      fullName = "MIT/X11";
+    };
+  };
+};
+luadbi-postgresql = buildLuarocksPackage {
+  pname = "luadbi-postgresql";
+  version = "0.7.2-1";
+
+  src = fetchurl {
+    url    = https://luarocks.org/luadbi-postgresql-0.7.2-1.src.rock;
+    sha256 = "0nmm1hdzl77wk8p6r6al6mpkh2n332a8r3iqsdi6v4nxamykdh28";
+  };
+  disabled = (luaOlder "5.1") || (luaAtLeast "5.4");
+  propagatedBuildInputs = [ lua luadbi ];
+
+  meta = with stdenv.lib; {
+    homepage = "https://github.com/mwild1/luadbi";
+    description = "Database abstraction layer";
+    license = {
+      fullName = "MIT/X11";
+    };
+  };
+};
+luadbi-sqlite3 = buildLuarocksPackage {
+  pname = "luadbi-sqlite3";
+  version = "0.7.2-1";
+
+  src = fetchurl {
+    url    = https://luarocks.org/luadbi-sqlite3-0.7.2-1.src.rock;
+    sha256 = "17wd2djzk5x4l4pv2k3c7b8dcvl46s96kqyk8dp3q6ll8gdl7c65";
+  };
+  disabled = (luaOlder "5.1") || (luaAtLeast "5.4");
+  propagatedBuildInputs = [ lua luadbi ];
+
+  meta = with stdenv.lib; {
+    homepage = "https://github.com/mwild1/luadbi";
+    description = "Database abstraction layer";
+    license = {
+      fullName = "MIT/X11";
+    };
+  };
+};
 luaevent = buildLuarocksPackage {
   pname = "luaevent";
   version = "0.4.6-1";
@@ -606,7 +857,7 @@ luaevent = buildLuarocksPackage {
   disabled = (luaOlder "5.1");
   propagatedBuildInputs = [ lua ];
 
-  meta = {
+  meta = with stdenv.lib; {
     homepage = "https://github.com/harningt/luaevent";
     description = "libevent binding for Lua";
     license = {
@@ -614,22 +865,23 @@ luaevent = buildLuarocksPackage {
     };
   };
 };
-luacheck = buildLuarocksPackage {
-  pname = "luacheck";
-  version = "0.23.0-1";
+luaexpat = buildLuarocksPackage {
+  pname = "luaexpat";
+  version = "1.3.3-1";
 
   src = fetchurl {
-    url    = https://luarocks.org/luacheck-0.23.0-1.src.rock;
-    sha256 = "0akj61c7k1na2mggsckvfn9a3ljfp4agnmr9gp3mac4vin99a1cl";
+    url    = https://luarocks.org/luaexpat-1.3.3-1.src.rock;
+    sha256 = "0ahpfnby9qqgj22bajmrqvqq70nx19388lmjm9chljfzszy0hndm";
   };
-  disabled = (luaOlder "5.1") || (luaAtLeast "5.4");
-  propagatedBuildInputs = [ lua argparse luafilesystem ];
+  disabled = (luaOlder "5.0");
+  propagatedBuildInputs = [ lua ];
 
-  meta = {
-    homepage = "https://github.com/mpeterv/luacheck";
-    description = "A static analyzer and a linter for Lua";
+  meta = with stdenv.lib; {
+    homepage = "http://www.keplerproject.org/luaexpat/";
+    description = "XML Expat parsing";
+    maintainers = with maintainers; [ flosse ];
     license = {
-      fullName = "MIT";
+      fullName = "MIT/X11";
     };
   };
 };
@@ -644,7 +896,7 @@ luaffi = buildLuarocksPackage {
   disabled = (luaOlder "5.1");
   propagatedBuildInputs = [ lua ];
 
-  meta = {
+  meta = with stdenv.lib; {
     homepage = "https://github.com/facebook/luaffifb";
     description = "FFI library for calling C functions from lua";
     license = {
@@ -652,200 +904,218 @@ luaffi = buildLuarocksPackage {
     };
   };
 };
+luafilesystem = buildLuarocksPackage {
+  pname = "luafilesystem";
+  version = "1.7.0-2";
+
+  src = fetchurl {
+    url    = https://raw.githubusercontent.com/rocks-moonscript-org/moonrocks-mirror/master/luafilesystem-1.7.0-2.src.rock;
+    sha256 = "0xhmd08zklsgpnpjr9rjipah35fbs8jd4v4va36xd8bpwlvx9rk5";
+  };
+  disabled = (luaOlder "5.1");
+  propagatedBuildInputs = [ lua ];
+
+  meta = with stdenv.lib; {
+    homepage = "git://github.com/keplerproject/luafilesystem";
+    description = "File System Library for the Lua Programming Language";
+    maintainers = with maintainers; [ flosse vcunat ];
+    license = {
+      fullName = "MIT/X11";
+    };
+  };
+};
+luaossl = buildLuarocksPackage {
+  pname = "luaossl";
+  version = "20190612-0";
+
+  src = fetchurl {
+    url    = https://luarocks.org/luaossl-20190612-0.src.rock;
+    sha256 = "0q47rsfjnx3rbbr9jl2j5nlj56c6mwmnnma9m4rrbsza2p98wb4s";
+  };
+  propagatedBuildInputs = [ lua ];
+
+  meta = with stdenv.lib; {
+    homepage = "http://25thandclement.com/~william/projects/luaossl.html";
+    description = "Most comprehensive OpenSSL module in the Lua universe.";
+    maintainers = with maintainers; [ vcunat ];
+    license = {
+      fullName = "MIT/X11";
+    };
+  };
+};
 luaposix = buildLuarocksPackage {
   pname = "luaposix";
   version = "34.0.4-1";
 
   src = fetchurl {
-    url    = https://luarocks.org/luaposix-34.0.4-1.src.rock;
+    url    = https://raw.githubusercontent.com/rocks-moonscript-org/moonrocks-mirror/master/luaposix-34.0.4-1.src.rock;
     sha256 = "0yrm5cn2iyd0zjd4liyj27srphvy0gjrjx572swar6zqr4dwjqp2";
   };
   disabled = (luaOlder "5.1") || (luaAtLeast "5.4");
   propagatedBuildInputs = [ bit32 lua std_normalize ];
 
-  meta = {
+  meta = with stdenv.lib; {
     homepage = "http://github.com/luaposix/luaposix/";
     description = "Lua bindings for POSIX";
+    maintainers = with maintainers; [ vyp lblasc ];
     license = {
       fullName = "MIT/X11";
     };
   };
 };
-luazip = buildLuarocksPackage {
-  pname = "luazip";
-  version = "1.2.7-1";
+luasec = buildLuarocksPackage {
+  pname = "luasec";
+  version = "0.8-1";
 
   src = fetchurl {
-    url    = https://luarocks.org/luazip-1.2.7-1.src.rock;
-    sha256 = "1yprlr1ap6bhshhy88qfphmmyg9zp1py2hj2158iw6vsva0fk03l";
+    url    = https://raw.githubusercontent.com/rocks-moonscript-org/moonrocks-mirror/master/luasec-0.8-1.src.rock;
+    sha256 = "063rgz0zdmaizirsm6jbcfijgkpdcrb8a2fvhvg3y2s8ixbaff13";
   };
-  disabled = (luaOlder "5.1") || (luaAtLeast "5.4");
-  propagatedBuildInputs = [ lua ];
+  disabled = (luaOlder "5.1");
+  propagatedBuildInputs = [ lua luasocket ];
 
-  meta = {
-    homepage = "https://github.com/mpeterv/luazip";
-    description = "Library for reading files inside zip files";
+  meta = with stdenv.lib; {
+    homepage = "https://github.com/brunoos/luasec/wiki";
+    description = "A binding for OpenSSL library to provide TLS/SSL communication over LuaSocket.";
+    maintainers = with maintainers; [ flosse ];
     license = {
       fullName = "MIT";
     };
   };
 };
-luuid = buildLuarocksPackage {
-  pname = "luuid";
-  version = "20120509-2";
+luasocket = buildLuarocksPackage {
+  pname = "luasocket";
+  version = "3.0rc1-2";
 
   src = fetchurl {
-    url    = https://luarocks.org/luuid-20120509-2.src.rock;
-    sha256 = "08q54x0m51w89np3n117h2a153wsgv3qayabd8cz6i55qm544hkg";
+    url    = https://raw.githubusercontent.com/rocks-moonscript-org/moonrocks-mirror/master/luasocket-3.0rc1-2.src.rock;
+    sha256 = "1isin9m40ixpqng6ds47skwa4zxrc6w8blza8gmmq566w6hz50iq";
   };
-  disabled = (luaOlder "5.2") || (luaAtLeast "5.4");
+  disabled = (luaOlder "5.1");
   propagatedBuildInputs = [ lua ];
 
-  meta = {
-    homepage = "http://www.tecgraf.puc-rio.br/~lhf/ftp/lua/#luuid";
-    description = "A library for UUID generation";
+  meta = with stdenv.lib; {
+    homepage = "http://luaforge.net/projects/luasocket/";
+    description = "Network support for the Lua language";
     license = {
-      fullName = "Public domain";
+      fullName = "MIT";
     };
   };
 };
-markdown = buildLuarocksPackage {
-  pname = "markdown";
-  version = "0.33-1";
+luasql-sqlite3 = buildLuarocksPackage {
+  pname = "luasql-sqlite3";
+  version = "2.4.0-1";
 
   src = fetchurl {
-    url    = https://luarocks.org/markdown-0.33-1.src.rock;
-    sha256 = "01xw4b4jvmrv1hz2gya02g3nphsj3hc94hsbc672ycj8pcql5n5y";
+    url    = https://luarocks.org/luasql-sqlite3-2.4.0-1.src.rock;
+    sha256 = "0pdk8c9iw0625imf5wdrhq60484jn475b85rvp0xgh86bsyalbsh";
   };
-  disabled = (luaOlder "5.1") || (luaAtLeast "5.4");
+  disabled = (luaOlder "5.1");
   propagatedBuildInputs = [ lua ];
 
-  meta = {
-    homepage = "https://github.com/mpeterv/markdown";
-    description = "Markdown text-to-html markup system.";
+  meta = with stdenv.lib; {
+    homepage = "http://www.keplerproject.org/luasql/";
+    description = "Database connectivity for Lua (SQLite3 driver)";
+    maintainers = with maintainers; [ vyp ];
     license = {
       fullName = "MIT/X11";
     };
   };
 };
-penlight = buildLuarocksPackage {
-  pname = "penlight";
-  version = "1.5.4-1";
+luassert = buildLuarocksPackage {
+  pname = "luassert";
+  version = "1.7.11-0";
 
   knownRockspec = (fetchurl {
-    url    = https://luarocks.org/penlight-1.5.4-1.rockspec;
-    sha256 = "07mhsk9kmdxg4i2w4mrnnd2zs34bgggi9gigfplakxin96sa6c0p";
+    url    = https://luarocks.org/luassert-1.7.11-0.rockspec;
+    sha256 = "12zgybcv8acjzvjdbxd1764s1vxbksxdv9fkvsymcsdmppxkbd0s";
   }).outPath;
 
   src = fetchurl {
-    url    = http://stevedonovan.github.io/files/penlight-1.5.4.zip;
-    sha256 = "138f921p6kdqkmf4pz115phhj0jsqf28g33avws80d2vq2ixqm8q";
-  };
-
-  propagatedBuildInputs = [ luafilesystem ];
-
-  meta = {
-    homepage = "http://stevedonovan.github.com/Penlight";
-    description = "Lua utility libraries loosely based on the Python standard libraries";
-    license = {
-      fullName = "MIT/X11";
-    };
+    url    = https://github.com/Olivine-Labs/luassert/archive/v1.7.11.tar.gz;
+    sha256 = "1vwq3wqj9cjyz9lnf1n38yhpcglr2h40v3n9096i8vcpmyvdb3ka";
   };
-};
-rapidjson = buildLuarocksPackage {
-  pname = "rapidjson";
-  version = "0.5.1-1";
 
-  src = fetchurl {
-    url    = https://luarocks.org/rapidjson-0.5.1-1.src.rock;
-    sha256 = "0hnqsixnbz95cvm9q5dn0lr0qjvhqw4llw6l1sjswwk0am4yybay";
-  };
   disabled = (luaOlder "5.1");
-  propagatedBuildInputs = [ lua ];
+  propagatedBuildInputs = [ lua say ];
 
-  meta = {
-    homepage = "https://github.com/xpol/lua-rapidjson";
-    description = "Json module based on the very fast RapidJSON.";
+  meta = with stdenv.lib; {
+    homepage = "http://olivinelabs.com/busted/";
+    description = "Lua Assertions Extension";
     license = {
-      fullName = "MIT";
+      fullName = "MIT <http://opensource.org/licenses/MIT>";
     };
   };
 };
-say = buildLuarocksPackage {
-  pname = "say";
-  version = "1.3-1";
-
-  knownRockspec = (fetchurl {
-    url    = https://luarocks.org/say-1.3-1.rockspec;
-    sha256 = "0bknglb0qwd6r703wp3hcb6z2xxd14kq4md3sg9al3b28fzxbhdv";
-  }).outPath;
+luasystem = buildLuarocksPackage {
+  pname = "luasystem";
+  version = "0.2.1-0";
 
   src = fetchurl {
-    url    = https://github.com/Olivine-Labs/say/archive/v1.3-1.tar.gz;
-    sha256 = "1jh76mxq9dcmv7kps2spwcc6895jmj2sf04i4y9idaxlicvwvs13";
+    url    = https://luarocks.org/luasystem-0.2.1-0.src.rock;
+    sha256 = "091xmp8cijgj0yzfsjrn7vljwznjnjn278ay7z9pjwpwiva0diyi";
   };
-
   disabled = (luaOlder "5.1");
   propagatedBuildInputs = [ lua ];
 
-  meta = {
-    homepage = "http://olivinelabs.com/busted/";
-    description = "Lua String Hashing/Indexing Library";
+  meta = with stdenv.lib; {
+    homepage = "http://olivinelabs.com/luasystem/";
+    description = "Platform independent system calls for Lua.";
     license = {
       fullName = "MIT <http://opensource.org/licenses/MIT>";
     };
   };
 };
-std__debug = buildLuarocksPackage {
-  pname = "std._debug";
-  version = "1.0.1-1";
+luazip = buildLuarocksPackage {
+  pname = "luazip";
+  version = "1.2.7-1";
 
   src = fetchurl {
-    url    = https://luarocks.org/std._debug-1.0.1-1.src.rock;
-    sha256 = "1qkcc5rph3ns9mzrfsa1671pb3hzbzfnaxvyw7zdly2b7ll88svz";
+    url    = https://luarocks.org/luazip-1.2.7-1.src.rock;
+    sha256 = "1yprlr1ap6bhshhy88qfphmmyg9zp1py2hj2158iw6vsva0fk03l";
   };
-  disabled = (luaOlder "5.1") || (luaAtLeast "5.5");
+  disabled = (luaOlder "5.1") || (luaAtLeast "5.4");
   propagatedBuildInputs = [ lua ];
 
-  meta = {
-    homepage = "http://lua-stdlib.github.io/_debug";
-    description = "Debug Hints Library";
+  meta = with stdenv.lib; {
+    homepage = "https://github.com/mpeterv/luazip";
+    description = "Library for reading files inside zip files";
     license = {
-      fullName = "MIT/X11";
+      fullName = "MIT";
     };
   };
 };
-std_normalize = buildLuarocksPackage {
-  pname = "std.normalize";
-  version = "2.0.2-1";
+luuid = buildLuarocksPackage {
+  pname = "luuid";
+  version = "20120509-2";
 
   src = fetchurl {
-    url    = https://luarocks.org/std.normalize-2.0.2-1.src.rock;
-    sha256 = "0yn60zqnxflhhlv6xk6w0ifdfxk1qcg8gq1wnrrbwsxwpipsrfjh";
+    url    = https://luarocks.org/luuid-20120509-2.src.rock;
+    sha256 = "08q54x0m51w89np3n117h2a153wsgv3qayabd8cz6i55qm544hkg";
   };
-  disabled = (luaOlder "5.1") || (luaAtLeast "5.4");
-  propagatedBuildInputs = [ lua std__debug ];
+  disabled = (luaOlder "5.2") || (luaAtLeast "5.4");
+  propagatedBuildInputs = [ lua ];
 
-  meta = {
-    homepage = "https://lua-stdlib.github.io/normalize";
-    description = "Normalized Lua Functions";
+  meta = with stdenv.lib; {
+    homepage = "http://www.tecgraf.puc-rio.br/~lhf/ftp/lua/#luuid";
+    description = "A library for UUID generation";
     license = {
-      fullName = "MIT/X11";
+      fullName = "Public domain";
     };
   };
 };
 luv = buildLuarocksPackage {
   pname = "luv";
-  version = "1.29.1-1";
+  version = "1.29.1-2";
 
   src = fetchurl {
-    url    = https://luarocks.org/luv-1.29.1-1.src.rock;
-    sha256 = "0x801pp8h2035lbncsb6vkwgxqrai69ri3sp9g1dwnfnipsfsvrg";
+    url    = https://luarocks.org/luv-1.29.1-2.src.rock;
+    sha256 = "180g06lkhapb76nhlgsa8ik8z6mrlkvq9mpb8rx74lr101h1yqxg";
   };
   disabled = (luaOlder "5.1");
   propagatedBuildInputs = [ lua ];
 
-  meta = {
+  meta = with stdenv.lib; {
     homepage = "https://github.com/luvit/luv";
     description = "Bare libuv bindings for lua";
     license = {
@@ -853,22 +1123,22 @@ luv = buildLuarocksPackage {
     };
   };
 };
-luasystem = buildLuarocksPackage {
-  pname = "luasystem";
-  version = "0.2.1-0";
+markdown = buildLuarocksPackage {
+  pname = "markdown";
+  version = "0.33-1";
 
   src = fetchurl {
-    url    = https://luarocks.org/luasystem-0.2.1-0.src.rock;
-    sha256 = "091xmp8cijgj0yzfsjrn7vljwznjnjn278ay7z9pjwpwiva0diyi";
+    url    = https://luarocks.org/markdown-0.33-1.src.rock;
+    sha256 = "01xw4b4jvmrv1hz2gya02g3nphsj3hc94hsbc672ycj8pcql5n5y";
   };
-  disabled = (luaOlder "5.1");
+  disabled = (luaOlder "5.1") || (luaAtLeast "5.4");
   propagatedBuildInputs = [ lua ];
 
-  meta = {
-    homepage = "http://olivinelabs.com/luasystem/";
-    description = "Platform independent system calls for Lua.";
+  meta = with stdenv.lib; {
+    homepage = "https://github.com/mpeterv/markdown";
+    description = "Markdown text-to-html markup system.";
     license = {
-      fullName = "MIT <http://opensource.org/licenses/MIT>";
+      fullName = "MIT/X11";
     };
   };
 };
@@ -876,14 +1146,20 @@ mediator_lua = buildLuarocksPackage {
   pname = "mediator_lua";
   version = "1.1.2-0";
 
+  knownRockspec = (fetchurl {
+    url    = https://luarocks.org/mediator_lua-1.1.2-0.rockspec;
+    sha256 = "0frzvf7i256260a1s8xh92crwa2m42972qxfq29zl05aw3pyn7bm";
+  }).outPath;
+
   src = fetchurl {
-    url    = http://luarocks.org/manifests/teto/mediator_lua-1.1.2-0.src.rock;
-    sha256 = "18j49vvs94yfk4fw0xsq4v3j4difr6c99gfba0kxairmcqamd1if";
+    url    = https://github.com/Olivine-Labs/mediator_lua/archive/v1.1.2-0.tar.gz;
+    sha256 = "16zzzhiy3y35v8advmlkzpryzxv5vji7727vwkly86q8sagqbxgs";
   };
+
   disabled = (luaOlder "5.1");
   propagatedBuildInputs = [ lua ];
 
-  meta = {
+  meta = with stdenv.lib; {
     homepage = "http://olivinelabs.com/mediator_lua/";
     description = "Event handling through channels";
     license = {
@@ -906,7 +1182,7 @@ mpack = buildLuarocksPackage {
   };
 
 
-  meta = {
+  meta = with stdenv.lib; {
     homepage = "https://github.com/libmpack/libmpack-lua/releases/download/1.0.7/libmpack-lua-1.0.7.tar.gz";
     description = "Lua binding to libmpack";
     license = {
@@ -925,7 +1201,7 @@ nvim-client = buildLuarocksPackage {
   disabled = (luaOlder "5.1");
   propagatedBuildInputs = [ lua mpack luv coxpcall ];
 
-  meta = {
+  meta = with stdenv.lib; {
     homepage = "https://github.com/neovim/lua-client/archive/0.2.0-1.tar.gz";
     description = "Lua client to Nvim";
     license = {
@@ -933,62 +1209,127 @@ nvim-client = buildLuarocksPackage {
     };
   };
 };
-busted = buildLuarocksPackage {
-  pname = "busted";
-  version = "2.0.rc12-1";
+penlight = buildLuarocksPackage {
+  pname = "penlight";
+  version = "1.5.4-1";
+
+  knownRockspec = (fetchurl {
+    url    = https://luarocks.org/penlight-1.5.4-1.rockspec;
+    sha256 = "07mhsk9kmdxg4i2w4mrnnd2zs34bgggi9gigfplakxin96sa6c0p";
+  }).outPath;
 
   src = fetchurl {
-    url    = http://luarocks.org/manifests/teto/busted-2.0.rc12-1.src.rock;
-    sha256 = "18fzdc7ww4nxwinnw9ah5hi329ghrf0h8xrwcy26lk9qcs9n079z";
+    url    = http://stevedonovan.github.io/files/penlight-1.5.4.zip;
+    sha256 = "138f921p6kdqkmf4pz115phhj0jsqf28g33avws80d2vq2ixqm8q";
+  };
+
+  propagatedBuildInputs = [ luafilesystem ];
+
+  meta = with stdenv.lib; {
+    homepage = "http://stevedonovan.github.com/Penlight";
+    description = "Lua utility libraries loosely based on the Python standard libraries";
+    license = {
+      fullName = "MIT/X11";
+    };
+  };
+};
+rapidjson = buildLuarocksPackage {
+  pname = "rapidjson";
+  version = "0.5.2-1";
+
+  src = fetchurl {
+    url    = https://luarocks.org/rapidjson-0.5.2-1.src.rock;
+    sha256 = "17lgbzv9kairx49kwa0m8xwyly95mg6fw60jan2dpqwnnkf2m8y6";
   };
   disabled = (luaOlder "5.1");
-  propagatedBuildInputs = [ lua lua_cliargs luafilesystem luasystem dkjson say luassert lua-term penlight mediator_lua ];
+  propagatedBuildInputs = [ lua ];
 
-  meta = {
-    homepage = "http://olivinelabs.com/busted/";
-    description = "Elegant Lua unit testing.";
+  meta = with stdenv.lib; {
+    homepage = "https://github.com/xpol/lua-rapidjson";
+    description = "Json module based on the very fast RapidJSON.";
     license = {
-      fullName = "MIT <http://opensource.org/licenses/MIT>";
+      fullName = "MIT";
     };
   };
 };
-luassert = buildLuarocksPackage {
-  pname = "luassert";
-  version = "1.7.11-0";
+say = buildLuarocksPackage {
+  pname = "say";
+  version = "1.3-1";
 
   knownRockspec = (fetchurl {
-    url    = https://luarocks.org/luassert-1.7.11-0.rockspec;
-    sha256 = "12zgybcv8acjzvjdbxd1764s1vxbksxdv9fkvsymcsdmppxkbd0s";
+    url    = https://luarocks.org/say-1.3-1.rockspec;
+    sha256 = "0bknglb0qwd6r703wp3hcb6z2xxd14kq4md3sg9al3b28fzxbhdv";
   }).outPath;
 
   src = fetchurl {
-    url    = https://github.com/Olivine-Labs/luassert/archive/v1.7.11.tar.gz;
-    sha256 = "1vwq3wqj9cjyz9lnf1n38yhpcglr2h40v3n9096i8vcpmyvdb3ka";
+    url    = https://github.com/Olivine-Labs/say/archive/v1.3-1.tar.gz;
+    sha256 = "1jh76mxq9dcmv7kps2spwcc6895jmj2sf04i4y9idaxlicvwvs13";
   };
 
   disabled = (luaOlder "5.1");
-  propagatedBuildInputs = [ lua say ];
+  propagatedBuildInputs = [ lua ];
 
-  meta = {
+  meta = with stdenv.lib; {
     homepage = "http://olivinelabs.com/busted/";
-    description = "Lua Assertions Extension";
+    description = "Lua String Hashing/Indexing Library";
     license = {
       fullName = "MIT <http://opensource.org/licenses/MIT>";
     };
   };
 };
-coxpcall = buildLuarocksPackage {
-  pname = "coxpcall";
-  version = "1.17.0-1";
+std__debug = buildLuarocksPackage {
+  pname = "std._debug";
+  version = "1.0.1-1";
 
   src = fetchurl {
-    url    = https://luarocks.org/manifests/hisham/coxpcall-1.17.0-1.src.rock;
-    sha256 = "0n1jmda4g7x06458596bamhzhcsly6x0p31yp6q3jz4j11zv1zhi";
+    url    = https://luarocks.org/std._debug-1.0.1-1.src.rock;
+    sha256 = "1qkcc5rph3ns9mzrfsa1671pb3hzbzfnaxvyw7zdly2b7ll88svz";
   };
+  disabled = (luaOlder "5.1") || (luaAtLeast "5.5");
+  propagatedBuildInputs = [ lua ];
 
-  meta = {
-    homepage = "http://keplerproject.github.io/coxpcall";
-    description = "Coroutine safe xpcall and pcall";
+  meta = with stdenv.lib; {
+    homepage = "http://lua-stdlib.github.io/_debug";
+    description = "Debug Hints Library";
+    license = {
+      fullName = "MIT/X11";
+    };
+  };
+};
+std_normalize = buildLuarocksPackage {
+  pname = "std.normalize";
+  version = "2.0.2-1";
+
+  src = fetchurl {
+    url    = https://luarocks.org/std.normalize-2.0.2-1.src.rock;
+    sha256 = "0yn60zqnxflhhlv6xk6w0ifdfxk1qcg8gq1wnrrbwsxwpipsrfjh";
+  };
+  disabled = (luaOlder "5.1") || (luaAtLeast "5.4");
+  propagatedBuildInputs = [ lua std__debug ];
+
+  meta = with stdenv.lib; {
+    homepage = "https://lua-stdlib.github.io/normalize";
+    description = "Normalized Lua Functions";
+    license = {
+      fullName = "MIT/X11";
+    };
+  };
+};
+stdlib = buildLuarocksPackage {
+  pname = "stdlib";
+  version = "41.2.2-1";
+
+  src = fetchurl {
+    url    = https://luarocks.org/stdlib-41.2.2-1.src.rock;
+    sha256 = "1kricll40xy75j72lrbp2jpyxsj9v8b9d7qjf3m3fq1bpg6dmsk7";
+  };
+  disabled = (luaOlder "5.1") || (luaAtLeast "5.5");
+  propagatedBuildInputs = [ lua ];
+
+  meta = with stdenv.lib; {
+    homepage = "http://lua-stdlib.github.io/lua-stdlib";
+    description = "General Lua Libraries";
+    maintainers = with maintainers; [ vyp ];
     license = {
       fullName = "MIT/X11";
     };
diff --git a/pkgs/development/lua-modules/luasql.patch b/pkgs/development/lua-modules/luasql.patch
deleted file mode 100644
index e91840101ee5..000000000000
--- a/pkgs/development/lua-modules/luasql.patch
+++ /dev/null
@@ -1,37 +0,0 @@
---- a/config	2013-02-18 19:36:44.000000000 +0400
-+++ b/config	2014-10-01 08:36:37.104254404 +0400
-@@ -1,12 +1,12 @@
- # $Id: config,v 1.10 2008/05/30 17:21:18 tomas Exp $
- 
- # Driver (leave uncommented ONLY the line with the name of the driver)
--T= mysql
-+#T= mysql
- #T= oci8
- #T= odbc
- #T= postgres
- #T= sqlite
--#T=sqlite3
-+T=sqlite3
- #T=firebird
- 
- # Installation directories
-@@ -37,8 +37,8 @@
- ######## MySQL
- #DRIVER_LIBS= -L/usr/local/mysql/lib -lmysqlclient -lz
- #DRIVER_INCS= -I/usr/local/mysql/include
--DRIVER_LIBS= -L/usr/lib -lmysqlclient -lz
--DRIVER_INCS= -I/usr/include/mysql
-+#DRIVER_LIBS= -L/usr/lib -lmysqlclient -lz
-+#DRIVER_INCS= -I/usr/include/mysql
- ######## Oracle OCI8
- #DRIVER_LIBS= -L/home/oracle/OraHome1/lib -lz -lclntsh
- #DRIVER_INCS= -I/home/oracle/OraHome1/rdbms/demo -I/home/oracle/OraHome1/rdbms/public
-@@ -51,7 +51,7 @@
- #DRIVER_LIBS= -lsqlite
- #DRIVER_INCS=
- ######## SQLite3 
--#DRIVER_LIBS= -L/opt/local/lib -lsqlite3
-+DRIVER_LIBS= -lsqlite3
- #DRIVER_INCS= -I/opt/local/include
- ######## ODBC
- #DRIVER_LIBS= -L/usr/local/lib -lodbc
diff --git a/pkgs/development/lua-modules/luuid.patch b/pkgs/development/lua-modules/luuid.patch
new file mode 100644
index 000000000000..039d522be6d7
--- /dev/null
+++ b/pkgs/development/lua-modules/luuid.patch
@@ -0,0 +1,16 @@
+diff -Naur 5.2/uuid/luuid.c rock/uuid/luuid.c
+--- 5.2/uuid/luuid.c	2012-05-10 11:22:00.000000000 +1000
++++ rock/uuid/luuid.c	2019-06-13 15:13:10.374134079 +1000
+@@ -64,7 +64,11 @@
+ 
+ LUALIB_API int luaopen_uuid(lua_State *L)
+ {
+- luaL_newlib(L,R);
++ #if LUA_VERSION_NUM == 501
++  luaL_register(L,MYNAME,R);
++ #else
++  luaL_newlib(L,R);
++ #endif
+  lua_pushliteral(L,"version");			/** version */
+  lua_pushliteral(L,MYVERSION);
+  lua_settable(L,-3);
diff --git a/pkgs/development/lua-modules/overrides.nix b/pkgs/development/lua-modules/overrides.nix
index 0f448343e968..9f03b84588ec 100644
--- a/pkgs/development/lua-modules/overrides.nix
+++ b/pkgs/development/lua-modules/overrides.nix
@@ -5,113 +5,260 @@ with super;
   ##########################################3
   #### manual fixes for generated packages
   ##########################################3
-  lgi = super.lgi.overrideAttrs(oa: {
-    nativeBuildInputs = [ pkgs.pkgconfig ];
-    buildInputs = with pkgs; oa.buildInputs ++ [ glib gobjectIntrospection];
+  bit32 = super.bit32.override({
+    disabled = !isLua51;
+    # Theoretically works with luajit, but it does redefine at least one Lua
+    # 5.2 function that Luajit 2.1 provides, see:
+    # https://github.com/LuaJIT/LuaJIT/issues/325
+  });
+
+  busted = super.busted.override({
+    postConfigure = ''
+      substituteInPlace ''${rockspecFilename} \
+        --replace "'lua_cliargs = 3.0-1'," "'lua_cliargs >= 3.0-1',"
+    '';
+    postInstall = ''
+      install -D completions/zsh/_busted $out/share/zsh/site-functions/_busted
+      install -D completions/bash/busted.bash $out/share/bash-completion/completions/busted
+    '';
+  });
+
+  cqueues = super.cqueues.override(rec {
+    # Parse out a version number without the Lua version inserted
+    version = with pkgs.lib; let
+      version' = super.cqueues.version;
+      rel = splitString "." version';
+      date = head rel;
+      rev = last (splitString "-" (last rel));
+    in "${date}-${rev}";
+    nativeBuildInputs = [
+      pkgs.gnum4
+    ];
+    externalDeps = [
+      { name = "CRYPTO"; dep = pkgs.openssl; }
+      { name = "OPENSSL"; dep = pkgs.openssl; }
+    ];
     patches = [
-        (pkgs.fetchpatch {
-            name = "lgi-find-cairo-through-typelib.patch";
-            url = "https://github.com/psychon/lgi/commit/46a163d9925e7877faf8a4f73996a20d7cf9202a.patch";
-            sha256 = "0gfvvbri9kyzhvq3bvdbj2l6mwvlz040dk4mrd5m9gz79f7w109c";
-        })
+      # https://github.com/wahern/cqueues/issues/216 &
+      # https://github.com/wahern/cqueues/issues/217
+      (pkgs.fetchpatch {
+        name = "find-version-fix.patch";
+        url = "https://github.com/wahern/cqueues/pull/217.patch";
+        sha256 = "0068ql0jlxmjkvhzydyy52sjd0k4vad6b8w4y5szpbv4vb2lzcsc";
+      })
     ];
+    disabled = luaOlder "5.1" || luaAtLeast "5.4";
+    # Upstream rockspec is pointlessly broken into separate rockspecs, per Lua
+    # version, which doesn't work well for us, so modify it
+    postConfigure = let inherit (super.cqueues) pname; in ''
+      # 'all' target auto-detects correct Lua version, which is fine for us as
+      # we only have the right one available :)
+      sed -Ei ''${rockspecFilename} \
+        -e 's|lua == 5.[[:digit:]]|lua >= 5.1, <= 5.3|' \
+        -e 's|build_target = "[^"]+"|build_target = "all"|' \
+        -e 's|version = "[^"]+"|version = "${version}"|'
+      specDir=$(dirname ''${rockspecFilename})
+      cp ''${rockspecFilename} "$specDir/${pname}-${version}.rockspec"
+      rockspecFilename="$specDir/${pname}-${version}.rockspec"
+    '';
   });
 
-  ltermbox = super.ltermbox.override( {
-    disabled = !isLua51 || isLuaJIT;
+  cyrussasl = super.cyrussasl.override({
+    externalDeps = [
+      { name = "LIBSASL"; dep = pkgs.cyrus_sasl; }
+    ];
   });
 
-  lua-cmsgpack = super.lua-cmsgpack.override({
-    # TODO this should work with luajit once we fix luajit headers ?
-    disabled = (!isLua51) || isLuaJIT;
+  http = super.http.override({
+    patches = [
+      (pkgs.fetchpatch {
+        name = "invalid-state-progression.patch";
+        url = "https://github.com/daurnimator/lua-http/commit/cb7b59474a.diff";
+        sha256 = "1vmx039n3nqfx50faqhs3wgiw28ws416rhw6vh6srmh9i826dac7";
+      })
+    ];
+    /* TODO: separate docs derivation? (pandoc is heavy)
+    nativeBuildInputs = [ pandoc ];
+    makeFlags = [ "-C doc" "lua-http.html" "lua-http.3" ];
+    */
   });
 
-  lrexlib-posix = super.lrexlib-posix.override({
-    buildInputs = [ pkgs.glibc.dev ];
+  lgi = super.lgi.override({
+    nativeBuildInputs = [
+      pkgs.pkgconfig
+    ];
+    buildInputs = [
+      pkgs.glib
+      pkgs.gobjectIntrospection
+    ];
+    patches = [
+      (pkgs.fetchpatch {
+        name = "lgi-find-cairo-through-typelib.patch";
+        url = "https://github.com/psychon/lgi/commit/46a163d9925e7877faf8a4f73996a20d7cf9202a.patch";
+        sha256 = "0gfvvbri9kyzhvq3bvdbj2l6mwvlz040dk4mrd5m9gz79f7w109c";
+      })
+    ];
   });
+
   lrexlib-gnu = super.lrexlib-gnu.override({
-    buildInputs = [ pkgs.gnulib ];
+    buildInputs = [
+      pkgs.gnulib
+    ];
+  });
+
+  lrexlib-pcre = super.lrexlib-pcre.override({
+    externalDeps = [
+      { name = "PCRE"; dep = pkgs.pcre; }
+    ];
+  });
+
+  lrexlib-posix = super.lrexlib-posix.override({
+    buildInputs = [
+      pkgs.glibc.dev
+    ];
+  });
+
+  ltermbox = super.ltermbox.override( {
+    disabled = !isLua51 || isLuaJIT;
   });
+
+  lua-iconv = super.lua-iconv.override({
+    buildInputs = [
+      pkgs.libiconv
+    ];
+  });
+
   lua-zlib = super.lua-zlib.override({
-    buildInputs = [ pkgs.zlib.dev ];
-    disabled=luaOlder "5.1" || luaAtLeast "5.4";
+    buildInputs = [
+      pkgs.zlib.dev
+    ];
+    disabled = luaOlder "5.1" || luaAtLeast "5.4";
   });
-  luaevent = super.luaevent.override({
-    buildInputs = with pkgs; [ libevent.dev libevent ];
-    propagatedBuildInputs = [ luasocket ];
-    extraConfig = ''
-      variables={
-        EVENT_INCDIR="${pkgs.libevent.dev}/include";
-        EVENT_LIBDIR="${pkgs.libevent}/lib";
-      }
+
+  luadbi-mysql = super.luadbi-mysql.override({
+    extraVariables = ''
+      -- Can't just be /include, unfortunately
+      MYSQL_INCDIR='${pkgs.mysql.connector-c}/include/mysql';
     '';
-    disabled= luaOlder "5.1" || luaAtLeast "5.4" || isLuaJIT;
+    buildInputs = [
+      pkgs.mysql.client
+      pkgs.mysql.connector-c
+    ];
   });
-  lua-iconv = super.lua-iconv.override({
-    buildInputs = [ pkgs.libiconv ];
+
+  luadbi-postgresql = super.luadbi-postgresql.override({
+    buildInputs = [
+      pkgs.postgresql
+    ];
+  });
+
+  luadbi-sqlite3 = super.luadbi-sqlite3.override({
+    externalDeps = [
+      { name = "SQLITE"; dep = pkgs.sqlite; }
+    ];
   });
+
+  luaevent = super.luaevent.override({
+    propagatedBuildInputs = [
+      luasocket
+    ];
+    externalDeps = [
+      { name = "EVENT"; dep = pkgs.libevent; }
+    ];
+    disabled = luaOlder "5.1" || luaAtLeast "5.4";
+  });
+
+  luaexpat = super.luaexpat.override({
+    externalDeps = [
+      { name = "EXPAT"; dep = pkgs.expat; }
+    ];
+  });
+
+  # TODO Somehow automatically amend buildInputs for things that need luaffi
+  # but are in luajitPackages?
+  luaffi = super.luaffi.override({
+    # The packaged .src.rock version is pretty old, and doesn't work with Lua 5.3
+    src = pkgs.fetchFromGitHub {
+      owner = "facebook"; repo = "luaffifb";
+      rev = "532c757e51c86f546a85730b71c9fef15ffa633d";
+      sha256 = "1nwx6sh56zfq99rcs7sph0296jf6a9z72mxknn0ysw9fd7m1r8ig";
+    };
+    knownRockspec = with super.luaffi; "${pname}-${version}.rockspec";
+    disabled = luaOlder "5.1" || luaAtLeast "5.4" || isLuaJIT;
+  });
+
+  luaossl = super.luaossl.override({
+    externalDeps = [
+      { name = "CRYPTO"; dep = pkgs.openssl; }
+      { name = "OPENSSL"; dep = pkgs.openssl; }
+    ];
+  });
+
+  luasec = super.luasec.override({
+    externalDeps = [
+      { name = "OPENSSL"; dep = pkgs.openssl; }
+    ];
+  });
+
+  luasql-sqlite3 = super.luasql-sqlite3.override({
+    externalDeps = [
+      { name = "SQLITE"; dep = pkgs.sqlite; }
+    ];
+  });
+
+  luasystem = super.luasystem.override({
+    buildInputs = [
+      pkgs.glibc
+    ];
+  });
+
   luazip = super.luazip.override({
-    buildInputs = [ pkgs.zziplib ];
+    buildInputs = [
+      pkgs.zziplib
+    ];
   });
-  luv = super.luv.overrideAttrs(oa: {
+
+  luuid = super.luuid.override(old: {
+    externalDeps = [
+      { name = "LIBUUID"; dep = pkgs.libuuid; }
+    ];
+    meta = old.meta // {
+      platforms = pkgs.lib.platforms.linux;
+    };
+    # Trivial patch to make it work in both 5.1 and 5.2.  Basically just the
+    # tiny diff between the two upstream versions placed behind an #if.
+    # Upstreams:
+    # 5.1: http://webserver2.tecgraf.puc-rio.br/~lhf/ftp/lua/5.1/luuid.tar.gz
+    # 5.2: http://webserver2.tecgraf.puc-rio.br/~lhf/ftp/lua/5.2/luuid.tar.gz
+    patchFlags = "-p2";
+    patches = [
+      ./luuid.patch
+    ];
+    postConfigure = let inherit (super.luuid) version pname; in ''
+      sed -Ei ''${rockspecFilename} -e 's|lua >= 5.2|lua >= 5.1,|'
+    '';
+    disabled = luaOlder "5.1" || (luaAtLeast "5.4");
+  });
+
+  luv = super.luv.override({
     # Use system libuv instead of building local and statically linking
     # This is a hacky way to specify -DWITH_SHARED_LIBUV=ON which
-    # should be possible but I'm unable to make work.
+    # is not possible with luarocks and the current luv rockspec
     # While at it, remove bundled libuv source entirely to be sure.
     # We may wish to drop bundled lua submodules too...
     preBuild = ''
      sed -i 's,\(option(WITH_SHARED_LIBUV.*\)OFF,\1ON,' CMakeLists.txt
      rm -rf deps/libuv
     '';
-    propagatedBuildInputs = oa.propagatedBuildInputs ++ [ pkgs.libuv ];
-  });
-
-  busted = super.busted.overrideAttrs(oa: {
-    postInstall = ''
-      install -D completions/zsh/_busted $out/share/zsh/site-functions/_busted
-    '';
-  });
-
-  luuid = super.luuid.override(oa: {
-    buildInputs = [ pkgs.libuuid ];
-    extraConfig = ''
-      variables = {
-        LIBUUID_INCDIR="${pkgs.lib.getDev pkgs.libuuid}/include";
-        LIBUUID_LIBDIR="${pkgs.lib.getLib pkgs.libuuid}/lib";
-      }
-    '';
-    meta = oa.meta // {
-      platforms = pkgs.lib.platforms.linux;
-    };
+    propagatedBuildInputs = [
+      pkgs.libuv
+    ];
   });
 
-  rapidjson = super.rapidjson.overrideAttrs(oa: {
+  rapidjson = super.rapidjson.override({
     preBuild = ''
       sed -i '/set(CMAKE_CXX_FLAGS/d' CMakeLists.txt
       sed -i '/set(CMAKE_C_FLAGS/d' CMakeLists.txt
     '';
   });
-
-  binaryheap = super.binaryheap.overrideAttrs(oa: {
-    meta = oa.meta // {
-      maintainers = with pkgs.lib.maintainers; oa.meta.maintainers ++ [ vcunat ];
-    };
-  });
-
-  http = super.http.overrideAttrs(oa: {
-    patches = oa.patches or [] ++ [
-      (pkgs.fetchpatch {
-        name = "invalid-state-progression.patch";
-        url = "https://github.com/daurnimator/lua-http/commit/cb7b59474a.diff";
-        sha256 = "1vmx039n3nqfx50faqhs3wgiw28ws416rhw6vh6srmh9i826dac7";
-      })
-    ];
-    /* TODO: separate docs derivation? (pandoc is heavy)
-    nativeBuildInputs = [ pandoc ];
-    makeFlags = [ "-C doc" "lua-http.html" "lua-http.3" ];
-    */
-    meta = oa.meta // {
-      maintainers = with pkgs.lib.maintainers; oa.meta.maintainers ++ [ vcunat ];
-    };
-  });
 }
diff --git a/pkgs/development/tools/misc/luarocks/darwin.patch b/pkgs/development/tools/misc/luarocks/darwin-3.0.x.patch
index a5e4ac461b48..a5e4ac461b48 100644
--- a/pkgs/development/tools/misc/luarocks/darwin.patch
+++ b/pkgs/development/tools/misc/luarocks/darwin-3.0.x.patch
diff --git a/pkgs/development/tools/misc/luarocks/darwin-3.1.3.patch b/pkgs/development/tools/misc/luarocks/darwin-3.1.3.patch
new file mode 100644
index 000000000000..7ef1c7a319ca
--- /dev/null
+++ b/pkgs/development/tools/misc/luarocks/darwin-3.1.3.patch
@@ -0,0 +1,24 @@
+diff --git a/src/luarocks/core/cfg.lua b/src/luarocks/core/cfg.lua
+index c5af5a2..1949fdc 100644
+--- a/src/luarocks/core/cfg.lua
++++ b/src/luarocks/core/cfg.lua
+@@ -425,7 +425,7 @@ local function make_defaults(lua_version, target_cpu, platforms, home)
+       defaults.external_lib_extension = "dylib"
+       defaults.arch = "macosx-"..target_cpu
+       defaults.variables.LIBFLAG = "-bundle -undefined dynamic_lookup -all_load"
+-      local version = util.popen_read("sw_vers -productVersion")
++      local version = "10.10"
+       version = tonumber(version and version:match("^[^.]+%.([^.]+)")) or 3
+       if version >= 10 then
+          version = 8
+@@ -434,8 +434,8 @@ local function make_defaults(lua_version, target_cpu, platforms, home)
+       else
+          defaults.gcc_rpath = false
+       end
+-      defaults.variables.CC = "env MACOSX_DEPLOYMENT_TARGET=10."..version.." gcc"
+-      defaults.variables.LD = "env MACOSX_DEPLOYMENT_TARGET=10."..version.." gcc"
++      defaults.variables.CC = "env MACOSX_DEPLOYMENT_TARGET=10."..version.." clang"
++      defaults.variables.LD = "env MACOSX_DEPLOYMENT_TARGET=10."..version.." clang"
+       defaults.web_browser = "open"
+    end
+ 
diff --git a/pkgs/development/tools/misc/luarocks/default.nix b/pkgs/development/tools/misc/luarocks/default.nix
index 7edcb79388ab..2e0eec5ae57d 100644
--- a/pkgs/development/tools/misc/luarocks/default.nix
+++ b/pkgs/development/tools/misc/luarocks/default.nix
@@ -9,14 +9,14 @@
 
 stdenv.mkDerivation rec {
   pname = "luarocks";
-  version = "3.0.4";
+  version = "3.1.3";
 
   src = fetchurl {
     url="http://luarocks.org/releases/luarocks-${version}.tar.gz";
-    sha256="1pqfzwvjy8dzqg4fqjq2cgqcr00fgrdd7nwzxm7nqmawr83s6dhj";
+    sha256="04q5k6drypsnbp1wspr9ns72k8kjf62a787a6jg1bb2s95gl6wy5";
   };
 
-  patches = [ ./darwin.patch ];
+  patches = [ ./darwin-3.1.3.patch ];
   preConfigure = ''
     lua -e "" || {
         luajit -e "" && {
diff --git a/pkgs/development/tools/misc/luarocks/luarocks-nix.nix b/pkgs/development/tools/misc/luarocks/luarocks-nix.nix
index d9f481425b62..8da224f0ef8c 100644
--- a/pkgs/development/tools/misc/luarocks/luarocks-nix.nix
+++ b/pkgs/development/tools/misc/luarocks/luarocks-nix.nix
@@ -4,7 +4,10 @@ luarocks.overrideAttrs(old: {
   src = fetchFromGitHub {
     owner = "teto";
     repo = "luarocks";
-    rev = "595456f1246d66e5bdce0de838d0d6188274991c";
-    sha256 = "14nn0n5a0m516lnbwljy85h7y98zwnfbcyz7hgsm6fn4p8316yz2";
+    rev = "38ed82ba3e5682d7d55ef9a870dfb464ca180df9";
+    sha256 = "0vlzywiv3sxkpjg1fzzxicmfr6kh04fxw5q9n8vsd2075xjxg6bs";
   };
+  patches = [
+    ./darwin-3.0.x.patch
+  ];
 })
diff --git a/pkgs/games/mudlet/default.nix b/pkgs/games/mudlet/default.nix
index 673efb0e118d..dab83ddc900d 100644
--- a/pkgs/games/mudlet/default.nix
+++ b/pkgs/games/mudlet/default.nix
@@ -1,5 +1,5 @@
 { fetchurl, unzip, stdenv, makeWrapper, qtbase, yajl, libzip, hunspell
-, boost, lua5_1, luafilesystem, luazip, lrexlib, luasqlite3, qmake }:
+, boost, lua5_1, luafilesystem, luazip, lrexlib-pcre, luasql-sqlite3, qmake }:
 
 stdenv.mkDerivation rec {
   name = "mudlet-${version}";
@@ -13,7 +13,7 @@ stdenv.mkDerivation rec {
   nativeBuildInputs = [ makeWrapper qmake ];
   buildInputs = [
     unzip qtbase lua5_1 hunspell libzip yajl boost
-    luafilesystem luazip lrexlib luasqlite3
+    luafilesystem luazip lrexlib-pcre luasql-sqlite3
   ];
 
   preConfigure = "cd src";
@@ -21,8 +21,8 @@ stdenv.mkDerivation rec {
   installPhase = let
     luaZipPath = "${luazip}/lib/lua/5.1/?.so";
     luaFileSystemPath = "${luafilesystem}/lib/lua/5.1/?.so";
-    lrexlibPath = "${lrexlib}/lib/lua/5.1/?.so";
-    luasqlitePath = "${luasqlite3}/lib/lua/5.1/?.so";
+    lrexlibPath = "${lrexlib-pcre}/lib/lua/5.1/?.so";
+    luasqlitePath = "${luasql-sqlite3}/lib/lua/5.1/?.so";
   in ''
     mkdir -pv $out/bin
     cp mudlet $out
diff --git a/pkgs/servers/dns/knot-resolver/default.nix b/pkgs/servers/dns/knot-resolver/default.nix
index 0a4d6f154807..0fd0e67c907a 100644
--- a/pkgs/servers/dns/knot-resolver/default.nix
+++ b/pkgs/servers/dns/knot-resolver/default.nix
@@ -80,7 +80,7 @@ wrapped-full = runCommand unwrapped.name
     nativeBuildInputs = [ makeWrapper ];
     buildInputs = with luajitPackages; [
       luasec luasocket # trust anchor bootstrap, prefill module
-      lfs # prefill module
+      luafilesystem # prefill module
       http # for http module; brings lots of deps; some are useful elsewhere
     ];
     preferLocalBuild = true;
diff --git a/pkgs/servers/xmpp/prosody/default.nix b/pkgs/servers/xmpp/prosody/default.nix
index 28be53b4e6cb..928c48329656 100644
--- a/pkgs/servers/xmpp/prosody/default.nix
+++ b/pkgs/servers/xmpp/prosody/default.nix
@@ -12,17 +12,6 @@ assert withDBI -> luadbi != null;
 
 with stdenv.lib;
 
-let
-  libs        = [ luasocket luasec luaexpat luafilesystem luabitop ]
-                ++ optional withLibevent luaevent
-                ++ optional withDBI luadbi
-                ++ withExtraLibs;
-  getPath     = lib : type : "${lib}/lib/lua/${lua5.luaversion}/?.${type};${lib}/share/lua/${lua5.luaversion}/?.${type}";
-  getLuaPath  = lib : getPath lib "lua";
-  getLuaCPath = lib : getPath lib "so";
-  luaPath     = concatStringsSep ";" (map getLuaPath  libs);
-  luaCPath    = concatStringsSep ";" (map getLuaCPath libs);
-in
 
 stdenv.mkDerivation rec {
   version = "0.11.2"; # also update communityModules
@@ -42,8 +31,17 @@ stdenv.mkDerivation rec {
     sha256 = "0bzn92j48krb2zhp9gn5bbn5sg0qv15j5lpxfszwqdln3lpmrvzg";
   };
 
-  buildInputs = [ lua5 makeWrapper libidn openssl ]
-    ++ optional withDBI luadbi;
+  buildInputs = [
+    lua5 makeWrapper libidn openssl
+  ]
+  # Lua libraries
+  ++ [
+    luasocket luasec luaexpat luafilesystem luabitop
+  ]
+  ++ optional withLibevent luaevent
+  ++ optional withDBI luadbi
+  ++ withExtraLibs;
+
 
   configureFlags = [
     "--ostype=linux"
@@ -56,12 +54,12 @@ stdenv.mkDerivation rec {
         cp -r $communityModules/mod_${module} $out/lib/prosody/modules/
       '') (withCommunityModules ++ withOnlyInstalledCommunityModules)}
       wrapProgram $out/bin/prosody \
-        --set LUA_PATH '${luaPath};' \
-        --set LUA_CPATH '${luaCPath};'
+        --prefix LUA_PATH ';' "$NIX_LUA_PATH" \
+        --prefix LUA_CPATH ';' "$NIX_LUA_CPATH"
       wrapProgram $out/bin/prosodyctl \
         --add-flags '--config "/etc/prosody/prosody.cfg.lua"' \
-        --set LUA_PATH '${luaPath};' \
-        --set LUA_CPATH '${luaCPath};'
+        --prefix LUA_PATH ';' "$NIX_LUA_PATH" \
+        --prefix LUA_CPATH ';' "$NIX_LUA_CPATH"
     '';
 
   passthru.communityModules = withCommunityModules;
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index 3088bfae971d..98ede4119222 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -18904,8 +18904,7 @@ in
   };
 
   luakit = callPackage ../applications/networking/browsers/luakit {
-    inherit (lua51Packages) luafilesystem;
-    lua5 = lua5_1;
+    inherit (luajitPackages) luafilesystem;
   };
 
   looking-glass-client = callPackage ../applications/virtualization/looking-glass-client { };
@@ -21663,7 +21662,7 @@ in
   mrrescue = callPackage ../games/mrrescue { };
 
   mudlet = libsForQt5.callPackage ../games/mudlet {
-    inherit (lua51Packages) luafilesystem lrexlib luazip luasqlite3;
+    inherit (lua51Packages) luafilesystem lrexlib-pcre luazip luasql-sqlite3;
   };
 
   n2048 = callPackage ../games/n2048 {};
diff --git a/pkgs/top-level/lua-packages.nix b/pkgs/top-level/lua-packages.nix
index f1e2fde2e7e1..87c9bd3bacfb 100644
--- a/pkgs/top-level/lua-packages.nix
+++ b/pkgs/top-level/lua-packages.nix
@@ -56,7 +56,7 @@ let
 
   buildLuaApplication = args: buildLuarocksPackage ({namePrefix="";} // args );
 
-  buildLuarocksPackage = with pkgs.lib; makeOverridable( callPackage ../development/interpreters/lua-5/build-lua-package.nix {
+  buildLuarocksPackage = with pkgs.lib; makeOverridable(callPackage ../development/interpreters/lua-5/build-lua-package.nix {
     inherit toLuaModule;
     inherit lua;
   });
@@ -98,327 +98,6 @@ with self; {
 
   luarocks-nix = callPackage ../development/tools/misc/luarocks/luarocks-nix.nix { };
 
-  bit32 = buildLuaPackage rec {
-    version = "5.3.0";
-    name = "bit32-${version}";
-
-    src = fetchFromGitHub {
-      owner = "keplerproject";
-      repo = "lua-compat-5.2";
-      rev = "bitlib-${version}";
-      sha256 = "1ipqlbvb5w394qwhm2f3w6pdrgy8v4q8sps5hh3pqz14dcqwakhj";
-    };
-
-    buildPhase = ''
-      cc ${if stdenv.isDarwin then "-bundle -undefined dynamic_lookup -all_load" else "-shared"} -Ic-api lbitlib.c -o bit32.so
-    '';
-
-    installPhase = ''
-      mkdir -p $out/lib/lua/${lua.luaversion}
-      install -p bit32.so $out/lib/lua/${lua.luaversion}
-    '';
-
-    meta = with stdenv.lib; {
-      description = "Lua 5.2 bit manipulation library";
-      homepage = "http://www.lua.org/manual/5.2/manual.html#6.7";
-      license = licenses.mit;
-      maintainers = with maintainers; [ lblasc ];
-      platforms = platforms.unix;
-    };
-  };
-
-  compat53 = buildLuaPackage rec {
-    version = "0.7";
-    name = "compat53-${version}";
-
-    src = fetchFromGitHub {
-      owner = "keplerproject";
-      repo = "lua-compat-5.3";
-      rev = "v${version}";
-      sha256 = "02a14nvn7aggg1yikj9h3dcf8aqjbxlws1bfvqbpfxv9d5phnrpz";
-    };
-
-    nativeBuildInputs = [ pkgconfig ];
-
-    postConfigure = ''
-      CFLAGS+=" -shared $(pkg-config --libs ${if isLuaJIT then "luajit" else "lua"})"
-    '';
-
-    buildPhase = ''
-      cc lstrlib.c $CFLAGS -o string.so
-      cc ltablib.c $CFLAGS -o table.so
-      cc lutf8lib.c $CFLAGS -o utf8.so
-    '';
-
-    # The hook in ../development/lua-modules/generic/default.nix
-    # is strict about share vs. lib for _PATH and _CPATH.
-    installPhase = ''
-      install -Dt "$out/share/lua/${lua.luaversion}/compat53" compat53/*.lua
-      install -Dt "$out/lib/lua/${lua.luaversion}/compat53" *.so
-    '';
-
-    meta = with stdenv.lib; {
-      description = "Compatibility module providing Lua-5.3-style APIs for Lua 5.2 and 5.1";
-      homepage = "https://github.com/keplerproject/lua-compat-5.3";
-      license = licenses.mit;
-      maintainers = with maintainers; [ vcunat ];
-      platforms = platforms.all;
-    };
-  };
-
-  cqueues = buildLuaPackage rec {
-    name = "cqueues-${version}";
-    version = "20171014";
-
-    src = fetchurl {
-      url = "https://www.25thandclement.com/~william/projects/releases/${name}.tgz";
-      sha256 = "1dabhpn6r0hlln8vx9hxm34pfcm46qzgpb2apmziwg5z51fi4ksb";
-    };
-
-    preConfigure = ''export prefix=$out'';
-
-    # https://github.com/wahern/cqueues/issues/216
-    NIX_CFLAGS_COMPILE = [ "-DCQUEUES_VERSION=${version}" ];
-
-    nativeBuildInputs = [ gnum4 ];
-    buildInputs = [ openssl ];
-
-    meta = with stdenv.lib; {
-      description = "A type of event loop for Lua";
-      homepage = "https://www.25thandclement.com/~william/projects/cqueues.html";
-      license = licenses.mit;
-      maintainers = with maintainers; [ vcunat ];
-      platforms = platforms.unix;
-    };
-  };
-
-  luacyrussasl = buildLuaPackage rec {
-    version = "1.1.0";
-    name = "lua-cyrussasl-${version}";
-    src = fetchFromGitHub {
-      owner = "JorjBauer";
-      repo = "lua-cyrussasl";
-      rev = "v${version}";
-      sha256 = "14kzm3vk96k2i1m9f5zvpvq4pnzaf7s91h5g4h4x2bq1mynzw2s1";
-    };
-
-    preBuild = ''
-      makeFlagsArray=(
-        CFLAGS="-O2 -fPIC"
-        LDFLAGS="-O -shared -fpic -lsasl2"
-        LUAPATH="$out/share/lua/${lua.luaversion}"
-        CPATH="$out/lib/lua/${lua.luaversion}"
-      );
-      mkdir -p $out/{share,lib}/lua/${lua.luaversion}
-    '';
-
-    buildInputs = [ cyrus_sasl ];
-
-    meta = with stdenv.lib; {
-      homepage = "https://github.com/JorjBauer/lua-cyrussasl";
-      description = "Cyrus SASL library for Lua 5.1+";
-      license = licenses.bsd3;
-    };
-  };
-
-  luaexpat = buildLuaPackage rec {
-    version = "1.3.0";
-    name = "expat-${version}";
-
-    src = fetchurl {
-      url = "https://matthewwild.co.uk/projects/luaexpat/luaexpat-${version}.tar.gz";
-      sha256 = "1hvxqngn0wf5642i5p3vcyhg3pmp102k63s9ry4jqyyqc1wkjq6h";
-    };
-
-    buildInputs = [ expat ];
-
-    preConfigure = stdenv.lib.optionalString stdenv.isDarwin ''
-      substituteInPlace Makefile \
-      --replace '-shared' '-bundle -undefined dynamic_lookup -all_load'
-    '';
-
-    preBuild = ''
-      makeFlagsArray=(
-        LUA_LDIR="$out/share/lua/${lua.luaversion}"
-        LUA_INC="-I${lua}/include" LUA_CDIR="$out/lib/lua/${lua.luaversion}"
-        EXPAT_INC="-I${expat.dev}/include");
-    '';
-
-    disabled = isLua53 || isLuaJIT;
-
-    meta = with stdenv.lib; {
-      description = "SAX XML parser based on the Expat library";
-      homepage = "http://matthewwild.co.uk/projects/luaexpat";
-      license = licenses.mit;
-      maintainers = with maintainers; [ flosse ];
-      platforms = platforms.unix;
-    };
-  };
-
-  luadbi = buildLuaPackage rec {
-    name = "luadbi-${version}";
-    version = "0.7.2";
-
-    src = fetchFromGitHub {
-      owner = "mwild1";
-      repo = "luadbi";
-      rev = "v${version}";
-      sha256 = "167ivwmczhp98bxzpz3wdxcfj6vi0a10gpi7rdfjs2rbfwkzqvjh";
-    };
-
-    MYSQL_INC = [ "-I${mysql.connector-c}/include/mysql" ];
-    MYSQL_LDFLAGS= [
-      "-lmysqlclient"
-      "-L${mysql.connector-c}/lib/mysql"
-    ];
-
-    nativeBuildInputs = [ mysql.client ];
-    buildInputs = [ mysql.connector-c postgresql sqlite ];
-
-    preConfigure = stdenv.lib.optionalString stdenv.isDarwin ''
-      substituteInPlace Makefile \
-        --replace '-shared' '-bundle -undefined dynamic_lookup -all_load'
-    '';
-
-    installFlags = [
-      "LUA_CDIR=$(out)/lib/lua/${lua.luaversion}"
-      "LUA_LDIR=$(out)/share/lua/${lua.luaversion}"
-    ];
-
-    installTargets = [
-      "install_lua" "install_mysql" "install_psql" "install_sqlite3"
-    ];
-
-    meta = with stdenv.lib; {
-      homepage = https://github.com/mwild1/luadbi;
-      license = licenses.mit;
-      platforms = stdenv.lib.platforms.unix;
-    };
-  };
-
-  luafilesystem = buildLuaPackage rec {
-    version = "1.7.0";
-    name = "filesystem-${version}";
-
-    src = fetchFromGitHub {
-      owner = "keplerproject";
-      repo = "luafilesystem";
-      rev = "v${stdenv.lib.replaceChars ["."] ["_"] version}";
-      sha256 = "0fibrasshlgpa71m9wkpjxwmylnxpcf06rpqbaa0qwvqh94nhwby";
-    };
-
-    preConfigure = ''
-      substituteInPlace config --replace "CC= gcc" "";
-    ''
-    + stdenv.lib.optionalString stdenv.isDarwin ''
-      substituteInPlace config \
-      --replace 'LIB_OPTION= -shared' '###' \
-      --replace '#LIB_OPTION= -bundle' 'LIB_OPTION= -bundle'
-      substituteInPlace Makefile --replace '10.3' '10.5'
-    '';
-
-    meta = with stdenv.lib; {
-      description = "Lua library complementing filesystem-related functions";
-      homepage = "https://github.com/keplerproject/luafilesystem";
-      license = licenses.mit;
-      maintainers = with maintainers; [ flosse ];
-      platforms = platforms.unix;
-    };
-  };
-
-  luaossl = buildLuaPackage rec {
-    name = "luaossl-${version}";
-    version = "20181207";
-
-    src = fetchurl {
-      url = "https://github.com/wahern/luaossl/releases/download/rel-${version}/luaossl-rel-${version}.zip";
-      sha256 = "194r6db80ksh4zh8d2k35q6vci9zbrfvkanjl280y6ij2xyhkvj7";
-    };
-
-    preConfigure = ''export prefix=$out'';
-
-    nativeBuildInputs = [ unzip ];
-    buildInputs = [ openssl ];
-
-    meta = with stdenv.lib; {
-      description = "Comprehensive binding to OpenSSL for Lua 5.1+";
-      homepage = "https://www.25thandclement.com/~william/projects/luaossl.html";
-      license = licenses.mit;
-      maintainers = with maintainers; [ vcunat ];
-      platforms = platforms.unix;
-    };
-  };
-
-  luasec = buildLuaPackage rec {
-    name = "sec-0.8";
-
-    src = fetchFromGitHub {
-      owner = "brunoos";
-      repo = "luasec";
-      rev = "lua${name}";
-      sha256 = "1cgb7ihnrrfr59a2da4d3chr7lqpid98xpglmzhv3hrpg4x5sksz";
-    };
-
-    propagatedBuildInputs = [ luasocket ];
-    buildInputs = [ openssl ];
-
-    preBuild = ''
-      makeFlagsArray=(
-        ${platformString}
-        LUAPATH="$out/share/lua/${lua.luaversion}"
-        LUACPATH="$out/lib/lua/${lua.luaversion}"
-        INC_PATH="-I${lua}/include"
-        LIB_PATH="-L$out/lib");
-    '';
-
-    meta = with stdenv.lib; {
-      description = "Lua binding for OpenSSL library to provide TLS/SSL communication";
-      homepage = "https://github.com/brunoos/luasec";
-      license = licenses.mit;
-      maintainers = with maintainers; [ flosse ];
-      platforms = platforms.unix;
-    };
-  };
-
-  luasocket = buildLuaPackage rec {
-    name = "socket-${version}";
-    version = "3.0-rc1";
-
-    src = fetchFromGitHub {
-      owner = "diegonehab";
-      repo = "luasocket";
-      rev = "v${version}";
-      sha256 = "1chs7z7a3i3lck4x7rz60ziwbf793gw169hpjdfca8y4yf1hzsxk";
-    };
-
-    patchPhase = stdenv.lib.optionalString stdenv.isDarwin ''
-      substituteInPlace src/makefile \
-        --replace 10.3 10.5
-    '';
-
-    preBuild = ''
-      makeFlagsArray=(
-        LUAV=${lua.luaversion}
-        PLAT=${platformString}
-        CC=''${CC}
-        LD=''${CC}
-        prefix=$out
-      );
-    '';
-
-    doCheck = false; # fails to find itself
-
-    installTargets = [ "install" "install-unix" ];
-
-    meta = with stdenv.lib; {
-      description = "Network support for Lua";
-      homepage = "http://w3.impa.br/~diego/software/luasocket/";
-      license = licenses.mit;
-      maintainers = with maintainers; [ ];
-      platforms = with platforms; darwin ++ linux ++ freebsd ++ illumos;
-    };
-  };
-
   luxio = buildLuaPackage rec {
     name = "luxio-${version}";
     version = "13";
@@ -452,115 +131,6 @@ with self; {
     };
   };
 
-
-  luastdlib = buildLuaPackage rec {
-    name = "stdlib-${version}";
-    version = "41.2.1";
-
-    src = fetchFromGitHub {
-      owner = "lua-stdlib";
-      repo = "lua-stdlib";
-      rev = "release-v${version}";
-      sha256 = "03wd1qvkrj50fjszb2apzdkc8d5bpfbbi9pajl0vbrlzzmmi3jlq";
-    };
-
-    nativeBuildInputs = [ autoreconfHook unzip ];
-
-    meta = with stdenv.lib; {
-      description = "General Lua libraries";
-      homepage = "https://github.com/lua-stdlib/lua-stdlib";
-      license = licenses.mit;
-      maintainers = with maintainers; [ vyp ];
-      platforms = platforms.linux;
-    };
-  };
-
-  lrexlib = buildLuaPackage rec {
-    name = "lrexlib-${version}";
-    version = "2.8.0";
-
-    src = fetchFromGitHub {
-      owner = "rrthomas";
-      repo = "lrexlib";
-      rev = "rel-2-8-0";
-      sha256 = "1c62ny41b1ih6iddw5qn81gr6dqwfffzdp7q6m8x09zzcdz78zhr";
-    };
-
-    buildInputs = [ luastdlib pcre luarocks oniguruma gnulib tre glibc ];
-
-    buildPhase = let
-      luaVariable = ''LUA_PATH="${luastdlib}/share/lua/${lua.luaversion}/?/init.lua;${luastdlib}/share/lua/${lua.luaversion}/?.lua"'';
-      pcreVariable = "PCRE_DIR=${pcre.out} PCRE_INCDIR=${pcre.dev}/include";
-      onigVariable = "ONIG_DIR=${oniguruma}";
-      gnuVariable = "GNU_INCDIR=${gnulib}/lib";
-      treVariable = "TRE_DIR=${tre}";
-      posixVariable = "POSIX_DIR=${glibc.dev}";
-    in ''
-      sed -e 's@$(LUAROCKS) $(LUAROCKS_COMMAND) $$i;@$(LUAROCKS) $(LUAROCKS_COMMAND) $$i ${pcreVariable} ${onigVariable} ${gnuVariable} ${treVariable} ${posixVariable};@' -i Makefile
-      ${luaVariable} make
-    '';
-
-    installPhase = ''
-      mkdir -pv $out;
-      cp -r luarocks/lib $out;
-    '';
-
-    meta = with stdenv.lib; {
-      description = "Lua bindings of various regex library APIs";
-      homepage = "https://github.com/rrthomas/lrexlib";
-      license = licenses.mit;
-      maintainers = with maintainers; [ vyp ];
-      platforms = platforms.linux;
-    };
-  };
-
-  luasqlite3 = buildLuaPackage rec {
-    name = "sqlite3-${version}";
-    version = "2.3.0";
-
-    src = fetchFromGitHub {
-      owner = "LuaDist";
-      repo = "luasql-sqlite3";
-      rev = version;
-      sha256 = "05k8zs8nsdmlwja3hdhckwknf7ww5cvbp3sxhk2xd1i3ij6aa10b";
-    };
-
-    disabled = isLua53;
-
-    buildInputs = [ sqlite ];
-
-    patches = [ ../development/lua-modules/luasql.patch ];
-
-    meta = with stdenv.lib; {
-      description = "Database connectivity for Lua";
-      homepage = "https://github.com/LuaDist/luasql-sqlite3";
-      license = licenses.mit;
-      maintainers = with maintainers; [ vyp ];
-      platforms = platforms.linux;
-    };
-  };
-
-  lfs = buildLuaPackage rec {
-    name = "lfs-${version}";
-    version = "1.7.0.2";
-
-    src = fetchFromGitHub {
-      owner = "keplerproject";
-      repo = "luafilesystem";
-      rev = "v" + stdenv.lib.replaceStrings ["."] ["_"] version;
-      sha256 = "0zmprgkm9zawdf9wnw0v3w6ibaj442wlc6alp39hmw610fl4vghi";
-    };
-
-    meta = with stdenv.lib; {
-      description = "Portable library for filesystem operations";
-      homepage = https://keplerproject.github.com/luafilesystem;
-      license = licenses.mit;
-      maintainers = with maintainers; [ vcunat ];
-      platforms = platforms.all;
-    };
-  };
-
-
   vicious = toLuaModule(stdenv.mkDerivation rec {
     name = "vicious-${version}";
     version = "2.3.1";