Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lua/luarocks packaging improvements #63108

Merged
merged 9 commits into from
Jun 19, 2019
40 changes: 28 additions & 12 deletions maintainers/scripts/luarocks-packages.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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
teto marked this conversation as resolved.
Show resolved Hide resolved
cyrussasl,,,,,vcunat
digestif,,http://luarocks.org/dev,,lua5_3,
dkjson,,,,,
fifo,,,,,
http,,,,,
http,,,,,vcunat
inspect,,,,,
ldoc,,,,,
lgi,,,,,
Expand All @@ -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
100 changes: 58 additions & 42 deletions maintainers/scripts/update-luarocks-packages
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env nix-shell
#!nix-shell -p nix-prefetch-scripts luarocks-nix -i bash
#!nix-shell -p parallel nix-prefetch-scripts luarocks-nix -i bash
Shados marked this conversation as resolved.
Show resolved Hide resolved

# You'll likely want to use
# ``
Expand All @@ -8,17 +8,15 @@
# 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)"

exit_trap()
{
local lc="$BASH_COMMAND" rc=$?
test $rc -eq 0 || echo -e "*** error $rc: $lc.\nGenerated temporary file in $TMP_FILE" >&2
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() {
Expand All @@ -37,19 +35,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"
Expand All @@ -72,43 +70,61 @@ 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
luarocks_args+=("--lua-dir=$(nix path-info "nixpkgs.$lua_version")/bin")
Shados marked this conversation as resolved.
Show resolved Hide resolved
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" | tee -a "$TMP_FILE"
Shados marked this conversation as resolved.
Show resolved Hide resolved
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"
export -f convert_pkg
export SHELL=bash
# Read each line in the csv file and run convert_pkg for each, in parallel
# 10 is a pretty arbitrary number of simultaneous jobs, but it is generally
# impolite to hit a webserver with *too* many simultaneous connections :)
parallel --group --keep-order --halt now,fail=1 --jobs 10 --colsep ',' convert_pkg {} <"$CSV_FILE" | tee -a "$TMP_FILE"
Shados marked this conversation as resolved.
Show resolved Hide resolved

# close the set
echo "$FOOTER" | tee -a "$TMP_FILE"

cp "$TMP_FILE" "$GENERATED_NIXFILE"

# vim: set ts=4 sw=4 ft=sh:
25 changes: 10 additions & 15 deletions pkgs/applications/networking/browsers/luakit/default.nix
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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
Expand All @@ -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 = [
Expand All @@ -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"
)
'';

Expand Down
Loading