Initial commit (unfinished, up to flakes)
This commit is contained in:
commit
7f1f5c16c0
12 changed files with 515 additions and 0 deletions
401
src/slides.md
Normal file
401
src/slides.md
Normal file
|
|
@ -0,0 +1,401 @@
|
|||
---
|
||||
title: Introducción a Nix & NixOS
|
||||
sub_title: Sistemas y paquetes que funcionan donde y cuando quieras
|
||||
author: Pedro Rey
|
||||
---
|
||||
|
||||
# Introducción
|
||||
|
||||
NixOS está de moda
|
||||
===
|
||||
|
||||

|
||||
|
||||
<!-- end_slide -->
|
||||
|
||||
La _temida_ curva de aprendizaje de Nix(OS)
|
||||
===
|
||||
|
||||

|
||||
|
||||
<!-- end_slide -->
|
||||
|
||||
¿ Qué es Nix, NixOS, Nixpkgs ?
|
||||
===
|
||||
|
||||
<!-- pause -->
|
||||
|
||||
## Muchos nombres, muy parecidos no?
|
||||
|
||||
<!-- pause -->
|
||||
|
||||

|
||||
|
||||
<!-- end_slide -->
|
||||
|
||||
Nix
|
||||
===
|
||||
|
||||
- Gestor de paquetes
|
||||
- Declarativo
|
||||
- Reproducible
|
||||
- Sencillo
|
||||
|
||||
<!-- pause -->
|
||||
|
||||
Declarativo?
|
||||
===
|
||||
|
||||
> El usuario especifica el estado final deseado y Nix se encarga de conseguirlo.
|
||||
|
||||
<!-- end_slide -->
|
||||
|
||||
Nix, el lenguaje
|
||||
===
|
||||
|
||||
> Sólo existe por y para Nix, el gestor de paquetes: para describir paquetes y configuraciones, así como sus variantes y composiciones. **No está pensado para casos de uso generales**.
|
||||
|
||||
- Sencillo
|
||||
- Funcional
|
||||
- Lazy
|
||||
- Turing completo
|
||||
|
||||
```nix +exec
|
||||
let
|
||||
fibonacci = n:
|
||||
if n == 0 then
|
||||
0
|
||||
else if n == 1 then
|
||||
1
|
||||
else
|
||||
fibonacci(n - 1) + fibonacci(n - 2);
|
||||
in
|
||||
fibonacci 12
|
||||
```
|
||||
<!-- end_slide -->
|
||||
|
||||
NixOS
|
||||
===
|
||||
|
||||

|
||||
|
||||
- Nix como gestor de paquetes
|
||||
- _OS as code_
|
||||
- Se encarga **solo** de la parte declarativa
|
||||
- Datos dinámicos (estado) y **carpeta de usuario**, **NO**
|
||||
```nix
|
||||
{
|
||||
users.users.john= {
|
||||
isNormalUser = true;
|
||||
home = "/home/john";
|
||||
description = "John Doe";
|
||||
extraGroups = [ "wheel" "networkmanager" ];
|
||||
openssh.authorizedKeys.keys = [ "ssh-dss AAAAB3Nza... john@foobar" ];
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
<!-- end_slide -->
|
||||
|
||||
Home Manager
|
||||
===
|
||||
|
||||
- Gestión de _dotfiles_
|
||||
- Independiente de NixOS
|
||||
- Por la comunidad
|
||||
|
||||
```nix
|
||||
{
|
||||
programs.zsh = {
|
||||
enable = true;
|
||||
enableCompletion = true;
|
||||
autosuggestion.enable = true;
|
||||
syntaxHighlighting.enable = true;
|
||||
|
||||
oh-my-zsh = {
|
||||
enable = true;
|
||||
plugins = ["git" "fzf"];
|
||||
};
|
||||
|
||||
shellAliases = {
|
||||
c = "clear";
|
||||
cd = "z";
|
||||
};
|
||||
};
|
||||
|
||||
programs.zoxide = {
|
||||
enable = true;
|
||||
enableZshIntegration = true;
|
||||
};
|
||||
|
||||
programs.fzf.enable = true;
|
||||
}
|
||||
```
|
||||
|
||||
<!-- end_slide -->
|
||||
|
||||
Ecosistema
|
||||
===
|
||||
|
||||
- Entornos de desarrollo
|
||||
- Entornos de compilación
|
||||
- Máquinas virtuales en la nube
|
||||
- Imáges de contenedores (more on that later)
|
||||
- NixOps, clan, colmena...
|
||||
|
||||
```nix
|
||||
# Construir una imagen de coker para el paquete hello
|
||||
pkgs.dockerTools.buildLayeredImage {
|
||||
name = "nix-hello";
|
||||
tag = "latest";
|
||||
contents = [ pkgs.hello ];
|
||||
}
|
||||
```
|
||||
<!-- end_slide -->
|
||||
|
||||
# Nix, el lenguaje
|
||||
|
||||
## Modo interactivo
|
||||
```bash
|
||||
nix repl
|
||||
```
|
||||
|
||||
<!-- end_slide -->
|
||||
|
||||
## Espacios
|
||||
<!-- column_layout: [1, 1] -->
|
||||
<!-- column: 0 -->
|
||||
```nix +exec
|
||||
let
|
||||
x = 1;
|
||||
y = 2;
|
||||
in x + y
|
||||
```
|
||||
<!-- column: 1 -->
|
||||
```nix +exec
|
||||
let x=1;y=2;in x+y
|
||||
```
|
||||
|
||||
<!-- end_slide -->
|
||||
|
||||
## Attribute sets
|
||||
<!-- column_layout: [1, 1] -->
|
||||
<!-- column: 0 -->
|
||||
### Nix
|
||||
```nix
|
||||
{
|
||||
string = "hello";
|
||||
integer = 1;
|
||||
float = 3.141;
|
||||
bool = true;
|
||||
null = null;
|
||||
list = [ 1 "two" false ];
|
||||
attribute-set = {
|
||||
a = "hello";
|
||||
b = 2;
|
||||
c = 2.718;
|
||||
d = false;
|
||||
}; # comentarios
|
||||
}
|
||||
```
|
||||
<!-- column: 1 -->
|
||||
### JSON
|
||||
```json
|
||||
{
|
||||
"string": "hello",
|
||||
"integer": 1,
|
||||
"float": 3.141,
|
||||
"bool": true,
|
||||
"null": null,
|
||||
"list": [1, "two", false],
|
||||
"object": {
|
||||
"a": "hello",
|
||||
"b": 1,
|
||||
"c": 2.718,
|
||||
"d": false
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<!-- reset_layout -->
|
||||
|
||||
```nix +exec
|
||||
/// let a=
|
||||
/// {
|
||||
/// string = "hello";
|
||||
/// integer = 1;
|
||||
/// float = 3.141;
|
||||
/// bool = true;
|
||||
/// null = null;
|
||||
/// list = [ 1 "two" false ];
|
||||
/// attribute-set = {
|
||||
/// a = "hello";
|
||||
/// b = 2;
|
||||
/// c = 2.718;
|
||||
/// d = false;
|
||||
/// };
|
||||
/// };
|
||||
/// in
|
||||
a.attribute-set.c
|
||||
```
|
||||
|
||||
<!-- end_slide -->
|
||||
|
||||
## `let ... in ...`
|
||||
```nix +exec
|
||||
let
|
||||
a = 1;
|
||||
in
|
||||
a + a
|
||||
```
|
||||
|
||||
<!-- pause -->
|
||||
|
||||
## `with ...; ...`
|
||||
```nix +exec
|
||||
let
|
||||
a = {
|
||||
x = 1;
|
||||
y = 2;
|
||||
z = 3;
|
||||
};
|
||||
in
|
||||
with a; [ x y z ]
|
||||
```
|
||||
<!-- end_slide -->
|
||||
|
||||
## `inherit ...`
|
||||
```nix +exec
|
||||
let
|
||||
x = 1;
|
||||
y = 2;
|
||||
in
|
||||
{
|
||||
inherit x y;
|
||||
}
|
||||
```
|
||||
<!-- end_slide -->
|
||||
|
||||
## String interpoilation `${...}`
|
||||
```nix +exec
|
||||
let
|
||||
name = "mundo";
|
||||
in
|
||||
"hola ${name}"
|
||||
```
|
||||
<!-- end_slide -->
|
||||
|
||||
## Paths
|
||||
```nix +exec
|
||||
/tmp/no/existe
|
||||
```
|
||||
<!-- end_slide -->
|
||||
|
||||
## Funciones
|
||||
```nix +exec
|
||||
let
|
||||
f = x: x + 1;
|
||||
in f 1
|
||||
```
|
||||
|
||||
<!-- pause -->
|
||||
|
||||
```nix +exec
|
||||
let
|
||||
f = x: x.a;
|
||||
v = { a = 1; };
|
||||
in
|
||||
f v
|
||||
```
|
||||
<!-- end_slide -->
|
||||
|
||||
## Librerias
|
||||
### `builtins`
|
||||
- Vienen con Nix
|
||||
- Escritas en **C++**
|
||||
|
||||
```nix +exec
|
||||
builtins.toString
|
||||
```
|
||||
|
||||
<!--pause -->
|
||||
### `pkgs.lib`
|
||||
- En nixpkgs
|
||||
- Escritas en Nix
|
||||
```nix +exec
|
||||
let
|
||||
pkgs = import <nixpkgs> {};
|
||||
in
|
||||
pkgs.lib.strings.toUpper "lookup paths considered harmful"
|
||||
```
|
||||
<!-- end_slide -->
|
||||
|
||||
## Impuridades
|
||||
### Path
|
||||
|
||||
```bash +exec
|
||||
echo "Hola mundo" > data
|
||||
nix-instantiate --eval -E '"${./data}"'
|
||||
```
|
||||
|
||||
<!--pause -->
|
||||
### Fetchers
|
||||
|
||||
- `builtins.fetchurl`
|
||||
- `builtins.fetchTarball`
|
||||
- `builtins.fetchGit`
|
||||
- `builtins.fetchClosure`
|
||||
|
||||
|
||||
```nix +exec
|
||||
builtins.fetchurl "https://www.kernel.org/theme/images/logos/tux.png"
|
||||
```
|
||||
<!-- end_slide -->
|
||||
|
||||
## Derivaciones
|
||||
|
||||
- Nix se usa para escribir derivaciones
|
||||
- Nix ejecuta derivaciones para producir resultados de _compilación_
|
||||
- Esos resultados se pueden usar como entrada para otras derivaciones
|
||||
|
||||
```nix
|
||||
{ lib, stdenv, fetchurl }:
|
||||
|
||||
stdenv.mkDerivation rec {
|
||||
pname = "hello";
|
||||
version = "2.12";
|
||||
src = fetchurl {
|
||||
url = "mirror://gnu/${pname}/${pname}-${version}.tar.gz";
|
||||
sha256 = "1ayhp9v4m4rdhjmnl2bq3cibrbqqkgjbl3s7yk2nhlh8vj3ay16g";
|
||||
};
|
||||
meta = with lib; {
|
||||
license = licenses.gpl3Plus;
|
||||
};
|
||||
}
|
||||
```
|
||||
<!-- pause -->
|
||||
```nix +exec
|
||||
let
|
||||
pkgs = import <nixpkgs> {};
|
||||
in "${pkgs.hello}"
|
||||
```
|
||||
<!-- end_slide -->
|
||||
|
||||
Flakes
|
||||
===
|
||||
- Experimentales
|
||||
- Simplemente un **_wrapper_** para otras configuraciones de Nix
|
||||
- `flake.nix` `flake.lock`
|
||||
|
||||
<!-- end_slide -->
|
||||
¿Preguntas?
|
||||
===
|
||||
|
||||

|
||||
|
||||
<!-- end_slide -->
|
||||
|
||||
<!-- jump_to_middle -->
|
||||
|
||||
Muchas Gracias ❤️
|
||||
===
|
||||
Loading…
Add table
Add a link
Reference in a new issue