What is the canonical way of installing Elixir on Erlang > 19 with `nix` on a non-NixOS system?

痞子三分冷 提交于 2019-12-04 14:38:51

问题


Please explain it as you would to a 10-year-old, from the point after the Nix package manager is installed on a non-NixOS machine. For example, I am on a Mac, and there isn't even a ~/.config directory.

I found the following (probably) relevant resources, and I can't put the pieces together:

  • Nixpkgs manual, 9.1. BEAM Languages (Erlang, Elixir & LFE)

  • Elixir 1.5.1 with Erlang 20.0 on NixOS 18.03?

    Where do I specify the beam.packages.erlang<rel>.elixir exactly?

  • Nixpkgs manual, 6.4. Modify packages via packageOverrides

  • Nix Pills, Chapter 14. Override Design Pattern

    Is this needed for this?


In the end I installed the latest Elixir with Erlang 21 as shown below, but I'm sure that this is not how it is supposed to be done.

$ # Cloned the `nixpkgs` repo from github and started the repl
$ # in the same the directory.
$
$ nix repl
Welcome to Nix version 2.0.4. Type :? for help.

nix-repl> :l nixpkgs
Added 9182 variables.

nix-repl> pkgs.beam.packages.erlangR21.elixir
«derivation /nix/store/vcadn6d6wgk1yjlci458vy8jqv66wwdy-elixir-1.6.5.drv»

nix-repl> :q

$ nix-store --realise /nix/store/vcadn6d6wgk1yjlci458vy8jqv66wwdy-elixir-1.6.5.drv

回答1:


You are on the right track; there is no need to start over.

To install the package from nix repl you can use the :i command.

nix-repl> :i pkgs.beam.packages.erlangR21.elixir

This will install the package into your ~/.nix-profile where it will be in $PATH, so you can call it. It is equivalent to running

nix-env -iA nixpkgs.beam.packages.erlangR21.elixir

nix-store -r (or equivalently, nix-store --realise) is considered a very low-level tool. It can only create a symlink to a package and that is rarely what you want. It doesn't even create a garbage collection root by default, so if you garbage collect, the symlink will become broken.

Although nix-env -iA is a valid way of installing software, you may consider ~/.nix-profile global state and avoid it for that reason. It seems to me like elixir that is more tied to a project, rather than to your user. For example you may want to use distinct versions for some projects and it may make sense to share your development tools with others who work on a project. That is you can use nix-shell for. Here's an example of shell.nix.




回答2:


You can create a dedicated shell for use with your project, and avoid installing the runtime globally/for current user.

Example of minimal nix shell for Elixir on Erlang/OTP 20:

The contents of default.nix file:

with import <nixpkgs> {};

stdenv.mkDerivation rec {
    name = "env";
    env = buildEnv { name = name; paths = buildInputs; };
    buildInputs = [
        beam.packages.erlangR20.elixir
        inotify-tools
    ];
}

Then in terminal, navigate to the directory where default.nix is saved, and invoke nix-shell. You should drop into a shell which has iex and mix available.



来源:https://stackoverflow.com/questions/51371028/what-is-the-canonical-way-of-installing-elixir-on-erlang-19-with-nix-on-a-no

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!