title: Nix: the Functional Package Manager class: wrapper layout: true --- class: center, middle # {{title}} --- class: center, middle ###
# Piotr Gaczkowski ![DoomHammer](img/doomhammer.jpg)
|
[@doomhammerng](https://twitter.com/doomhammerng)
--- class: center, middle, twitter # Package Management is Hard Which package manager do you use? --- class: twitter, split75 background-image: url(img/element5-digital-fuZWqL1C2rM-unsplash.jpg) .left-pane[ # Package Managers - Apt-get, RPM, ... - Homebrew - pip, gem, npm, cabal, ... - Docker - Helm? ] --- class: twitter background-image: url(img/chuttersnap-fyaTq-fIlro-unsplash.jpg) --- class: twitter # Nix is Different Nix is a domain-specific, purely functional, lazily-evaluated language -- Nix-lang – the language -- Nix – the software -- Nixpkgs – the Package Repository -- NixOS – the Operating System --- class: twitter # Nix features - Operates in userland - Deterministic packages and environments - Atomic upgrades - Rollbacks - Build environment management - Multiple versions of packages side-by-side on a single system - Runs on Linux and macOS --- class: twitter # Functional approach - Installing or upgrading package won't break other packages - Every package is installed in a separate directory - It allows easy rollback - Prevents inconsistent state --- class: nopadding, center
--- class: twitter background-image: url(img/element5-digital-fuZWqL1C2rM-unsplash.jpg) --- class: twitter background-image: url(img/curology-pDsmoI5j3B8-unsplash.jpg) --- class: twitter # Good for multi-user environments - Several users can install packages without superuser privileges - Different users can have different package versions --- class: twitter, split75 background-image: url(img/nix-cli.png) # Package Manager --- class: twitter # Installing Remote Packages
--- class: twitter # Using Nix Expressions - Nix expressions are deterministic -- - ... as far as network connectivity goes --- class: twitter # Rolling back `nix-env --list-generations` `nix-env --rollback` `nix-env --switch-generation 3` `nix-env -G 3` --- class: twitter # Nix Closures Closures are packages with their dependencies. Closure can be copied between systems. They can be exported to files and imported later on. Or they can be copied over SSH. --- class: twitter, split50 background-image: url(img/javardh-0z7r3FIyXcE-unsplash.jpg) .left-pane[ # `nix-shell` Creates a Nix environment based on a Nix derivation and enters a shell inside it. Good for portable development environments. ] --- class: twitter-right, split75-right background-image: url(img/brett-jordan-MFLNpz5FZRk-unsplash.jpg) .left-pane[ # `manifest.nix` A list of all the software we have hoarded so far. ] --- class: twitter # Projects with direnv Uses `nix-shell`. Automatically sets up development environment whenever you enter a directory. You can pin the packages version. --- .envrc ```bash use_nix . env/bin/activate ``` default.nix ```nix { pkgs ? import
{} }: with pkgs; let python = python37; in mkShell { buildInputs = [ python git gnumake ]; } ``` --- class: twitter # Lorri lorri is a nix-shell replacement for project development. lorri is based around fast direnv integration for robust CLI and editor integration. --- # Using Nix in Standalone Scripts ```elixir #! /usr/bin/env nix-shell #! nix-shell -p "elixir" #! nix-shell -i elixir current_process = self() # Spawn an Elixir process (not an operating system one!) spawn_link(fn -> send(current_process, {:msg, "hello world"}) end) # Block until the message is received receive do {:msg, contents} -> IO.puts(contents) end ``` --- class: twitter # How Does it Compare to The Rest? - Still not as easy as Homebrew - GNU Guix using GNU Scheme (LISP) - ... if you love parentheses, you'll love GUIX! - ... also works with direnv! --- # Inspiration Asko Soukka @ PyCon PL 2019
--- class: center, middle # Thank you! ![DoomHammer](img/doomhammer.jpg)
|
[@doomhammerng](https://twitter.com/doomhammerng)
###