2021-08-05 21:33:18 +00:00
|
|
|
{ lib, stdenv, fetchFromGitHub, fetchpatch,
|
2021-05-20 23:08:51 +00:00
|
|
|
fetchHex, erlang, makeWrapper,
|
|
|
|
writeScript, common-updater-scripts, coreutils, git, gnused, nix, rebar3-nix }:
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
let
|
2021-05-28 09:39:13 +00:00
|
|
|
version = "3.16.1";
|
2021-05-20 23:08:51 +00:00
|
|
|
owner = "erlang";
|
|
|
|
deps = import ./rebar-deps.nix { inherit fetchFromGitHub fetchHex; };
|
|
|
|
rebar3 = stdenv.mkDerivation rec {
|
|
|
|
pname = "rebar3";
|
|
|
|
inherit version erlang;
|
|
|
|
|
|
|
|
# How to obtain `sha256`:
|
|
|
|
# nix-prefetch-url --unpack https://github.com/erlang/rebar3/archive/${version}.tar.gz
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
inherit owner;
|
|
|
|
repo = pname;
|
|
|
|
rev = version;
|
2021-05-28 09:39:13 +00:00
|
|
|
sha256 = "0dhwlx7zykf9y3znk2k8fxrq5j43jy3c3gd76k74q34p1xbajgzr";
|
2021-05-20 23:08:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
buildInputs = [ erlang ];
|
|
|
|
|
|
|
|
postPatch = ''
|
|
|
|
mkdir -p _checkouts _build/default/lib/
|
|
|
|
|
|
|
|
${toString (lib.mapAttrsToList (k: v: ''
|
|
|
|
cp -R --no-preserve=mode ${v} _checkouts/${k}
|
|
|
|
'') deps)}
|
|
|
|
|
|
|
|
# Bootstrap script expects the dependencies in _build/default/lib
|
|
|
|
# TODO: Make it accept checkouts?
|
|
|
|
for i in _checkouts/* ; do
|
|
|
|
ln -s $(pwd)/$i $(pwd)/_build/default/lib/
|
|
|
|
done
|
|
|
|
'';
|
|
|
|
|
|
|
|
buildPhase = ''
|
|
|
|
HOME=. escript bootstrap
|
|
|
|
'';
|
|
|
|
|
2021-07-14 22:03:04 +00:00
|
|
|
|
2021-08-05 21:33:18 +00:00
|
|
|
patches = [
|
|
|
|
# TODO: remove this on next rebar3 release
|
|
|
|
(fetchpatch {
|
|
|
|
name = "escriptize-erl-libs";
|
|
|
|
url = "https://github.com/erlang/rebar3/commit/11055384dbd5bf7d181bca83a33b0e100275ff21.patch";
|
|
|
|
sha256 = "01xjaqnhmjlxqdgb8ph15wssjq5crdhjslxnndbs5f0kscqpq14c";
|
|
|
|
})
|
|
|
|
];
|
2021-07-14 22:03:04 +00:00
|
|
|
|
2021-06-28 23:13:55 +00:00
|
|
|
checkPhase = ''
|
|
|
|
HOME=. escript ./rebar3 ct
|
|
|
|
'';
|
|
|
|
|
|
|
|
doCheck = true;
|
|
|
|
|
2021-05-20 23:08:51 +00:00
|
|
|
installPhase = ''
|
|
|
|
mkdir -p $out/bin
|
|
|
|
cp rebar3 $out/bin/rebar3
|
|
|
|
'';
|
|
|
|
|
|
|
|
meta = {
|
|
|
|
homepage = "https://github.com/rebar/rebar3";
|
|
|
|
description = "Erlang build tool that makes it easy to compile and test Erlang applications, port drivers and releases";
|
|
|
|
|
|
|
|
longDescription = ''
|
|
|
|
rebar is a self-contained Erlang script, so it's easy to distribute or
|
|
|
|
even embed directly in a project. Where possible, rebar uses standard
|
|
|
|
Erlang/OTP conventions for project structures, thus minimizing the amount
|
|
|
|
of build configuration work. rebar also provides dependency management,
|
|
|
|
enabling application writers to easily re-use common libraries from a
|
|
|
|
variety of locations (hex.pm, git, hg, and so on).
|
|
|
|
'';
|
|
|
|
|
|
|
|
platforms = lib.platforms.unix;
|
|
|
|
maintainers = lib.teams.beam.members;
|
|
|
|
license = lib.licenses.asl20;
|
|
|
|
};
|
|
|
|
|
|
|
|
passthru.updateScript = writeScript "update.sh" ''
|
|
|
|
#!${stdenv.shell}
|
|
|
|
set -ox errexit
|
|
|
|
PATH=${
|
|
|
|
lib.makeBinPath [
|
|
|
|
common-updater-scripts
|
|
|
|
coreutils
|
|
|
|
git
|
|
|
|
gnused
|
|
|
|
nix
|
|
|
|
(rebar3WithPlugins { globalPlugins = [rebar3-nix]; })
|
|
|
|
]
|
|
|
|
}
|
|
|
|
latest=$(list-git-tags https://github.com/${owner}/${pname}.git | sed -n '/[\d\.]\+/p' | sort -V | tail -1)
|
|
|
|
if [ "$latest" != "${version}" ]; then
|
|
|
|
nixpkgs="$(git rev-parse --show-toplevel)"
|
|
|
|
nix_path="$nixpkgs/pkgs/development/tools/build-managers/rebar3"
|
|
|
|
update-source-version rebar3 "$latest" --version-key=version --print-changes --file="$nix_path/default.nix"
|
|
|
|
tmpdir=$(mktemp -d)
|
|
|
|
cp -R $(nix-build $nixpkgs --no-out-link -A rebar3.src)/* "$tmpdir"
|
|
|
|
(cd "$tmpdir" && rebar3 nix lock -o "$nix_path/rebar-deps.nix")
|
|
|
|
else
|
|
|
|
echo "rebar3 is already up-to-date"
|
|
|
|
fi
|
|
|
|
'';
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
2021-05-20 23:08:51 +00:00
|
|
|
rebar3WithPlugins = { plugins ? [ ], globalPlugins ? [ ] }:
|
|
|
|
let
|
|
|
|
pluginLibDirs = map (p: "${p}/lib/erlang/lib") (lib.unique (plugins ++ globalPlugins));
|
|
|
|
globalPluginNames = lib.unique (map (p: p.packageName) globalPlugins);
|
|
|
|
rebar3Patched = (rebar3.overrideAttrs (old: {
|
|
|
|
|
|
|
|
# skip-plugins.patch is necessary because otherwise rebar3 will always
|
|
|
|
# try to fetch plugins if they are not already present in _build.
|
|
|
|
#
|
|
|
|
# global-deps.patch makes it possible to use REBAR_GLOBAL_PLUGINS to
|
|
|
|
# instruct rebar3 to always load a certain plugin. It is necessary since
|
|
|
|
# REBAR_GLOBAL_CONFIG_DIR doesn't seem to work for this.
|
|
|
|
patches = [ ./skip-plugins.patch ./global-plugins.patch ];
|
2021-06-28 23:13:55 +00:00
|
|
|
|
|
|
|
# our patches cause the tests to fail
|
|
|
|
doCheck = false;
|
2021-05-20 23:08:51 +00:00
|
|
|
}));
|
|
|
|
in stdenv.mkDerivation {
|
|
|
|
pname = "rebar3-with-plugins";
|
|
|
|
inherit (rebar3) version;
|
|
|
|
nativeBuildInputs = [ erlang makeWrapper ];
|
|
|
|
unpackPhase = "true";
|
|
|
|
|
|
|
|
# Here we extract the rebar3 escript (like `rebar3_prv_local_install.erl`) and
|
|
|
|
# add plugins to the code path.
|
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
erl -noshell -eval '
|
|
|
|
{ok, Escript} = escript:extract("${rebar3Patched}/bin/rebar3", []),
|
|
|
|
{archive, Archive} = lists:keyfind(archive, 1, Escript),
|
|
|
|
{ok, _} = zip:extract(Archive, [{cwd, "'$out/lib'"}]),
|
|
|
|
init:stop(0)
|
|
|
|
'
|
2021-06-28 23:13:55 +00:00
|
|
|
cp ${./rebar_ignore_deps.erl} rebar_ignore_deps.erl
|
|
|
|
erlc -o $out/lib/rebar/ebin rebar_ignore_deps.erl
|
2021-05-20 23:08:51 +00:00
|
|
|
mkdir -p $out/bin
|
|
|
|
makeWrapper ${erlang}/bin/erl $out/bin/rebar3 \
|
2021-06-28 23:13:55 +00:00
|
|
|
--set REBAR_GLOBAL_PLUGINS "${toString globalPluginNames} rebar_ignore_deps" \
|
2021-05-20 23:08:51 +00:00
|
|
|
--suffix-each ERL_LIBS ":" "$out/lib ${toString pluginLibDirs}" \
|
|
|
|
--add-flags "+sbtu +A1 -noshell -boot start_clean -s rebar3 main -extra"
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
2021-05-20 23:08:51 +00:00
|
|
|
};
|
|
|
|
in { inherit rebar3 rebar3WithPlugins; }
|