Upgrade to Pro — share decks privately, control downloads, hide ads and more …

NixOS - Purely Functional Package Management

1d27f02822d73e2c64e87e14c45bffcc?s=47 yawnt
June 01, 2016

NixOS - Purely Functional Package Management

1d27f02822d73e2c64e87e14c45bffcc?s=128

yawnt

June 01, 2016
Tweet

Transcript

  1. Nix(OS) purely functional package management Fueled by

  2. f(x)

  3. Why is state evil?

  4. Expensive to keep track of mutation

  5. Which in turns means no rollback

  6. Which in turns means no portability

  7. The Nix language

  8. Why?

  9. $ nix-repl > true true > 1 + 1 2

    > (a: a + 1) 1 2
  10. We use Nix to describe how to build packages

  11. { stdenv, fetchurl, perl }: stdenv.mkDerivation { name = "hello-2.1.1";

    builder = ./builder.sh; src = fetchurl { url = “${packageURL}; md5 = “${md5hash}; }; inherit perl; }
  12. Packages are immutable once built

  13. Everything lives inside a single directory, the store

  14. “Live” packages are symlinked

  15. Old packages are still in the store, just not accessible

  16. Rollback for free

  17. Multiple versions for free

  18. Multiple envs for free

  19. Puppies for free

  20. Ok, maybe not puppies

  21. $ nix-repl command not found: nix-repl $ nix-shell -p nix-repl

    [nix-shell:~]$ nix-repl -v nix-repl v1.1.2 [nix-shell:~]$ exit $ nix-repl command not found: nix-repl
  22. NixOS is a distribution built around Nix

  23. In Nix, to build a package you write a function

  24. In NixOS, to build a system you write a function

  25. configuration.nix

  26. $ fdisk /dev/sda $ mkfs.ext4 -L nixos /dev/sda1 $ mkswap

    -L swap /dev/sda2 $ swapon /dev/sda2 $ mount /dev/disk/by-label/nixos /mnt $ nixos-generate-config --root /mnt $ nano /mnt/etc/nixos/configuration.nix $ nixos-install $ reboot
  27. { config, pkgs, ... }: { imports = [ ./hardware-configuration.nix

    ]; boot.loader.grub.device = "/dev/sda"; }
  28. Building your system is purely functional

  29. Upgrading is the same as rebuilding from scratch

  30. No /usr, /sbin/, /share

  31. Just /nix/store

  32. Nix(OS) cryoptographically hashes all build inputs

  33. That means built-in versioning

  34. dotfiles, just store ‘em in /nix/store .emacs.d, *wink* *wink* ;)

    ;)
  35. More than just a distribution

  36. nixops

  37. (hail) hydra

  38. Questions?