2019-02-04 12:30:58 +01:00
|
|
|
#!/usr/bin/env nix-shell
|
2019-06-14 07:17:52 +02:00
|
|
|
#!nix-shell update-luarocks-shell.nix -i bash
|
2019-02-04 12:30:58 +01:00
|
|
|
|
|
|
|
# You'll likely want to use
|
|
|
|
# ``
|
|
|
|
# nixpkgs $ maintainers/scripts/update-luarocks-packages pkgs/development/lua-modules/generated-packages.nix
|
|
|
|
# ``
|
|
|
|
# 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)"
|
2019-06-14 07:17:52 +02:00
|
|
|
# Set in the update-luarocks-shell.nix
|
|
|
|
NIXPKGS_PATH="$LUAROCKS_NIXPKGS_PATH"
|
2019-09-07 12:55:30 +02:00
|
|
|
export LUAROCKS_CONFIG="$NIXPKGS_PATH/maintainers/scripts/luarocks-config.lua"
|
2019-06-14 07:17:52 +02:00
|
|
|
|
|
|
|
# 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
|
2019-02-04 12:30:58 +01:00
|
|
|
|
2019-06-13 12:00:00 +02:00
|
|
|
exit_trap() {
|
|
|
|
local lc="$BASH_COMMAND" rc=$?
|
|
|
|
test $rc -eq 0 || echo -e "*** error $rc: $lc.\nGenerated temporary file in $TMP_FILE" >&2
|
2019-02-04 12:30:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
print_help() {
|
|
|
|
echo "Usage: $0 <GENERATED_FILE>"
|
|
|
|
echo "(most likely pkgs/development/lua-modules/generated-packages.nix)"
|
2019-06-04 11:06:08 +02:00
|
|
|
echo ""
|
|
|
|
echo " -c <CSV_FILE> to set the list of luarocks package to generate"
|
|
|
|
exit 1
|
2019-02-04 12:30:58 +01:00
|
|
|
}
|
|
|
|
|
2019-06-04 11:06:08 +02:00
|
|
|
if [ $# -lt 1 ]; then
|
|
|
|
print_help
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
trap exit_trap EXIT
|
2019-02-04 12:30:58 +01:00
|
|
|
|
|
|
|
while getopts ":hc:" opt; do
|
2019-06-13 12:00:00 +02:00
|
|
|
case $opt in
|
2019-02-04 12:30:58 +01:00
|
|
|
h)
|
2019-06-13 12:00:00 +02:00
|
|
|
print_help
|
|
|
|
;;
|
2019-02-04 12:30:58 +01:00
|
|
|
c)
|
2019-06-13 12:00:00 +02:00
|
|
|
echo "Loading package list from $OPTARG !" >&2
|
|
|
|
CSV_FILE="$OPTARG"
|
|
|
|
;;
|
2019-02-04 12:30:58 +01:00
|
|
|
\?)
|
2019-06-13 12:00:00 +02:00
|
|
|
echo "Invalid option: -$OPTARG" >&2
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift $((OPTIND - 1))
|
2019-02-04 12:30:58 +01:00
|
|
|
done
|
|
|
|
|
|
|
|
GENERATED_NIXFILE="$1"
|
|
|
|
|
|
|
|
HEADER="
|
|
|
|
/* ${GENERATED_NIXFILE} is an auto-generated file -- DO NOT EDIT!
|
|
|
|
Regenerate it with:
|
|
|
|
nixpkgs$ ${0} ${GENERATED_NIXFILE}
|
|
|
|
|
|
|
|
These packages are manually refined in lua-overrides.nix
|
|
|
|
*/
|
2019-02-26 06:51:42 +01:00
|
|
|
{ self, stdenv, fetchurl, fetchgit, pkgs, ... } @ args:
|
2019-02-04 12:30:58 +01:00
|
|
|
self: super:
|
|
|
|
with self;
|
|
|
|
{
|
|
|
|
"
|
|
|
|
|
|
|
|
FOOTER="
|
|
|
|
}
|
|
|
|
/* GENERATED */
|
|
|
|
"
|
|
|
|
|
2019-06-13 12:00:00 +02:00
|
|
|
function convert_pkg() {
|
2019-03-07 08:58:54 +01:00
|
|
|
nix_pkg_name="$1"
|
|
|
|
lua_pkg_name="$2"
|
2019-06-13 12:00:00 +02:00
|
|
|
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
|
2019-06-14 07:17:52 +02:00
|
|
|
lua_drv_path=$(nix-build --no-out-link "$NIXPKGS_PATH" -A "$lua_version")
|
|
|
|
luarocks_args+=("--lua-dir=$lua_drv_path/bin")
|
2019-06-13 12:00:00 +02:00
|
|
|
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"
|
2019-02-04 12:30:58 +01:00
|
|
|
else
|
2019-06-13 12:00:00 +02:00
|
|
|
echo "Failed to convert $nix_pkg_name" >&2
|
|
|
|
return 1
|
2019-02-04 12:30:58 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# params needed when called via callPackage
|
|
|
|
echo "$HEADER" | tee "$TMP_FILE"
|
|
|
|
|
2019-06-14 07:17:52 +02:00
|
|
|
# Ensure parallel can run our bash function
|
2019-06-13 12:00:00 +02:00
|
|
|
export -f convert_pkg
|
|
|
|
export SHELL=bash
|
|
|
|
# Read each line in the csv file and run convert_pkg for each, in parallel
|
2019-06-14 07:17:52 +02:00
|
|
|
parallel --group --keep-order --halt now,fail=1 --jobs "$PARALLEL_JOBS" --colsep ',' convert_pkg {} <"$CSV_FILE" | tee -a "$TMP_FILE"
|
2019-02-04 12:30:58 +01:00
|
|
|
|
|
|
|
# close the set
|
|
|
|
echo "$FOOTER" | tee -a "$TMP_FILE"
|
|
|
|
|
|
|
|
cp "$TMP_FILE" "$GENERATED_NIXFILE"
|
2019-06-13 12:00:00 +02:00
|
|
|
|
|
|
|
# vim: set ts=4 sw=4 ft=sh:
|