Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at netboot-syslinux-multiplatform 93 lines 2.5 kB view raw
1{ stdenv, writeText, elixir, erlang, hex, lib }: 2 3{ name 4, version 5, src 6, buildInputs ? [ ] 7, nativeBuildInputs ? [ ] 8, beamDeps ? [ ] 9, propagatedBuildInputs ? [ ] 10, postPatch ? "" 11, compilePorts ? false 12, meta ? { } 13, enableDebugInfo ? false 14, mixEnv ? "prod" 15, ... 16}@attrs: 17 18let 19 shell = drv: stdenv.mkDerivation { 20 name = "interactive-shell-${drv.name}"; 21 buildInputs = [ drv ]; 22 }; 23 24 pkg = self: stdenv.mkDerivation (attrs // { 25 name = "${name}-${version}"; 26 inherit version src; 27 28 MIX_ENV = mixEnv; 29 MIX_DEBUG = if enableDebugInfo then 1 else 0; 30 HEX_OFFLINE = 1; 31 32 # add to ERL_LIBS so other modules can find at runtime. 33 # http://erlang.org/doc/man/code.html#code-path 34 # Mix also searches the code path when compiling with the --no-deps-check flag 35 setupHook = attrs.setupHook or 36 writeText "setupHook.sh" '' 37 addToSearchPath ERL_LIBS "$1/lib/erlang/lib" 38 ''; 39 40 buildInputs = buildInputs ++ [ ]; 41 nativeBuildInputs = nativeBuildInputs ++ [ elixir hex ]; 42 propagatedBuildInputs = propagatedBuildInputs ++ beamDeps; 43 44 configurePhase = attrs.configurePhase or '' 45 runHook preConfigure 46 47 ${./mix-configure-hook.sh} 48 49 runHook postConfigure 50 ''; 51 52 buildPhase = attrs.buildPhase or '' 53 runHook preBuild 54 export HEX_HOME="$TEMPDIR/hex" 55 export MIX_HOME="$TEMPDIR/mix" 56 mix compile --no-deps-check 57 runHook postBuild 58 ''; 59 60 installPhase = attrs.installPhase or '' 61 runHook preInstall 62 63 # This uses the install path convention established by nixpkgs maintainers 64 # for all beam packages. Changing this will break compatibility with other 65 # builder functions like buildRebar3 and buildErlangMk. 66 mkdir -p "$out/lib/erlang/lib/${name}-${version}" 67 68 # Some packages like db_connection will use _build/shared instead of 69 # honoring the $MIX_ENV variable. 70 for reldir in _build/{$MIX_ENV,shared}/lib/${name}/{src,ebin,priv,include} ; do 71 if test -d $reldir ; then 72 # Some builds produce symlinks (eg: phoenix priv dircetory). They must 73 # be followed with -H flag. 74 cp -Hrt "$out/lib/erlang/lib/${name}-${version}" "$reldir" 75 fi 76 done 77 78 runHook postInstall 79 ''; 80 81 # stripping does not have any effect on beam files 82 # it is however needed for dependencies with NIFs like bcrypt for example 83 dontStrip = false; 84 85 passthru = { 86 packageName = name; 87 env = shell self; 88 inherit beamDeps; 89 }; 90 }); 91in 92lib.fix pkg 93