Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{ 2 stdenv, 3 writeText, 4 erlang, 5 rebar3WithPlugins, 6 openssl, 7 libyaml, 8 lib, 9}: 10 11{ 12 name, 13 version, 14 src, 15 setupHook ? null, 16 buildInputs ? [ ], 17 beamDeps ? [ ], 18 buildPlugins ? [ ], 19 postPatch ? "", 20 installPhase ? null, 21 buildPhase ? null, 22 configurePhase ? null, 23 meta ? { }, 24 enableDebugInfo ? false, 25 ... 26}@attrs: 27 28let 29 debugInfoFlag = lib.optionalString (enableDebugInfo || erlang.debugInfo) "debug-info"; 30 31 rebar3 = rebar3WithPlugins { 32 plugins = buildPlugins; 33 }; 34 35 shell = 36 drv: 37 stdenv.mkDerivation { 38 name = "interactive-shell-${drv.name}"; 39 buildInputs = [ drv ]; 40 }; 41 42 customPhases = lib.filterAttrs (_: v: v != null) { 43 inherit 44 setupHook 45 configurePhase 46 buildPhase 47 installPhase 48 ; 49 }; 50 51 pkg = 52 self: 53 stdenv.mkDerivation ( 54 attrs 55 // { 56 57 name = "${name}-${version}"; 58 inherit version; 59 60 buildInputs = buildInputs ++ [ 61 erlang 62 rebar3 63 openssl 64 libyaml 65 ]; 66 propagatedBuildInputs = lib.unique beamDeps; 67 68 inherit src; 69 70 # stripping does not have any effect on beam files 71 # it is however needed for dependencies with NIFs 72 # false is the default but we keep this for readability 73 dontStrip = false; 74 75 setupHook = writeText "setupHook.sh" '' 76 addToSearchPath ERL_LIBS "$1/lib/erlang/lib/" 77 ''; 78 79 postPatch = '' 80 rm -f rebar rebar3 81 '' 82 + postPatch; 83 84 buildPhase = '' 85 runHook preBuild 86 HOME=. rebar3 bare compile -path "" 87 runHook postBuild 88 ''; 89 90 installPhase = '' 91 runHook preInstall 92 mkdir -p "$out/lib/erlang/lib/${name}-${version}" 93 for reldir in src ebin priv include; do 94 [ -d "$reldir" ] || continue 95 # $out/lib/erlang/lib is a convention used in nixpkgs for compiled BEAM packages 96 cp -Hrt "$out/lib/erlang/lib/${name}-${version}" "$reldir" 97 done 98 runHook postInstall 99 ''; 100 101 meta = { 102 inherit (erlang.meta) platforms; 103 } 104 // meta; 105 106 passthru = { 107 packageName = name; 108 env = shell self; 109 inherit beamDeps; 110 }; 111 } 112 // customPhases 113 ); 114in 115lib.fix pkg