Erlang On NixOS
Erlang On NixOS Managing And Releasing Erlang Systems In The Cloud With A Fully (( (((( Declarative (Package(( Manager System
Eric Merritt
March 11, 2016
Eric Merritt | March 11, 2016 1 / 18 Erlang On NixOS Declarative Supervision
i n i t ( Args ) −> SupFlags = #{ s t r a t e g y => o n e f o r o n e , i n t e n s i t y => 1 , p e r i o d => 5} , ChildSpecs = [#{ i d => ch3 , s t a r t => {ch3 , s t a r t l i n k , [] } , r e s t a r t => permanent , shutdown => b r u t a l k i l l , type => worker , modules => [ cg3 ] } ] , {ok , { SupFlags , ChildSpecs }} .
Eric Merritt | March 11, 2016 2 / 18 Erlang On NixOS Declarative Releases
{ application , ’gremlin’, [ { description , ”Don’t f e e d them a f t e r midnight ”} , { vsn, ”0.1.0”} , { registered , [] } , {mod , { ’ g r e m l i n a p p ’ , [] }} , { applications , [ k e r n e l , s t d l i b , e l l i , j s x ] } ] } .
Eric Merritt | March 11, 2016 3 / 18 Erlang On NixOS Declarative Releases
{ r e l x , [ { r e l e a s e , { thorndyke , ”0.0.1”} , [ thorndyke ] } ,
{ i n c l u d e e r t s , f a l s e } ,
{ e x t e n d e d s t a r t s c r i p t , f a l s e } ] } .
Eric Merritt | March 11, 2016 4 / 18 Erlang On NixOS
????
Eric Merritt | March 11, 2016 5 / 18 Erlang On NixOS Imperative Deployment
1 Create Tarballs/deb/rpm/fpm 2 Deploy Ansible/Salt/Puppet/Chef 3 Bake your images, or upgrade the boxes
Eric Merritt | March 11, 2016 6 / 18 Erlang On NixOS
Side Effect Hell
Eric Merritt | March 11, 2016 7 / 18 Erlang On NixOS
Eric Merritt | March 11, 2016 8 / 18 Erlang On NixOS What NixOS is
Purely Functional Package Manager Linux Distribution based on the Nix Package Manager
Eric Merritt | March 11, 2016 9 / 18 Erlang On NixOS Problems it solves
Directly Relevant Managed Via Files in a Git Repository Full dependency information Supports multiple versions of a package installed at the same time
Indirectly Relevant Upgrades are atomic Rollbacks Anyone can install packages
Eric Merritt | March 11, 2016 10 / 18 Erlang On NixOS How it solves those problems
Purely functional language to describe how to build packages and their dependencies Build results only depend on declared inputs. Packages never change after they have been built.
Eric Merritt | March 11, 2016 11 / 18 Erlang On NixOS
Store all packages in isolation from each other /nix/store/2l55rylrv22.... − renderproto − 0.11.1.tar.bz2.drv Paths contain a 160-bit cryptographic hash of all inputs used to build the package 1 sources 2 libraries 3 compilers 4 etc ....
Eric Merritt | March 11, 2016 12 / 18 Erlang On NixOS Declarative System
{ config, lib, pkgs, ... } : { users.extraUsers.thorndyke = rec { description = ”Thorndyke system user”; home = ”/home/thorndyke”; createHome = true; s h e l l = ”${ pkgs . bash }/bin/bash”; } ; services.thorndyke = { enable = true; user = ”thorndyke”; } ; }
Eric Merritt | March 11, 2016 13 / 18 Erlang On NixOS Service Definition
{ config, pkgs, lib, ... } : ...... config = mkIf cfg.enable { systemd. services .thorndyke = { description = ”Start the thorndyke user under \${ c f g . u s e r } .”; after = [ ”network.target” ]; wantedBy = [ ”multi −user.target” ]; serviceConfig.ExecStart = ’’/var/setuid −wrappers/sudo −u \${ c f g . u s e r } −− \ \${ pkgs.thorndyke }/var/sunlight/thorndyke/bin/thorndyke −n o s h e l l ’ ’ ; } ; } ; }
Eric Merritt | March 11, 2016 14 / 18 Erlang On NixOS Package Definition
{ stdenv , erlangPackages , bash, nettools , erlang } : erlangPackages.buildRebar3 { name = ”thorndyke − 0 . 0 . 1 ” ; s r c = . . . ;
buildInputs = [ bash nettools erlang ]; erlangDeps = with erlangPackages; [ elli jsx uri ]; installPhase = ’’ runHook preInstall target=”$out/var/thorndyke” e r l a n g=”${ e r l a n g }” make PREFIX=\$target install substituteAllInPlace \ $target/thorndyke/bin/thorndyke runHook postInstall ’’;
Eric} Merritt | March 11, 2016 15 / 18 Erlang On NixOS Non Hex Packages
{ stdenv , fetchFromGitHub , buildRebar3 } : l e t pkg = self: buildRebar3 rec { name = ”elli”; version = ”1.0.4”;
src = fetchFromGitHub { owner = ”knutin”; repo = ”elli”; rev = ”a15f838b4223caf7faa616cbadac4b250215d2f6”; sha256 = ”1ybf1p7bqbl4cg469qdx6rwdl4r1p7h4hiyshnsd9bbhp3wqcnb8”; } ; } ; in stdenv.lib.fix pkg
Eric Merritt | March 11, 2016 16 / 18 Erlang On NixOS How We Did It
Build Support reads rebar.config and environment to build the dep structure symlinks in packages from the nix dependency environment rewrites rebar.config where it needs to
Package Support Pull down every package from Hex.pm Generate nix expressions for packages in dependency order using the same dependency algo as rebar3
Eric Merritt | March 11, 2016 17 / 18 Erlang On NixOS
References http://nixos.org https://github.com/erlang-nix/rebar3-nix-bootstrap https://github.com/erlang-nix/hex2nix
Eric Merritt | March 11, 2016 18 / 18