Reproducible Riak Core Lite Tutorial with Nix
Introduction
Over the years I've created and recreated guides, posts and tutorials on how to setup an environment to create riak_core based applications.
Most of the repetitive work and troubleshooting is around the moving target that is a current Erlang/Elixir/Rebar3/Mix setup.
With this attempt I hope people will be able to setup and follow the guides with a reproducible environment that always reflects the one I had when I wrote the guide.
For that I will use Nix, to follow it you just need git and nix.
Follow instructions here to Install Nix if you haven't done that already.
Riak Core Lite with Erlang
Clone the Riak Core Lite Rebar3 Template
mkdir -p ~/.config/rebar3/templates git clone https://github.com/riak-core-lite/rebar3_template_riak_core_lite.git ~/.config/rebar3/templates/rebar3_template_riak_core_lite
Enter a nix-shell with the needed tools:
Now your shell should have Erlang and rebar3 available, try it:
Now let's create a new Riak Core Lite application, go to the folder where you want to store your new project and then:
Create the project:
Build it:
Try it:
The output should look something like, the number will probably be different:
With this environment you should be able to follow previous tutorials and guides like the Riak Core Tutorial and maybe the Little Riak Core Book.
Riak Core Lite with Elixir
I recommend you to follow Rkv: Step by Step Riak Core Lite Key Value Store Project
Clone the project:
Enter a nix-shell with the needed tools:
Now your shell should have Erlang, Elixir, rebar3 and mix available, try it:
Fetch deps, compile test and run:
Play with the API:
Rkv.get(:k1) # {:error, :not_found} Rkv.delete(:k1) # :ok Rkv.put(:k2, :v2) # :ok Rkv.get(:k2) # {:ok, :v2} Rkv.delete(:k2) # :ok Rkv.get(:k2) # {:error, :not_found} Rkv.put(:k2, :v2) Rkv.get(:k2) # {:ok, :v2}
You can follow the guide by switching to each tag in order: https://github.com/riak-core-lite/rkv/tags
I will try to keep the shell.nix files on both languages up to date from time to time to keep with major Erlang/Elixir versions, you can try to update the nix hash yourself and see if it still builds by following the instructions here: Nix Possible URL values
Have fun!