Erlang on Nixos
Total Page:16
File Type:pdf, Size:1020Kb
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 j March 11, 2016 1 / 18 Erlang On NixOS Declarative Supervision i n i t ( Args ) −> SupFlags = #f 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 => 5g , ChildSpecs = [#f i d => ch3 , s t a r t => fch3 , s t a r t l i n k , [] g , r e s t a r t => permanent , shutdown => b r u t a l k i l l , type => worker , modules => [ cg3 ] g ] , fok , f SupFlags , ChildSpecs gg . Eric Merritt j March 11, 2016 2 / 18 Erlang On NixOS Declarative Releases f application , 'gremlin', [ f description , "Don't f e e d them a f t e r midnight "g , f vsn, "0.1.0"g , f registered , [] g , fmod , f ' g r e m l i n a p p ' , [] gg , f applications , [ k e r n e l , s t d l i b , e l l i , j s x ] g ] g . Eric Merritt j March 11, 2016 3 / 18 Erlang On NixOS Declarative Releases f r e l x , [ f r e l e a s e , f thorndyke , "0.0.1"g , [ thorndyke ] g , f i n c l u d e e r t s , f a l s e g , f e x t e n d e d s t a r t s c r i p t , f a l s e g ] g . Eric Merritt j March 11, 2016 4 / 18 Erlang On NixOS ???? Eric Merritt j 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 j March 11, 2016 6 / 18 Erlang On NixOS Side Effect Hell Eric Merritt j March 11, 2016 7 / 18 Erlang On NixOS Eric Merritt j 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 j 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 j 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 j 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 j March 11, 2016 12 / 18 Erlang On NixOS Declarative System f config, lib, pkgs, ... g : f users.extraUsers.thorndyke = rec f description = "Thorndyke system user"; home = "/home/thorndyke"; createHome = true; s h e l l = "$f pkgs . bash g/bin/bash"; g ; services.thorndyke = f enable = true; user = "thorndyke"; g ; g Eric Merritt j March 11, 2016 13 / 18 Erlang On NixOS Service Definition f config, pkgs, lib, ... g : ...... config = mkIf cfg.enable f systemd. services .thorndyke = f description = "Start the thorndyke user under n$f c f g . u s e r g ."; after = [ "network.target" ]; wantedBy = [ "multi −user.target" ]; serviceConfig.ExecStart = ''/var/setuid −wrappers/sudo −u n$f c f g . u s e r g −− n n$f pkgs.thorndyke g/var/sunlight/thorndyke/bin/thorndyke −n o s h e l l ' ' ; g ; g ; g Eric Merritt j March 11, 2016 14 / 18 Erlang On NixOS Package Definition f stdenv , erlangPackages , bash, nettools , erlang g : erlangPackages.buildRebar3 f 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="$f e r l a n g g" make PREFIX=n$target install substituteAllInPlace n $target/thorndyke/bin/thorndyke runHook postInstall ''; Ericg Merritt j March 11, 2016 15 / 18 Erlang On NixOS Non Hex Packages f stdenv , fetchFromGitHub , buildRebar3 g : l e t pkg = self: buildRebar3 rec f name = "elli"; version = "1.0.4"; src = fetchFromGitHub f owner = "knutin"; repo = "elli"; rev = "a15f838b4223caf7faa616cbadac4b250215d2f6"; sha256 = "1ybf1p7bqbl4cg469qdx6rwdl4r1p7h4hiyshnsd9bbhp3wqcnb8"; g ; g ; in stdenv.lib.fix pkg Eric Merritt j 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 j 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 j March 11, 2016 18 / 18.