nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at python-updates 159 lines 5.0 kB view raw
1{ 2 stdenv, 3 writeText, 4 elixir, 5 erlang, 6 hex, 7 lib, 8}: 9 10{ 11 name, 12 version, 13 src, 14 buildInputs ? [ ], 15 nativeBuildInputs ? [ ], 16 erlangCompilerOptions ? [ ], 17 # Deterministic Erlang builds remove full system paths from debug information 18 # among other things to keep builds more reproducible. See their docs for more: 19 # https://www.erlang.org/doc/man/compile 20 erlangDeterministicBuilds ? true, 21 beamDeps ? [ ], 22 propagatedBuildInputs ? [ ], 23 postPatch ? "", 24 compilePorts ? false, 25 meta ? { }, 26 enableDebugInfo ? false, 27 mixEnv ? "prod", 28 mixTarget ? "host", 29 removeConfig ? true, 30 # A config directory that is considered for all the dependencies of an app, typically in $src/config/ 31 # This was initially added, as some of Mobilizon's dependencies need to access the config at build time. 32 appConfigPath ? null, 33 ... 34}@attrs: 35 36assert appConfigPath != null -> removeConfig; 37 38let 39 shell = 40 drv: 41 stdenv.mkDerivation { 42 name = "interactive-shell-${drv.name}"; 43 buildInputs = [ drv ]; 44 }; 45 46 pkg = 47 self: 48 stdenv.mkDerivation ( 49 attrs 50 // { 51 name = "${name}-${version}"; 52 inherit version src; 53 54 MIX_ENV = mixEnv; 55 MIX_TARGET = mixTarget; 56 MIX_BUILD_PREFIX = (if mixTarget == "host" then "" else "${mixTarget}_") + "${mixEnv}"; 57 MIX_DEBUG = if enableDebugInfo then 1 else 0; 58 HEX_OFFLINE = 1; 59 60 __darwinAllowLocalNetworking = true; 61 62 ERL_COMPILER_OPTIONS = 63 let 64 options = erlangCompilerOptions ++ lib.optionals erlangDeterministicBuilds [ "deterministic" ]; 65 in 66 "[${lib.concatStringsSep "," options}]"; 67 68 LANG = if stdenv.hostPlatform.isLinux then "C.UTF-8" else "C"; 69 LC_CTYPE = if stdenv.hostPlatform.isLinux then "C.UTF-8" else "UTF-8"; 70 71 # add to ERL_LIBS so other modules can find at runtime. 72 # http://erlang.org/doc/man/code.html#code-path 73 # Mix also searches the code path when compiling with the --no-deps-check flag 74 setupHook = attrs.setupHook or writeText "setupHook.sh" '' 75 addToSearchPath ERL_LIBS "$1/lib/erlang/lib" 76 ''; 77 78 buildInputs = buildInputs ++ [ ]; 79 nativeBuildInputs = nativeBuildInputs ++ [ 80 elixir 81 hex 82 ]; 83 propagatedBuildInputs = propagatedBuildInputs ++ beamDeps; 84 85 configurePhase = 86 attrs.configurePhase or '' 87 runHook preConfigure 88 89 ${./mix-configure-hook.sh} 90 ${lib.optionalString (removeConfig && isNull appConfigPath) 91 # By default, we don't want to include whatever config a dependency brings; per 92 # https://hexdocs.pm/elixir/main/Config.html, config is application specific. 93 '' 94 rm -rf config 95 mkdir config 96 '' 97 } 98 ${lib.optionalString (!isNull appConfigPath) 99 # Some more tightly-coupled dependencies do depend on the config of the application 100 # they're being built for. 101 '' 102 rm -rf config 103 cp -r ${appConfigPath} config 104 '' 105 } 106 107 runHook postConfigure 108 ''; 109 110 buildPhase = 111 attrs.buildPhase or '' 112 runHook preBuild 113 export HEX_HOME="$TEMPDIR/hex" 114 export MIX_HOME="$TEMPDIR/mix" 115 mix compile --no-deps-check 116 runHook postBuild 117 ''; 118 119 installPhase = 120 attrs.installPhase or '' 121 runHook preInstall 122 123 # This uses the install path convention established by nixpkgs maintainers 124 # for all beam packages. Changing this will break compatibility with other 125 # builder functions like buildRebar3 and buildErlangMk. 126 mkdir -p "$out/lib/erlang/lib/${name}-${version}" 127 128 # Some packages like db_connection will use _build/shared instead of 129 # honoring the $MIX_ENV variable. 130 for reldir in _build/{$MIX_BUILD_PREFIX,shared}/lib/${name}/{src,ebin,priv,include} ; do 131 if test -d $reldir ; then 132 # Some builds produce symlinks (eg: phoenix priv dircetory). They must 133 # be followed with -H flag. 134 cp -Hrt "$out/lib/erlang/lib/${name}-${version}" "$reldir" 135 fi 136 done 137 138 # Copy the source so it can be used by dependent packages. For example, 139 # phoenix applications need the source of phoenix and phoenix_html to 140 # build javascript and css assets. 141 mkdir -p $out/src 142 cp -r "$src/." "$out/src" 143 144 runHook postInstall 145 ''; 146 147 # stripping does not have any effect on beam files 148 # it is however needed for dependencies with NIFs like bcrypt for example 149 dontStrip = false; 150 151 passthru = { 152 packageName = name; 153 env = shell self; 154 inherit beamDeps; 155 }; 156 } 157 ); 158in 159lib.fix pkg