As I’ve started down the Indie Hacker road, one thing that has come up as I work on various projects is I need something to manage multiple versions of different binaries. I had used nvm and pyenv in the past (and rvm before that) so I started down the path of looking for the same type of tool in the elixir world. Thankfully, this led me down the path of more generic solutions to versioning these tools. First I looked at asdf but ultimately wound up using mise. I like mise for 3 main rasons:

  1. Manages per project env vars (much like direnv)
  2. Manages path modifications
  3. Support for tasks

Let’s take a quick look at using mise to manage an elixir project!

Installation

The instructions on the mise website cover enough on this front, so for the remainder of this post I’ll assume all is setup as expected.

Seeing It In Action

Mise can use an existing asdf-style .tool-versions as well as direnv’s .envrc but I prefer the .mise.toml to keep my configuration in one place and with a toml file. I’ll start with one that gives older erlang and elixir versions and a single env var defined.

[env]
SIMPLE_ENV_VAR="Hello from Environment"

[tools]
elixir = "1.16.2"
erlang = "27.0.1"

Once this file is present in the dir, we will get a notification about not having erlang and elixir versions installed, so we run mise install and the versions begin downloading and installing those versions.

Now with elixir installed, I can go ahead and install phoenix and bootstrap a new application.

$ mix archive.install hex phx_new
$ mix phx.new .
$ mix ecto.create
$ mix ecto.migrate

This generates the default Phoenix site. Now to demonstrate the env var usage, I’ll edit the default `home.html.heex and change up the placeholder text to the following.

    <p class="text-[2rem] mt-4 font-semibold leading-10 tracking-tighter text-zinc-900 text-balance">
      <%= System.get_env("SIMPLE_ENV_VAR") %>
    </p>

Run our local server via mix phx.server and navigate to http://localhost:4000 and sure enough, we see the environment variable placed on the page.

Tasks

I haven’t really looked into the task definition capabilities yet since these are covered just fine by Makefile for me personally, but I’ll take a look soon to see how it stacks up.

So far I’ve encountered a few rough edges, but nothing show stopping yet. Curious to hear from others who might be using mise or relying on other tools, please leave a comment below!

comments powered by Disqus