@@ -563,13 +563,38 @@ defmodule Mix do
563
563
* `:elixir` - if set, ensures the current Elixir version matches the given
564
564
version requirement (Default: `nil`)
565
565
566
+ * `:config` (since v1.13.0) - a keyword list of keyword lists with application
567
+ configuration to be set before the apps loaded. The configuration is part of
568
+ the `Mix.install/2` cache, so different configurations will lead to different
569
+ apps
570
+
571
+ * `:system_env` (since v1.13.0) - a map of system environment variable names as
572
+ binary keys and their respective values as binaries. The system environment is
573
+ made part of the `Mix.install/2` cache, so different configurations will lead
574
+ to different apps
575
+
566
576
## Examples
567
577
578
+ To install `:decimal` and `:jason`:
579
+
568
580
Mix.install([
569
581
:decimal,
570
582
{:jason, "~> 1.0"}
571
583
])
572
584
585
+ Using `:nx`, `:exla`, and configure the underlying applications
586
+ and environment variables:
587
+
588
+ Mix.install(
589
+ [:nx, :exla],
590
+ config: [
591
+ nx: [default_backend: EXLA]
592
+ ],
593
+ system_env: [
594
+ {"XLA_TARGET", "cuda111"}
595
+ ]
596
+ )
597
+
573
598
## Limitations
574
599
575
600
There is one limitation to `Mix.install/2`, which is actually an Elixir
@@ -636,29 +661,39 @@ defmodule Mix do
636
661
other
637
662
end )
638
663
664
+ config = Keyword . get ( opts , :config , [ ] )
665
+ system_env = Keyword . get ( opts , :system_env , [ ] )
666
+
667
+ id =
668
+ { deps , config , system_env }
669
+ |> :erlang . term_to_binary ( )
670
+ |> :erlang . md5 ( )
671
+ |> Base . encode16 ( case: :lower )
672
+
639
673
force? = ! ! opts [ :force ]
640
674
641
675
case Mix.State . get ( :installed ) do
642
676
nil ->
643
677
:ok
644
678
645
- ^ deps when not force? ->
679
+ ^ id when not force? ->
646
680
:ok
647
681
648
682
_ ->
649
683
Mix . raise ( "Mix.install/2 can only be called with the same dependencies in the given VM" )
650
684
end
651
685
686
+ Application . put_all_env ( config , persistent: true )
687
+ System . put_env ( system_env )
688
+
652
689
installs_root =
653
- System . get_env ( "MIX_INSTALL_DIR" ) ||
654
- Path . join ( Mix.Utils . mix_cache ( ) , "installs" )
690
+ System . get_env ( "MIX_INSTALL_DIR" ) || Path . join ( Mix.Utils . mix_cache ( ) , "installs" )
655
691
656
- id = deps |> :erlang . term_to_binary ( ) |> :erlang . md5 ( ) |> Base . encode16 ( case: :lower )
657
692
version = "elixir-#{ System . version ( ) } -erts-#{ :erlang . system_info ( :version ) } "
658
693
dir = Path . join ( [ installs_root , version , id ] )
659
694
660
695
if opts [ :verbose ] do
661
- Mix . shell ( ) . info ( "using #{ dir } " )
696
+ Mix . shell ( ) . info ( "Mix.install/2 using #{ dir } " )
662
697
end
663
698
664
699
if force? do
@@ -701,7 +736,7 @@ defmodule Mix do
701
736
Application . ensure_all_started ( app )
702
737
end
703
738
704
- Mix.State . put ( :installed , deps )
739
+ Mix.State . put ( :installed , id )
705
740
:ok
706
741
after
707
742
Mix.ProjectStack . pop ( )
0 commit comments