Initial commit (unfinished, up to flakes)

This commit is contained in:
Pedro Rey Anca 2025-12-15 18:56:07 +01:00
commit 7f1f5c16c0
Signed by: peprolinbot
GPG key ID: 053EA6E00116533A
12 changed files with 515 additions and 0 deletions

1
.envrc Normal file
View file

@ -0,0 +1 @@
use flake

8
.gitignore vendored Normal file
View file

@ -0,0 +1,8 @@
# Created by https://www.toptal.com/developers/gitignore/api/direnv
# Edit at https://www.toptal.com/developers/gitignore?templates=direnv
### direnv ###
.direnv
.envrc
# End of https://www.toptal.com/developers/gitignore/api/direnv

27
flake.lock generated Normal file
View file

@ -0,0 +1,27 @@
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1765608474,
"narHash": "sha256-9Wx53UK0z8Di5iesJID0tS1dRKwGxI4i7tsSanOHhF0=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "28bb483c11a1214a73f9fd2d9928a6e2ea86ec71",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixos-25.11",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

64
flake.nix Normal file
View file

@ -0,0 +1,64 @@
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-25.11";
};
outputs = {
self,
nixpkgs,
}: let
supportedSystems = [
"x86_64-linux"
];
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
nixpkgsFor = forAllSystems (system: import nixpkgs {inherit system;});
in {
packages = forAllSystems (system: let
pkgs = nixpkgsFor.${system};
src = ./src;
slides = "${src}/slides.md";
presenterm_config = ./presenterm_config.yaml;
in rec {
run-presentation = pkgs.writeShellApplication {
name = "run-presentation";
runtimeInputs = with pkgs; [
presenterm
nix # For snippet execution
];
text = ''
presenterm -x ${slides} -c ${presenterm_config}
'';
};
run-presentation-kitty = pkgs.writeShellApplication {
name = "run-presentation-kitty";
runtimeInputs = [
run-presentation
pkgs.kitty
];
text = ''
kitty --config=NONE run-presentation
'';
};
});
devShells = forAllSystems (
system: let
pkgs = nixpkgsFor.${system};
in {
default = pkgs.mkShell {
buildInputs = with pkgs; [
presenterm
python3Packages.weasyprint
markdown-oxide
];
};
}
);
};
}

13
presenterm_config.yaml Normal file
View file

@ -0,0 +1,13 @@
snippet:
exec:
custom:
nix:
filename: "snippet.nix"
# A prefix that indicates a line that starts with it should not be visible but should be executed if the
# snippet is marked with `+exec`.
hidden_line_prefix: "/// "
# A list of commands that will be ran one by one in the same directory as the snippet is in.
commands:
- ["nix-instantiate", "--eval", "--strict" ,"$pwd/snippet.nix"]

1
src/data Normal file
View file

@ -0,0 +1 @@
Hola mundo

BIN
src/images/doge.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 97 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 403 KiB

BIN
src/images/nixos-curve.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 299 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 330 KiB

401
src/slides.md Normal file
View 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
===
![](images/nix-star-history-20251215.png)
<!-- end_slide -->
La _temida_ curva de aprendizaje de Nix(OS)
===
![](images/nixos-curve.jpg)
<!-- end_slide -->
¿ Qué es Nix, NixOS, Nixpkgs ?
===
<!-- pause -->
## Muchos nombres, muy parecidos no?
<!-- pause -->
![](images/doge.png)
<!-- 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
===
![image:width:40%](images/nixos-logo-25.11-xantusia-lores.png)
- 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?
===
![](images/question-mark.png)
<!-- end_slide -->
<!-- jump_to_middle -->
Muchas Gracias ❤️
===