Build elixir_ls with custom elixir/erlang version?

I have a nix-shell that I have a custom build of erlang and elixir. I would like to add elixir_ls to the shell given that its now packaged in nixos. I tried overriding and i was able to get it to run using my custom setup

Content-Length: 102

{"jsonrpc":"2.0","method":"window/logMessage","params":{"message":"Started ElixirLS v0.7.0","type":4}}Content-Length: 135

{"jsonrpc":"2.0","method":"window/logMessage","params":{"message":"Elixir version: \"1.12.0 (compiled with Erlang/OTP 24)\"","type":4}}Content-Length: 101

{"jsonrpc":"2.0","method":"window/logMessage","params":{"message":"Erlang version: \"24\"","type":4}}Content-Length: 129

{"jsonrpc":"2.0","method":"window/logMessage","params":{"message":"ElixirLS compiled with Elixir 1.11.4 and erlang 23","type":4}}

but as you can see it is still built with the stock system.

my shell.nix looks like this currently.

# commit from unstable from 2021-05-21
{ pkgs ? import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/22c86a0466969819fb7bf9c7a0c65711e5f1a005.tar.gz") {}}:
with pkgs;
let
  inherit (lib) optionals;
  erlang24 = erlangR23.override {
    version = "24.0.1";
    # nix-prefetch-url --unpack https://github.com/erlang/otp/archive/OTP-24.0.1.tar.gz
    sha256 = "1j2y3m1k75c62gvhvj5f2jw3sijii1z8bjnk547w4ak4ldl60kfg";
    javacSupport = true;
    odbcSupport = true;
    configureFlags = [ "--with-ssl=${lib.getOutput "out" openssl}" ]
    ++ [ "--with-ssl-incl=${lib.getDev openssl}" ] ;
  };
  elixir12 = (beam.packagesWith erlang24).elixir.override {
   version = "1.12.0";
    # nix-prefetch-url --unpack https://github.com/elixir-lang/elixir/archive/refs/tags/v1.11.4.tar.gz
    sha256 = "0nx0ajbpib0hxpxz33p1kr3rqgvf35vkx91sh427qcjqy7964z16";
  };
  elixir_ls7 =  elixir_ls.override {
    elixir = elixir12;
  };
in pkgs.mkShell {
  MIX_HOME = "~/code/.mix";
  HEX_HOME = "~/code/.hex";

  ERL_AFLAGS = "-kernel shell_history enabled";

  buildInputs = [
    erlang24
    elixir12
    elixir_ls7
  ];
}

i tried overriding the mixRelease without success. is this something that could be better solved with an overlay?

I am also interested in a solution to this.

I was able to do it with this snippet:

let
  # ...
  beamPkg = pkgs.beam.packagesWith erlang24;
  elixir_ls7 = (
    beamPkg.elixir_ls.override {
      elixir = elixir12;
      mixRelease = beamPkg.mixRelease.override { elixir = elixir12; };
    }
  );
in # ...
1 Like

For those looking for a simple way to install custom Elixir, Erlang and ElixirLS versions on their system:

{ config, pkgs, ... }: {
  # ...

  environment.systemPackages = with pkgs; ([
    # Packages ...
  ] ++ (
    let
      erlang_25 = erlangR25.override {
        version = "25.2.3";
        # nix-prefetch-url --unpack https://github.com/erlang/otp/archive/OTP-25.2.3.tar.gz
        sha256 = "10ad3xqrxkcpdbj57n50990d1jhhdmc6rcf7swmf64nf23rcgr55";
        javacSupport = false;
        odbcSupport = false;
        configureFlags = [ "--with-ssl=${lib.getOutput "out" openssl}" ]
          ++ [ "--with-ssl-incl=${lib.getDev openssl}" ];
      };

      beamPkg = beam.packagesWith erlang_25;

      elixir_1_14 = beamPkg.elixir.override {
        version = "1.14.2";
        # nix-prefetch-url --unpack https://github.com/elixir-lang/elixir/archive/refs/tags/v1.14.2.tar.gz
        sha256 = "1w0wda304bk3j220n76bmv4yv0pkl9jca8myipvz7lm6fnsvw500";
      };

      elixir_ls = beamPkg.elixir-ls.override {
        lib = lib // {
          # Merge custom importJSON into lib.
          importJSON = _: {
            version = "0.14.6";
            sha256 = "sha256-O977DZLWPyLafIaOTPZKI4MOtK9E9TDProf2xyk05aI=";
            depsSha256 = "sha256-jF1Plkz1D85aWkiNgeBlJmHndhr7us+8+m/gMkXHvDw=";
          };
        };
        elixir = elixir_1_14;
        mixRelease = beamPkg.mixRelease.override { elixir = elixir_1_14; };
      };
    in
    [
      erlang_25
      elixir_1_14
      elixir_ls
    ]
  ) ++ [
    # Packages ...
  ]);
}