mixRelease: integrate mix2nix

This commit is contained in:
happysalada 2021-05-19 13:59:52 +09:00 committed by Raphael Megzari
parent 5ba789eeca
commit 72a1b62b47

View File

@ -8,15 +8,23 @@
, enableDebugInfo ? false
, mixEnv ? "prod"
, compileFlags ? [ ]
, mixDeps ? null
# mix fixed output derivation dependencies
, mixFodDeps ? null
# mix dependencies generated by mix2nix
# this assumes each dependency is built by buildMix or buildRebar3
# each dependency needs to have a setup hook to add the lib path to $ERL_LIBS
# this is how mix will find dependencies
, mixNixDeps ? { }
, ...
}@attrs:
let
overridable = builtins.removeAttrs attrs [ "compileFlags" ];
# remove non standard attributes that cannot be coerced to strings
overridable = builtins.removeAttrs attrs [ "compileFlags" "mixNixDeps" ];
in
assert mixNixDeps != { } -> mixFodDeps == null;
stdenv.mkDerivation (overridable // {
nativeBuildInputs = nativeBuildInputs ++ [ erlang hex elixir makeWrapper git ];
buildInputs = builtins.attrValues mixNixDeps;
MIX_ENV = mixEnv;
MIX_DEBUG = if enableDebugInfo then 1 else 0;
@ -29,17 +37,17 @@ stdenv.mkDerivation (overridable // {
postUnpack = ''
export HEX_HOME="$TEMPDIR/hex"
export MIX_HOME="$TEMPDIR/mix"
# compilation of the dependencies will require
# that the dependency path is writable
# thus a copy to the TEMPDIR is inevitable here
export MIX_DEPS_PATH="$TEMPDIR/deps"
# Rebar
export REBAR_GLOBAL_CONFIG_DIR="$TEMPDIR/rebar3"
export REBAR_CACHE_DIR="$TEMPDIR/rebar3.cache"
${lib.optionalString (mixDeps != null) ''
cp --no-preserve=mode -R "${mixDeps}" "$MIX_DEPS_PATH"
${lib.optionalString (mixFodDeps != null) ''
# compilation of the dependencies will require
# that the dependency path is writable
# thus a copy to the TEMPDIR is inevitable here
export MIX_DEPS_PATH="$TEMPDIR/deps"
cp --no-preserve=mode -R "${mixFodDeps}" "$MIX_DEPS_PATH"
''
}