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/beam-modules/rebar3-release.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/beam-modules/rebar3-release.nix')
-rw-r--r-- | pkgs/development/beam-modules/rebar3-release.nix | 153 |
1 files changed, 89 insertions, 64 deletions
diff --git a/pkgs/development/beam-modules/rebar3-release.nix b/pkgs/development/beam-modules/rebar3-release.nix index 1ec9f244d6c..59771c34029 100644 --- a/pkgs/development/beam-modules/rebar3-release.nix +++ b/pkgs/development/beam-modules/rebar3-release.nix @@ -1,83 +1,108 @@ -{ stdenv, writeText, erlang, rebar3, openssl, - lib }: +{ stdenv +, erlang +, rebar3WithPlugins +, openssl +, lib +}: -{ name, version +{ pname +, version , src +, beamDeps ? [ ] +, buildPlugins ? [ ] , checkouts ? null , releaseType -, buildInputs ? [] +, buildInputs ? [ ] , setupHook ? null , profile ? "default" , installPhase ? null , buildPhase ? null , configurePhase ? null -, meta ? {} -, enableDebugInfo ? false -, ... }@attrs: +, meta ? { } +, ... +}@attrs: -with stdenv.lib; +with lib; let shell = drv: stdenv.mkDerivation { - name = "interactive-shell-${drv.name}"; - buildInputs = [ drv ]; - }; + name = "interactive-shell-${drv.pname}"; + buildInputs = [ drv ]; + }; customPhases = filterAttrs (_: v: v != null) { inherit setupHook configurePhase buildPhase installPhase; }; - pkg = self: stdenv.mkDerivation (attrs // { - - name = "${name}-${version}"; - inherit version; - - buildInputs = buildInputs ++ [ erlang rebar3 openssl ]; - propagatedBuildInputs = [checkouts]; - - dontStrip = true; - - inherit src; - - setupHook = writeText "setupHook.sh" '' - addToSearchPath ERL_LIBS "$1/lib/erlang/lib/" - ''; - - configurePhase = '' - runHook preConfigure - ${if checkouts != null then - ''cp --no-preserve=all -R ${checkouts}/_checkouts .'' - else - ''''} - runHook postConfigure - ''; - - buildPhase = '' - runHook preBuild - HOME=. DEBUG=1 rebar3 as ${profile} ${if releaseType == "escript" - then '' escriptize'' - else '' release''} - runHook postBuild - ''; - - installPhase = '' - runHook preInstall - dir=${if releaseType == "escript" - then ''bin'' - else ''rel''} - mkdir -p "$out/$dir" - cp -R --preserve=mode "_build/${profile}/$dir" "$out" - runHook postInstall - ''; - - meta = { - inherit (erlang.meta) platforms; - } // meta; - - passthru = { - packageName = name; - env = shell self; - }; - } // customPhases); + # When using the `beamDeps` argument, it is important that we use + # `rebar3WithPlugins` here even when there are no plugins. The vanilla + # `rebar3` package is an escript archive with bundled dependencies which can + # interfere with those in the app we are trying to build. `rebar3WithPlugins` + # doesn't have this issue since it puts its own deps last on the code path. + rebar3 = rebar3WithPlugins { + plugins = buildPlugins; + }; + + pkg = + assert beamDeps != [ ] -> checkouts == null; + self: stdenv.mkDerivation (attrs // { + + name = "${pname}-${version}"; + inherit version pname; + + buildInputs = buildInputs ++ [ erlang rebar3 openssl ] ++ beamDeps; + + # ensure we strip any native binaries (eg. NIFs, ports) + stripDebugList = lib.optional (releaseType == "release") "rel"; + + inherit src; + + REBAR_IGNORE_DEPS = beamDeps != [ ]; + + configurePhase = '' + runHook preConfigure + ${lib.optionalString (checkouts != null) + "cp --no-preserve=all -R ${checkouts}/_checkouts ."} + runHook postConfigure + ''; + + buildPhase = '' + runHook preBuild + HOME=. DEBUG=1 rebar3 as ${profile} ${if releaseType == "escript" + then "escriptize" + else "release"} + runHook postBuild + ''; + + installPhase = '' + runHook preInstall + dir=${if releaseType == "escript" + then "bin" + else "rel"} + mkdir -p "$out/$dir" "$out/bin" + cp -R --preserve=mode "_build/${profile}/$dir" "$out" + ${lib.optionalString (releaseType == "release") + "find $out/rel/*/bin -type f -executable -exec ln -s -t $out/bin {} \\;"} + runHook postInstall + ''; + + postInstall = '' + for dir in $out/rel/*/erts-*; do + echo "ERTS found in $dir - removing references to erlang to reduce closure size" + for f in $dir/bin/{erl,start}; do + substituteInPlace "$f" --replace "${erlang}/lib/erlang" "''${dir/\/erts-*/}" + done + done + ''; + + meta = { + inherit (erlang.meta) platforms; + } // meta; + + passthru = ({ + packageName = pname; + env = shell self; + } // (if attrs ? passthru then attrs.passthru else { })); + } // customPhases); in - fix pkg +fix pkg |