diff options
author | Alyssa Ross <hi@alyssa.is> | 2021-08-04 10:43:07 +0000 |
---|---|---|
committer | Alyssa Ross <hi@alyssa.is> | 2021-08-04 10:43:07 +0000 |
commit | 62614cbef7da005c1eda8c9400160f6bcd6546b8 (patch) | |
tree | c2630f69080637987b68acb1ee8676d2681fe304 /pkgs/development/tools/build-managers/rebar3/default.nix | |
parent | d9c82ed3044c72cecf01c6ea042489d30914577c (diff) | |
parent | e24069138dfec3ef94f211f1da005bb5395adc11 (diff) | |
download | nixpkgs-62614cbef7da005c1eda8c9400160f6bcd6546b8.tar nixpkgs-62614cbef7da005c1eda8c9400160f6bcd6546b8.tar.gz nixpkgs-62614cbef7da005c1eda8c9400160f6bcd6546b8.tar.bz2 nixpkgs-62614cbef7da005c1eda8c9400160f6bcd6546b8.tar.lz nixpkgs-62614cbef7da005c1eda8c9400160f6bcd6546b8.tar.xz nixpkgs-62614cbef7da005c1eda8c9400160f6bcd6546b8.tar.zst nixpkgs-62614cbef7da005c1eda8c9400160f6bcd6546b8.zip |
Merge branch 'nixpkgs-update' into master
Diffstat (limited to 'pkgs/development/tools/build-managers/rebar3/default.nix')
-rw-r--r-- | pkgs/development/tools/build-managers/rebar3/default.nix | 266 |
1 files changed, 139 insertions, 127 deletions
diff --git a/pkgs/development/tools/build-managers/rebar3/default.nix b/pkgs/development/tools/build-managers/rebar3/default.nix index 5c0fff134a7..3b775eeaef1 100644 --- a/pkgs/development/tools/build-managers/rebar3/default.nix +++ b/pkgs/development/tools/build-managers/rebar3/default.nix @@ -1,135 +1,147 @@ -{ stdenv, fetchFromGitHub, - fetchHex, erlang, - tree }: +{ lib, stdenv, fetchFromGitHub, + fetchHex, erlang, makeWrapper, + writeScript, common-updater-scripts, coreutils, git, gnused, nix, rebar3-nix }: let - version = "3.12.0"; + version = "3.16.1"; + owner = "erlang"; + deps = import ./rebar-deps.nix { inherit fetchFromGitHub fetchHex; }; + rebar3 = stdenv.mkDerivation rec { + pname = "rebar3"; + inherit version erlang; - erlware_commons = fetchHex { - pkg = "erlware_commons"; - version = "1.3.1"; - sha256 = "7aada93f368d0a0430122e39931b7fb4ac9e94dbf043cdc980ad4330fd9cd166"; - }; - ssl_verify_fun = fetchHex { - pkg = "ssl_verify_fun"; - version = "1.1.3"; - sha256 = "2e120e6505d6e9ededb2836611dfe2f7028432dc280957998e154307b5ea92fe"; - }; - certifi = fetchHex { - pkg = "certifi"; - version = "2.3.1"; - sha256 = "e12d667d042c11d130594bae2b0097e63836fe8b1e6d6b2cc48f8bb7a2cf7d68"; - }; - providers = fetchHex { - pkg = "providers"; - version = "1.7.0"; - sha256 = "8be66129ca85c2fa74efd8737cdaedd31c1c1af51dd2fd601495a6def4cae4a6"; - }; - getopt = fetchHex { - pkg = "getopt"; - version = "1.0.1"; - sha256 = "53e1ab83b9ceb65c9672d3e7a35b8092e9bdc9b3ee80721471a161c10c59959c"; - }; - bbmustache = fetchHex { - pkg = "bbmustache"; - version = "1.6.0"; - sha256 = "53e02d296512a57be03a98c91541b34d2ca64930268030b2d12364a0332015df"; - }; - relx = fetchHex { - pkg = "relx"; - version = "3.28.0"; - sha256 = "8afb871c0a2a27f0063d973903fc64d2207bc705ecc3607462920683d24ac7b5"; - }; - cf = fetchHex { - pkg = "cf"; - version = "0.2.2"; - sha256 = "08cvy7skn5d2k4manlx5k3anqgjdvajjhc5jwxbaszxw34q3na28"; - }; - cth_readable = fetchHex { - pkg = "cth_readable"; - version = "1.4.3"; - sha256 = "0wr0hba6ka74s3628jrrd7ynjdh7syxigkh7ildg8fgi20ab88fd"; - }; - eunit_formatters = fetchHex { - pkg = "eunit_formatters"; - version = "0.5.0"; - sha256 = "1jb3hzb216r29x2h4pcjwfmx1k81431rgh5v0mp4x5146hhvmj6n"; - }; - hex_core = fetchHex { - pkg = "hex_core"; - version = "0.4.0"; - sha256 = "8ace8c6cfa10df4cb8be876f42f7446890e124203c094cc7b4e7616fb8de5d7f"; - }; - parse_trans = fetchHex { - pkg = "parse_trans"; - version = "3.3.0"; - sha256 = "0q5r871bzx1a8fa06yyxdi3xkkp7v5yqazzah03d6yl3vsmn7vqp"; - }; + # 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; + sha256 = "0dhwlx7zykf9y3znk2k8fxrq5j43jy3c3gd76k74q34p1xbajgzr"; + }; -in -stdenv.mkDerivation rec { - pname = "rebar3"; - inherit version erlang; + buildInputs = [ erlang ]; - src = fetchFromGitHub { - owner = "erlang"; - repo = pname; - rev = version; - sha256 = "0936ix7lfwsamssap58b265zid7x2m97azrr2qpjcln3xysd16lg"; - }; + postPatch = '' + mkdir -p _checkouts _build/default/lib/ - bootstrapper = ./rebar3-nix-bootstrap; - - buildInputs = [ erlang tree ]; - - postPatch = '' - mkdir -p _checkouts - mkdir -p _build/default/lib/ - - cp --no-preserve=mode -R ${erlware_commons} _checkouts/erlware_commons - cp --no-preserve=mode -R ${providers} _checkouts/providers - cp --no-preserve=mode -R ${getopt} _checkouts/getopt - cp --no-preserve=mode -R ${bbmustache} _checkouts/bbmustache - cp --no-preserve=mode -R ${certifi} _checkouts/certifi - cp --no-preserve=mode -R ${cf} _checkouts/cf - cp --no-preserve=mode -R ${cth_readable} _checkouts/cth_readable - cp --no-preserve=mode -R ${eunit_formatters} _checkouts/eunit_formatters - cp --no-preserve=mode -R ${relx} _checkouts/relx - cp --no-preserve=mode -R ${ssl_verify_fun} _checkouts/ssl_verify_fun - cp --no-preserve=mode -R ${hex_core} _checkouts/hex_core - cp --no-preserve=mode -R ${parse_trans} _checkouts/parse_trans - - # 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 - ''; - - 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). - ''; + ${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 + ''; - platforms = stdenv.lib.platforms.unix; - maintainers = with stdenv.lib.maintainers; [ gleber tazjin ]; - license = stdenv.lib.licenses.asl20; + buildPhase = '' + HOME=. escript bootstrap + ''; + + + patches = [] + # Skips test that can write outside the designated tmp directory, potentially resulting in build failures + # due to file ownership issues if ran without sandbox (eg. Mac M1 default). This patch can be Removed when + # rebar3 releases with the following commit: + # https://github.com/erlang/rebar3/commit/11055384dbd5bf7d181bca83a33b0e100275ff21 + ++ lib.optionals (stdenv.isDarwin && stdenv.isAarch64) [ ./tmp-tests-skip.patch ]; + + checkPhase = '' + HOME=. escript ./rebar3 ct + ''; + + doCheck = true; + + 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 + ''; }; -} + 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 ]; + + # our patches cause the tests to fail + doCheck = false; + })); + 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) + ' + cp ${./rebar_ignore_deps.erl} rebar_ignore_deps.erl + erlc -o $out/lib/rebar/ebin rebar_ignore_deps.erl + mkdir -p $out/bin + makeWrapper ${erlang}/bin/erl $out/bin/rebar3 \ + --set REBAR_GLOBAL_PLUGINS "${toString globalPluginNames} rebar_ignore_deps" \ + --suffix-each ERL_LIBS ":" "$out/lib ${toString pluginLibDirs}" \ + --add-flags "+sbtu +A1 -noshell -boot start_clean -s rebar3 main -extra" + ''; + }; +in { inherit rebar3 rebar3WithPlugins; } |