commit 7f1f5c16c0f7b6604fe614896440214e61a24535 Author: Pedro Rey Anca Date: Mon Dec 15 18:56:07 2025 +0100 Initial commit (unfinished, up to flakes) diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1bd505f --- /dev/null +++ b/.gitignore @@ -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 diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..ea254a9 --- /dev/null +++ b/flake.lock @@ -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 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..ad32b96 --- /dev/null +++ b/flake.nix @@ -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 + ]; + }; + } + ); + }; +} diff --git a/presenterm_config.yaml b/presenterm_config.yaml new file mode 100644 index 0000000..5e83528 --- /dev/null +++ b/presenterm_config.yaml @@ -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"] diff --git a/src/data b/src/data new file mode 100644 index 0000000..2d9b695 --- /dev/null +++ b/src/data @@ -0,0 +1 @@ +Hola mundo diff --git a/src/images/doge.png b/src/images/doge.png new file mode 100644 index 0000000..1b2d139 Binary files /dev/null and b/src/images/doge.png differ diff --git a/src/images/nix-star-history-20251215.png b/src/images/nix-star-history-20251215.png new file mode 100644 index 0000000..4d679d8 Binary files /dev/null and b/src/images/nix-star-history-20251215.png differ diff --git a/src/images/nixos-curve.jpg b/src/images/nixos-curve.jpg new file mode 100644 index 0000000..cd32b91 Binary files /dev/null and b/src/images/nixos-curve.jpg differ diff --git a/src/images/nixos-logo-25.11-xantusia-lores.png b/src/images/nixos-logo-25.11-xantusia-lores.png new file mode 100644 index 0000000..7c47f5c Binary files /dev/null and b/src/images/nixos-logo-25.11-xantusia-lores.png differ diff --git a/src/images/question-mark.png b/src/images/question-mark.png new file mode 100644 index 0000000..d969ec0 Binary files /dev/null and b/src/images/question-mark.png differ diff --git a/src/slides.md b/src/slides.md new file mode 100644 index 0000000..353d46b --- /dev/null +++ b/src/slides.md @@ -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) + + + +La _temida_ curva de aprendizaje de Nix(OS) +=== + +![](images/nixos-curve.jpg) + + + +¿ Qué es Nix, NixOS, Nixpkgs ? +=== + + + +## Muchos nombres, muy parecidos no? + + + +![](images/doge.png) + + + +Nix +=== + +- Gestor de paquetes +- Declarativo + - Reproducible +- Sencillo + + + +Declarativo? +=== + +> El usuario especifica el estado final deseado y Nix se encarga de conseguirlo. + + + +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 +``` + + +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" ]; + }; +} +``` + + + +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; +} +``` + + + +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 ]; +} +``` + + +# Nix, el lenguaje + +## Modo interactivo +```bash +nix repl +``` + + + +## Espacios + + +```nix +exec +let + x = 1; + y = 2; +in x + y +``` + +```nix +exec +let x=1;y=2;in x+y +``` + + + +## Attribute sets + + +### 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 +} +``` + +### 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 + } +} +``` + + + +```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 +``` + + + +## `let ... in ...` +```nix +exec +let + a = 1; +in +a + a +``` + + + +## `with ...; ...` +```nix +exec +let + a = { + x = 1; + y = 2; + z = 3; + }; +in +with a; [ x y z ] +``` + + +## `inherit ...` +```nix +exec +let + x = 1; + y = 2; +in +{ + inherit x y; +} +``` + + +## String interpoilation `${...}` +```nix +exec +let + name = "mundo"; +in +"hola ${name}" +``` + + +## Paths +```nix +exec +/tmp/no/existe +``` + + +## Funciones +```nix +exec +let + f = x: x + 1; +in f 1 +``` + + + +```nix +exec +let + f = x: x.a; + v = { a = 1; }; +in +f v +``` + + +## Librerias +### `builtins` +- Vienen con Nix +- Escritas en **C++** + +```nix +exec +builtins.toString +``` + + +### `pkgs.lib` +- En nixpkgs +- Escritas en Nix +```nix +exec +let + pkgs = import {}; +in +pkgs.lib.strings.toUpper "lookup paths considered harmful" +``` + + +## Impuridades +### Path + +```bash +exec +echo "Hola mundo" > data +nix-instantiate --eval -E '"${./data}"' +``` + + +### Fetchers + +- `builtins.fetchurl` +- `builtins.fetchTarball` +- `builtins.fetchGit` +- `builtins.fetchClosure` + + +```nix +exec +builtins.fetchurl "https://www.kernel.org/theme/images/logos/tux.png" +``` + + +## 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; + }; +} +``` + +```nix +exec +let + pkgs = import {}; +in "${pkgs.hello}" +``` + + +Flakes +=== +- Experimentales +- Simplemente un **_wrapper_** para otras configuraciones de Nix +- `flake.nix` `flake.lock` + + +¿Preguntas? +=== + +![](images/question-mark.png) + + + + + +Muchas Gracias ❤️ +===