Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at netboot-syslinux-multiplatform 106 lines 2.9 kB view raw
1{ stdenv 2, erlang 3, rebar3WithPlugins 4, openssl 5, lib 6}: 7 8{ pname 9, version 10, src 11, beamDeps ? [ ] 12, buildPlugins ? [ ] 13, checkouts ? null 14, releaseType 15, buildInputs ? [ ] 16, setupHook ? null 17, profile ? "default" 18, installPhase ? null 19, buildPhase ? null 20, configurePhase ? null 21, meta ? { } 22, ... 23}@attrs: 24 25let 26 shell = drv: stdenv.mkDerivation { 27 name = "interactive-shell-${drv.pname}"; 28 buildInputs = [ drv ]; 29 }; 30 31 customPhases = lib.filterAttrs 32 (_: v: v != null) 33 { inherit setupHook configurePhase buildPhase installPhase; }; 34 35 # When using the `beamDeps` argument, it is important that we use 36 # `rebar3WithPlugins` here even when there are no plugins. The vanilla 37 # `rebar3` package is an escript archive with bundled dependencies which can 38 # interfere with those in the app we are trying to build. `rebar3WithPlugins` 39 # doesn't have this issue since it puts its own deps last on the code path. 40 rebar3 = rebar3WithPlugins { 41 plugins = buildPlugins; 42 }; 43 44 pkg = 45 assert beamDeps != [ ] -> checkouts == null; 46 self: stdenv.mkDerivation (attrs // { 47 48 name = "${pname}-${version}"; 49 inherit version pname; 50 51 buildInputs = buildInputs ++ [ erlang rebar3 openssl ] ++ beamDeps; 52 53 # ensure we strip any native binaries (eg. NIFs, ports) 54 stripDebugList = lib.optional (releaseType == "release") "rel"; 55 56 inherit src; 57 58 REBAR_IGNORE_DEPS = beamDeps != [ ]; 59 60 configurePhase = '' 61 runHook preConfigure 62 ${lib.optionalString (checkouts != null) 63 "cp --no-preserve=all -R ${checkouts}/_checkouts ."} 64 runHook postConfigure 65 ''; 66 67 buildPhase = '' 68 runHook preBuild 69 HOME=. DEBUG=1 rebar3 as ${profile} ${if releaseType == "escript" 70 then "escriptize" 71 else "release"} 72 runHook postBuild 73 ''; 74 75 installPhase = '' 76 runHook preInstall 77 dir=${if releaseType == "escript" 78 then "bin" 79 else "rel"} 80 mkdir -p "$out/$dir" "$out/bin" 81 cp -R --preserve=mode "_build/${profile}/$dir" "$out" 82 ${lib.optionalString (releaseType == "release") 83 "find $out/rel/*/bin -type f -executable -exec ln -s -t $out/bin {} \\;"} 84 runHook postInstall 85 ''; 86 87 postInstall = '' 88 for dir in $out/rel/*/erts-*; do 89 echo "ERTS found in $dir - removing references to erlang to reduce closure size" 90 for f in $dir/bin/{erl,start}; do 91 substituteInPlace "$f" --replace "${erlang}/lib/erlang" "''${dir/\/erts-*/}" 92 done 93 done 94 ''; 95 96 meta = { 97 inherit (erlang.meta) platforms; 98 } // meta; 99 100 passthru = ({ 101 packageName = pname; 102 env = shell self; 103 } // (if attrs ? passthru then attrs.passthru else { })); 104 } // customPhases); 105in 106lib.fix pkg