Changer son environnement fullstack en un clin d’oeil avec devenv

A presentation at VolCamp.io in October 2023 in Clermont-Ferrand, France by Julien Tanguy

Slide 1

Slide 1

Changer son environnement fullstack en un clin d’oeil avec devenv

Slide 2

Slide 2

Qui sommes-nous Julien Tanguy Developer @jutanguy hello@jtanguy.me

Slide 3

Slide 3

Qui sommes-nous Anthony Pena Developer @_Anthony_Pena anthony.pena@outlook.fr

Slide 4

Slide 4

Prérequis Un environnement de développement linux-like • Linux • MacOS • WSL2 pour Windows • Github codespaces: https://github.com/jtanguy/workshop-devenv

Slide 5

Slide 5

Lab Installation • https://github.com/jtanguy/workshop-devenv • Lancer un codespace Étape: Installation

Slide 6

Slide 6

Lab Installation (Alt) https://devenv.sh/getting-started/ • installer Nix • installer Cachix • installer Devenv Étape: Installation

Slide 7

Slide 7

Contexte

Slide 8

Slide 8

Problématique

Slide 9

Slide 9

Problématique • Comment gérer les outils de développement ?

Slide 10

Slide 10

Problématique • Comment gérer les outils de développement ? • Comment faciliter l’installation d’un nouveau poste ?

Slide 11

Slide 11

Problématique • Comment gérer les outils de développement ? • Comment faciliter l’installation d’un nouveau poste ? • Comment mettre à jour, maintenir et diffuser des évolutions de ces outils ?

Slide 12

Slide 12

Problématique • Comment gérer les outils de développement ? • Comment faciliter l’installation d’un nouveau poste ? • Comment mettre à jour, maintenir et diffuser des évolutions de ces outils ? • Comment faciliter le développement en local ?

Slide 13

Slide 13

Solutions

Slide 14

Slide 14

Solutions • Gestion des versions des langages: nvm, sdkman, rvm

Slide 15

Slide 15

Solutions • Gestion des versions des langages: nvm, sdkman, rvm • Outils multi-languages et multi-outils: asdf

Slide 16

Slide 16

Solutions • Gestion des versions des langages: nvm, sdkman, rvm • Outils multi-languages et multi-outils: asdf • Comment gérer les services annexes: db, reverse-proxy, process autres ?

Slide 17

Slide 17

Pourquoi devenv ?

Slide 18

Slide 18

Avantages

Slide 19

Slide 19

Avantages • Gestion de nombreux langages

Slide 20

Slide 20

Avantages • Gestion de nombreux langages • Gestion des services annexes

Slide 21

Slide 21

Avantages • Gestion de nombreux langages • Gestion des services annexes • Se repose sur un vrai package manager: nix

Slide 22

Slide 22

Avantages • Gestion de nombreux langages • Gestion des services annexes • Se repose sur un vrai package manager: nix • Se repose sur le plus grand repository: nixpkgs

Slide 23

Slide 23

Nixpkgs 57000 nixpkgs unstable Number of fresh packages in repository nixpkgs stable 23.05 nixpkgs stable 22.11 nixpkgs stable 22.05 nixpkgs stable 21.11 AUR CRAN FreeBSD Ports Debian Unstable Devuan Unstable Debian Kali Linux 13Raspbian Rolling Testing Ubuntu 23.10 Hackage PyPI Fedora Rawhide Fedora 39 Raspbian Stable Debian Ubuntu 12 23.04 PureOS landing Fedora 38 Fedora 37 LiGurOS develop Ubuntu11.0 22.04 Trisquel Gentoo Raspbian Oldstable MacPorts LiGurOS stable openSUSE Tumbleweed Fedora 36 Parrot Debian Devuan Pardus 21 11 4.0 CPAN pkgsrc ALT Sisyphus current MetaCPAN Unstable FedoraGNU 35 Guix Manjaro Arch ParabolaTesting Rosa 2021.1 Manjaro Stable Fedora 34 Ubuntu 20.04 Alpine Linux Edge Trisquel 10.0 Mageia cauldron Arch Linux ARM aarch64 Fedora 33 Debian 10 PureOS Devuan DeepinAmber 3.0 Fedora Fedora 32 31 Fedora 30 29 ALT Linux p10 28 Ubuntu 18.04 Fedora i686 Arch Linux OpenMandriva 32 pentium4 Fedora Rolling Cooker 27 OpenMandriva 4.3 Rosa Fedora 2016.1 26 OpenBSD PLDPorts Linux ALT OpenMandriva 4.2 Homebrew Void Linux x86_64 Rosa 2014.1 openSUSE Leap Linux 15.5 p9 Ubuntu 16.04 OpenMandriva 4.1 Arch Linux 32 i486 OpenMandriva 4.0 Mageia 8 SlackBuilds BioArch openmamba Ubuntu 14.04 RubyGems Artix openSUSE Leap 15.4 Alpine Linux 3.18 PCLinuxOS crates.io Exherbo EPEL 9 openSUSELeap Leap15.2 15.3 Stackage Nightly Ravenports openSUSE MELPA Stable Spack Stackage Wikidata LTS Haskell Alpine Linux openSUSE 3.17 Leap 15.0 T2 SDE openSUSE Leap 15.1 Solus Scoop YACP openSUSE EPEL Alpine EPEL 8 Linux 7 mports 3.16 Leap 42.3 ArchPOWER powerpc powerpc64le ArchPOWER riscv64 OpenIndiana Termux packages KaOS MSYS2 Pisi MidnightBSD Linux Alpine mingw Linux 3.15 CRUX Buildroot 3.7 master Apertis v2023 v2022 v2024 Development Slackware Slackware64 SliTaz Alpine Cooking current current Linux 3.14 Homebrew Casks Cygwin openEuler BlackArch Alpine 2023.05.x Linux 22.03 3.13 RPM Debian Buildroot Chocolatey Sphere Janitor 2023.02.x Releases EPEL 6 HaikuPorts Alpine Linux master 3.12 winget Adélie Linux current Gentoo overlay GURU ConanCenter Vcpkg SliTaz Alpine Next Linux 3.11 OpenPKG CentOS Alpine GoboLinux Apertis Stream Linux v2021 3.10 97.x CRUX EuroLinux Rocky AlmaLinux Alpine 3.6 Linux Linux 9Linux 9 915.0 3.8 3.9 openSUSE AlmaLinux EuroLinux Rocky CentOS Rosa Linux games Server Stream 88 8 Tumbleweed 7.5 8 Entware CentOS Scientific Rosa 3.5 Server science 8 7.3 Tumbleweed GNU MSYS2 Debian Slackwarearm Slackware Slackware64 Amazon Elpa msys2 Experimental 7 Linux 15.0 15.0 2 Deb HP-UX freshcode.club Gentoo openEuler Multimedia Rosa 11.31 overlay Server 22.03 20.03 Unstable Pentoo 6.9 LuaRocks Carbs Libregamewiki OS4Depot Npackd AIX CRUX Debian Slackware Slackware64 Slackwarearm Ataraxia Amazon CentOS Open Linux 3.4 Stable 11 GNU/Linux Source 6 Linux 14.2 Backports 14.2 14.2 1 Packages DistroWatch.com openSUSE Terra RPM PackMan PackMan MPR yiffOS OpenWrt OpenWrt Debian Fusion 38 39 37 Knot openSUSE openSUSE 10 network multimedia:apps multimedia:libs graphics 19.07 Fedora 21.02 Debian Backports x86_64 x86_64 Rawhide Tumbleweed 37 Tumbleweed Janitor Tumbleweed Leap 15.2 42.3 15.0 15.1 Tumbleweed -Backports Tumbleweed Snapshots glaucus WakeMeOps NOIR Ubuntu Homebrew Npackd Pisi openSUSE RebornOS SageMath MX pacstall Gentoo AIX MX MX UBI OpenWrt OpenWrt Linux Toolbox Linux 8 Linux 23.10 Stable64 Science SLE Contrib MX-21 MX-21 MX-19 stable development hardware:sdr security 17.01 MX-19 Education 18.06 tap Main 12 Proposed Brewsci/bio overlay Testing x86_64 x86_64 Testing Tumbleweed Tumbleweed Tumbleweed F-Droid KaOS MX openSUSE Pardus Trisquel Arch Baulk Calculate Tails RPM BackBox antiX-16 Endless Linux LMDE PackMan ReactOS Sabayon Sparky UnitedRPMs Kali antiX-17 IBM KaOS KISS postmarketOS just-install Software MX Siduction antiX-21 antiX-19 Salix distri KDE AppGet KDE postmarketOS Linux Linux Linux iFusion stable devel Testing neon Linux Build Mint neon 14.2 4 5 kde-next 23 Stable Testing 22.04 20.04 14.04 10.0 11.0 OS 6 7 rapps for-gentoo SLE MX-23 Collections MX-23 Bleeding server:irc shells 20 20.1 21 21.1 Emulators 20.2 20.3 User Testing Games 4.0 Unstable EL master Hydrogen Helium backports 15 9 6 8 7 20.05 22.12 21.03 master LTS Testing Tumbleweed Edge 35 36 32 33 34 Tumbleweed 0 Ubuntu Npackd Siduction BunsenLabs Parabola ELRepo 18.04 16.04 23.04 el7 Unstable Testing Experimental Testing MELPA Hydrogen/Jessie Helium/Stretch Backports Backports 0 Number of packages in repository 87000

Slide 24

Slide 24

Introduction à Nix

Slide 25

Slide 25

Nix “ Nix est un package manager déclaratif ”

Slide 26

Slide 26

Nix store 1 2 3 4 5 6 7 8 9 10 11 12 13 14 $ which lnav /nix/store/hcv2abrk1mhsnz67xjasg3pwz4wdkw7q-devenv-profile/bin/lnav $ ls /nix/store/hcv2abrk1mhsnz67xjasg3pwz4wdkw7q-devenv-profile/bin/ -la total 36 dr-xr-xr-x 2 root root 4096 Jan 1 1970 ./ dr-xr-xr-x 6 root root 4096 Jan 1 1970 ../ lrwxrwxrwx 3 root root 71 Jan 1 1970 corepack -> /nix/store/x8vrc1c6r8nn454whr99bxc5hdy5ybjf-nodejs-18.18.0/bin/corepack* lrwxrwxrwx 3 root root 67 Jan 1 1970 honcho -> /nix/store/am744diswph5ml71n562k2rwhwk3ipw0-honcho-1.1.0/bin/honcho* lrwxrwxrwx 3 root root 76 Jan 1 1970 .honcho-wrapped -> /nix/store/am744diswph5ml71n562k2rwhwk3ipw0-honcho-1.1.0/bin/.honcho-wrapped* lrwxrwxrwx 2 root root 64 Jan 1 1970 lnav -> /nix/store/c9psaxm0syj8rriqdy8zaxns9s997rhk-lnav-0.11.2/bin/lnav* lrwxrwxrwx 3 root root 67 Jan 1 1970 node -> /nix/store/x8vrc1c6r8nn454whr99bxc5hdy5ybjf-nodejs-18.18.0/bin/node* lrwxrwxrwx 3 root root 66 Jan 1 1970 npm -> /nix/store/x8vrc1c6r8nn454whr99bxc5hdy5ybjf-nodejs-18.18.0/bin/npm* lrwxrwxrwx 3 root root 66 Jan 1 1970 npx -> /nix/store/x8vrc1c6r8nn454whr99bxc5hdy5ybjf-nodejs-18.18.0/bin/npx*

Slide 27

Slide 27

Nix store 1 2 3 4 5 6 7 8 9 10 11 12 13 14 $ which lnav /nix/store/hcv2abrk1mhsnz67xjasg3pwz4wdkw7q-devenv-profile/bin/lnav $ ls /nix/store/hcv2abrk1mhsnz67xjasg3pwz4wdkw7q-devenv-profile/bin/ -la total 36 dr-xr-xr-x 2 root root 4096 Jan 1 1970 ./ dr-xr-xr-x 6 root root 4096 Jan 1 1970 ../ lrwxrwxrwx 3 root root 71 Jan 1 1970 corepack -> /nix/store/x8vrc1c6r8nn454whr99bxc5hdy5ybjf-nodejs-18.18.0/bin/corepack* lrwxrwxrwx 3 root root 67 Jan 1 1970 honcho -> /nix/store/am744diswph5ml71n562k2rwhwk3ipw0-honcho-1.1.0/bin/honcho* lrwxrwxrwx 3 root root 76 Jan 1 1970 .honcho-wrapped -> /nix/store/am744diswph5ml71n562k2rwhwk3ipw0-honcho-1.1.0/bin/.honcho-wrapped* lrwxrwxrwx 2 root root 64 Jan 1 1970 lnav -> /nix/store/c9psaxm0syj8rriqdy8zaxns9s997rhk-lnav-0.11.2/bin/lnav* lrwxrwxrwx 3 root root 67 Jan 1 1970 node -> /nix/store/x8vrc1c6r8nn454whr99bxc5hdy5ybjf-nodejs-18.18.0/bin/node* lrwxrwxrwx 3 root root 66 Jan 1 1970 npm -> /nix/store/x8vrc1c6r8nn454whr99bxc5hdy5ybjf-nodejs-18.18.0/bin/npm* lrwxrwxrwx 3 root root 66 Jan 1 1970 npx -> /nix/store/x8vrc1c6r8nn454whr99bxc5hdy5ybjf-nodejs-18.18.0/bin/npx*

Slide 28

Slide 28

Nix store 1 2 3 4 5 6 7 8 9 10 11 12 13 14 $ which lnav /nix/store/hcv2abrk1mhsnz67xjasg3pwz4wdkw7q-devenv-profile/bin/lnav $ ls /nix/store/hcv2abrk1mhsnz67xjasg3pwz4wdkw7q-devenv-profile/bin/ -la total 36 dr-xr-xr-x 2 root root 4096 Jan 1 1970 ./ dr-xr-xr-x 6 root root 4096 Jan 1 1970 ../ lrwxrwxrwx 3 root root 71 Jan 1 1970 corepack -> /nix/store/x8vrc1c6r8nn454whr99bxc5hdy5ybjf-nodejs-18.18.0/bin/corepack* lrwxrwxrwx 3 root root 67 Jan 1 1970 honcho -> /nix/store/am744diswph5ml71n562k2rwhwk3ipw0-honcho-1.1.0/bin/honcho* lrwxrwxrwx 3 root root 76 Jan 1 1970 .honcho-wrapped -> /nix/store/am744diswph5ml71n562k2rwhwk3ipw0-honcho-1.1.0/bin/.honcho-wrapped* lrwxrwxrwx 2 root root 64 Jan 1 1970 lnav -> /nix/store/c9psaxm0syj8rriqdy8zaxns9s997rhk-lnav-0.11.2/bin/lnav* lrwxrwxrwx 3 root root 67 Jan 1 1970 node -> /nix/store/x8vrc1c6r8nn454whr99bxc5hdy5ybjf-nodejs-18.18.0/bin/node* lrwxrwxrwx 3 root root 66 Jan 1 1970 npm -> /nix/store/x8vrc1c6r8nn454whr99bxc5hdy5ybjf-nodejs-18.18.0/bin/npm* lrwxrwxrwx 3 root root 66 Jan 1 1970 npx -> /nix/store/x8vrc1c6r8nn454whr99bxc5hdy5ybjf-nodejs-18.18.0/bin/npx*

Slide 29

Slide 29

Nix store 1 2 3 4 5 6 7 8 9 10 11 12 13 14 $ which lnav /nix/store/hcv2abrk1mhsnz67xjasg3pwz4wdkw7q-devenv-profile/bin/lnav $ ls /nix/store/hcv2abrk1mhsnz67xjasg3pwz4wdkw7q-devenv-profile/bin/ -la total 36 dr-xr-xr-x 2 root root 4096 Jan 1 1970 ./ dr-xr-xr-x 6 root root 4096 Jan 1 1970 ../ lrwxrwxrwx 3 root root 71 Jan 1 1970 corepack -> /nix/store/x8vrc1c6r8nn454whr99bxc5hdy5ybjf-nodejs-18.18.0/bin/corepack* lrwxrwxrwx 3 root root 67 Jan 1 1970 honcho -> /nix/store/am744diswph5ml71n562k2rwhwk3ipw0-honcho-1.1.0/bin/honcho* lrwxrwxrwx 3 root root 76 Jan 1 1970 .honcho-wrapped -> /nix/store/am744diswph5ml71n562k2rwhwk3ipw0-honcho-1.1.0/bin/.honcho-wrapped* lrwxrwxrwx 2 root root 64 Jan 1 1970 lnav -> /nix/store/c9psaxm0syj8rriqdy8zaxns9s997rhk-lnav-0.11.2/bin/lnav* lrwxrwxrwx 3 root root 67 Jan 1 1970 node -> /nix/store/x8vrc1c6r8nn454whr99bxc5hdy5ybjf-nodejs-18.18.0/bin/node* lrwxrwxrwx 3 root root 66 Jan 1 1970 npm -> /nix/store/x8vrc1c6r8nn454whr99bxc5hdy5ybjf-nodejs-18.18.0/bin/npm* lrwxrwxrwx 3 root root 66 Jan 1 1970 npx -> /nix/store/x8vrc1c6r8nn454whr99bxc5hdy5ybjf-nodejs-18.18.0/bin/npx*

Slide 30

Slide 30

Cachix “ Nix binary cache hosting ”

Slide 31

Slide 31

Devenv “ Fast, Declarative, Reproducible, and Composable Developer Environments using Nix ”

Slide 32

Slide 32

Hello nix

Slide 33

Slide 33

Lab Hello world • Initialiser devenv • Démarrer le devenv shell • Observer les changements sur git • devenv info Étape: 01-hello-world

Slide 34

Slide 34

Devenv: syntaxe, doc et languges

Slide 35

Slide 35

devenv.yaml inputs: nixpkgs: url: github:NixOS/nixpkgs/nixpkgs-unstable

Slide 36

Slide 36

devenv.yaml allowUnfree: true inputs: nixpkgs: url: github:NixOS/nixpkgs/nixpkgs-unstable myproject: url: github:owner/myproject flake: false myproject2: url: github:owner/myproject overlays: - default imports: - ./frontend - ./backend - ./mymodule.nix - myproject myproject/relative/path

Slide 37

Slide 37

Syntaxe nix pour Devenv Exemple de fichier devenv.nix { pkgs, … }: { languages.rust = { enable = true; channel = “nightly”; components = [ “rustc” “cargo” “clippy” “rustfmt” “rust-analyzer” ]; }; #pre-commit.hooks = { # rustfmt.enable = true;

clippy.enable = true; #}; packages = [ pkgs.git pkgs.curl pkgs.jq pkgs.usql ]; } Chaque instruction se termine par un ;

Slide 38

Slide 38

Syntaxe nix Fonctions { pkgs, lib, … }: { # … } Le : sépare les arguments de la fonction de son corps

Slide 39

Slide 39

Syntaxe nix Attribute Sets - ou comment regrouper les clés { languages.rust.enable = true; languages.rust.channel = “nightly”; } { languages.rust = { enable = true; channel = “nightly”; } }

Slide 40

Slide 40

Syntaxe nix Tableaux { packages = [ pkgs.git pkgs.curl pkgs.jq pkgs.usql ]; } Pas de , entre les éléments d’un tableau

Slide 41

Slide 41

Nix Package https://search.nixos.org/packages

Slide 42

Slide 42

Référence de toutes les clés du devenv.nix https://devenv.sh/reference/options/

Slide 43

Slide 43

Lab Hello JQ • On ajoute le package jq • Help: devenv search jq Étape: 02-jq

Slide 44

Slide 44

Interlude direnv

Slide 45

Slide 45

direnv, un outil pour gérer votre $ENV # .envrc export WORKSHOP=”devenv” export CURRENT_STEP=”jq” 1 $ cd 02-jq 2 direnv: loading /workspaces/workshop-devenv/steps/02-jq/.envrc 3 direnv: export +CURRENT_STEP +WORKSHOP 4 5 $ cd .. 6 direnv: unloading

Slide 46

Slide 46

direnv, un outil pour gérer votre $ENV # .envrc export WORKSHOP=”devenv” export CURRENT_STEP=”jq” 1 $ cd 02-jq 2 direnv: loading /workspaces/workshop-devenv/steps/02-jq/.envrc 3 direnv: export +CURRENT_STEP +WORKSHOP 4 5 $ cd .. 6 direnv: unloading

Slide 47

Slide 47

direnv, un outil pour gérer votre $ENV # .envrc export WORKSHOP=”devenv” export CURRENT_STEP=”jq” 1 $ cd 02-jq 2 direnv: loading /workspaces/workshop-devenv/steps/02-jq/.envrc 3 direnv: export +CURRENT_STEP +WORKSHOP 4 5 $ cd .. 6 direnv: unloading

Slide 48

Slide 48

direnv, un outil pour gérer votre $ENV # .envrc export WORKSHOP=”devenv” export CURRENT_STEP=”jq” 1 $ cd 02-jq 2 direnv: loading /workspaces/workshop-devenv/steps/02-jq/.envrc 3 direnv: export +CURRENT_STEP +WORKSHOP 4 5 $ cd .. 6 direnv: unloading

Slide 49

Slide 49

Intégrations direnv 1 2 3 4 5 6

.envrc layout node

source_url “https://raw.githubusercontent.com/cachix/devenv/d1f7b48e35e6dee421cfd0f51481d17f77586997/direnvrc” “sha256-YBzqskFZxmNb3kYVoKD9 use devenv L’intégration devenv lance automatiquement un devenv shell dans un dossier avec devenv

Slide 50

Slide 50

Intégrations direnv 1 2 3 4 5 6

.envrc layout node

source_url “https://raw.githubusercontent.com/cachix/devenv/d1f7b48e35e6dee421cfd0f51481d17f77586997/direnvrc” “sha256-YBzqskFZxmNb3kYVoKD9 use devenv L’intégration devenv lance automatiquement un devenv shell dans un dossier avec devenv

Slide 51

Slide 51

Devenv: les languages

Slide 52

Slide 52

Avec des packages { pkgs, … }: { packages = [ pkgs.rustc pkgs.cargo pkgs.clippy pkgs.rustfmt pkgs.rust-analyzer } ];

Slide 53

Slide 53

Syntaxe des languages { pkgs, … }: { languages.rust = { enable = true; channel = “stable”; }; } https://devenv.sh/languages/

Slide 54

Slide 54

Comment garder devenv à jour ?

Slide 55

Slide 55

devenv update 1 $ devenv update 2 warning: updating lock file ‘/home/jtanguy/Sfeir/workshop-devenv/docs/devenv.lock’: 3 • Updated input ‘devenv’: 4 ‘github:cachix/devenv/895e8403410c3ec14d1e8cae94e88b4e7e2e8c2f?dir=src%2fmodules’ (2023-12-10) 5 → ‘github:cachix/devenv/0e68853bb27981a4ffd7a7225b59ed84f7180fc7?dir=src%2fmodules’ (2024-02-03) 6 • Updated input ‘nixpkgs’: 7 ‘github:NixOS/nixpkgs/29d6c96900b9b576c2fb89491452f283aa979819’ (2023-12-10) 8 → ‘github:NixOS/nixpkgs/8cc79aa39bbc6eaedaf286ae655b224c71e02907’ (2024-02-06) 9 • Updated input ‘pre-commit-hooks’: 10 ‘github:cachix/pre-commit-hooks.nix/e1d203c2fa7e2593c777e490213958ef81f71977’ (2023-12-11) 11 → ‘github:cachix/pre-commit-hooks.nix/0db2e67ee49910adfa13010e7f012149660af7f0’ (2024-02-07) 12 • Updated input ‘pre-commit-hooks/flake-compat’: 13 ‘github:edolstra/flake-compat/35bb57c0c8d8b62bbfd284272c928ceb64ddbde9’ (2023-01-17) 14 → ‘github:edolstra/flake-compat/0f9255e01c2351cc7d116c072cb317785dd33b33’ (2023-10-04) 15 • Updated input ‘pre-commit-hooks/flake-utils’: 16 ‘github:numtide/flake-utils/a1720a10a6cfe8234c0e93907ffe81be440f4cef’ (2023-05-31) 17 → ‘github:numtide/flake-utils/4022d587cbbfd70fe950c1e2083a02621806a725’ (2023-12-04) 18 • Updated input ‘pre-commit-hooks/gitignore’: 19 ‘github:hercules-ci/gitignore.nix/a20de23b925fd8264fd7fad6454652e142fd7f73’ (2022-08-14) 20 → ‘github:hercules-ci/gitignore.nix/43e1aa1308018f37118e34d3a9cb4f5e75dc11d5’ (2023-12-29) 21 • Updated input ‘pre-commit-hooks/nixpkgs-stable’: 22 ‘github:NixOS/nixpkgs/c37ca420157f4abc31e26f436c1145f8951ff373’ (2023-06-03) 23 → ‘github:NixOS/nixpkgs/3dc440faeee9e889fe2d1b4d25ad0f430d449356’ (2024-01-10)

Slide 56

Slide 56

devenv update 1 $ devenv update 2 warning: updating lock file ‘/home/jtanguy/Sfeir/workshop-devenv/docs/devenv.lock’: 3 • Updated input ‘devenv’: 4 ‘github:cachix/devenv/895e8403410c3ec14d1e8cae94e88b4e7e2e8c2f?dir=src%2fmodules’ (2023-12-10) 5 → ‘github:cachix/devenv/0e68853bb27981a4ffd7a7225b59ed84f7180fc7?dir=src%2fmodules’ (2024-02-03) 6 • Updated input ‘nixpkgs’: 7 ‘github:NixOS/nixpkgs/29d6c96900b9b576c2fb89491452f283aa979819’ (2023-12-10) 8 → ‘github:NixOS/nixpkgs/8cc79aa39bbc6eaedaf286ae655b224c71e02907’ (2024-02-06) 9 • Updated input ‘pre-commit-hooks’: 10 ‘github:cachix/pre-commit-hooks.nix/e1d203c2fa7e2593c777e490213958ef81f71977’ (2023-12-11) 11 → ‘github:cachix/pre-commit-hooks.nix/0db2e67ee49910adfa13010e7f012149660af7f0’ (2024-02-07) 12 • Updated input ‘pre-commit-hooks/flake-compat’: 13 ‘github:edolstra/flake-compat/35bb57c0c8d8b62bbfd284272c928ceb64ddbde9’ (2023-01-17) 14 → ‘github:edolstra/flake-compat/0f9255e01c2351cc7d116c072cb317785dd33b33’ (2023-10-04) 15 • Updated input ‘pre-commit-hooks/flake-utils’: 16 ‘github:numtide/flake-utils/a1720a10a6cfe8234c0e93907ffe81be440f4cef’ (2023-05-31) 17 → ‘github:numtide/flake-utils/4022d587cbbfd70fe950c1e2083a02621806a725’ (2023-12-04) 18 • Updated input ‘pre-commit-hooks/gitignore’: 19 ‘github:hercules-ci/gitignore.nix/a20de23b925fd8264fd7fad6454652e142fd7f73’ (2022-08-14) 20 → ‘github:hercules-ci/gitignore.nix/43e1aa1308018f37118e34d3a9cb4f5e75dc11d5’ (2023-12-29) 21 • Updated input ‘pre-commit-hooks/nixpkgs-stable’: 22 ‘github:NixOS/nixpkgs/c37ca420157f4abc31e26f436c1145f8951ff373’ (2023-06-03) 23 → ‘github:NixOS/nixpkgs/3dc440faeee9e889fe2d1b4d25ad0f430d449356’ (2024-01-10)

Slide 57

Slide 57

devenv update 1 $ devenv update 2 warning: updating lock file ‘/home/jtanguy/Sfeir/workshop-devenv/docs/devenv.lock’: 3 • Updated input ‘devenv’: 4 ‘github:cachix/devenv/895e8403410c3ec14d1e8cae94e88b4e7e2e8c2f?dir=src%2fmodules’ (2023-12-10) 5 → ‘github:cachix/devenv/0e68853bb27981a4ffd7a7225b59ed84f7180fc7?dir=src%2fmodules’ (2024-02-03) 6 • Updated input ‘nixpkgs’: 7 ‘github:NixOS/nixpkgs/29d6c96900b9b576c2fb89491452f283aa979819’ (2023-12-10) 8 → ‘github:NixOS/nixpkgs/8cc79aa39bbc6eaedaf286ae655b224c71e02907’ (2024-02-06) 9 • Updated input ‘pre-commit-hooks’: 10 ‘github:cachix/pre-commit-hooks.nix/e1d203c2fa7e2593c777e490213958ef81f71977’ (2023-12-11) 11 → ‘github:cachix/pre-commit-hooks.nix/0db2e67ee49910adfa13010e7f012149660af7f0’ (2024-02-07) 12 • Updated input ‘pre-commit-hooks/flake-compat’: 13 ‘github:edolstra/flake-compat/35bb57c0c8d8b62bbfd284272c928ceb64ddbde9’ (2023-01-17) 14 → ‘github:edolstra/flake-compat/0f9255e01c2351cc7d116c072cb317785dd33b33’ (2023-10-04) 15 • Updated input ‘pre-commit-hooks/flake-utils’: 16 ‘github:numtide/flake-utils/a1720a10a6cfe8234c0e93907ffe81be440f4cef’ (2023-05-31) 17 → ‘github:numtide/flake-utils/4022d587cbbfd70fe950c1e2083a02621806a725’ (2023-12-04) 18 • Updated input ‘pre-commit-hooks/gitignore’: 19 ‘github:hercules-ci/gitignore.nix/a20de23b925fd8264fd7fad6454652e142fd7f73’ (2022-08-14) 20 → ‘github:hercules-ci/gitignore.nix/43e1aa1308018f37118e34d3a9cb4f5e75dc11d5’ (2023-12-29) 21 • Updated input ‘pre-commit-hooks/nixpkgs-stable’: 22 ‘github:NixOS/nixpkgs/c37ca420157f4abc31e26f436c1145f8951ff373’ (2023-06-03) 23 → ‘github:NixOS/nixpkgs/3dc440faeee9e889fe2d1b4d25ad0f430d449356’ (2024-01-10)

Slide 58

Slide 58

devenv update 1 $ devenv update 2 warning: updating lock file ‘/home/jtanguy/Sfeir/workshop-devenv/docs/devenv.lock’: 3 • Updated input ‘devenv’: 4 ‘github:cachix/devenv/895e8403410c3ec14d1e8cae94e88b4e7e2e8c2f?dir=src%2fmodules’ (2023-12-10) 5 → ‘github:cachix/devenv/0e68853bb27981a4ffd7a7225b59ed84f7180fc7?dir=src%2fmodules’ (2024-02-03) 6 • Updated input ‘nixpkgs’: 7 ‘github:NixOS/nixpkgs/29d6c96900b9b576c2fb89491452f283aa979819’ (2023-12-10) 8 → ‘github:NixOS/nixpkgs/8cc79aa39bbc6eaedaf286ae655b224c71e02907’ (2024-02-06) 9 • Updated input ‘pre-commit-hooks’: 10 ‘github:cachix/pre-commit-hooks.nix/e1d203c2fa7e2593c777e490213958ef81f71977’ (2023-12-11) 11 → ‘github:cachix/pre-commit-hooks.nix/0db2e67ee49910adfa13010e7f012149660af7f0’ (2024-02-07) 12 • Updated input ‘pre-commit-hooks/flake-compat’: 13 ‘github:edolstra/flake-compat/35bb57c0c8d8b62bbfd284272c928ceb64ddbde9’ (2023-01-17) 14 → ‘github:edolstra/flake-compat/0f9255e01c2351cc7d116c072cb317785dd33b33’ (2023-10-04) 15 • Updated input ‘pre-commit-hooks/flake-utils’: 16 ‘github:numtide/flake-utils/a1720a10a6cfe8234c0e93907ffe81be440f4cef’ (2023-05-31) 17 → ‘github:numtide/flake-utils/4022d587cbbfd70fe950c1e2083a02621806a725’ (2023-12-04) 18 • Updated input ‘pre-commit-hooks/gitignore’: 19 ‘github:hercules-ci/gitignore.nix/a20de23b925fd8264fd7fad6454652e142fd7f73’ (2022-08-14) 20 → ‘github:hercules-ci/gitignore.nix/43e1aa1308018f37118e34d3a9cb4f5e75dc11d5’ (2023-12-29) 21 • Updated input ‘pre-commit-hooks/nixpkgs-stable’: 22 ‘github:NixOS/nixpkgs/c37ca420157f4abc31e26f436c1145f8951ff373’ (2023-06-03) 23 → ‘github:NixOS/nixpkgs/3dc440faeee9e889fe2d1b4d25ad0f430d449356’ (2024-01-10)

Slide 59

Slide 59

devenv update 1 $ devenv update 2 warning: updating lock file ‘/home/jtanguy/Sfeir/workshop-devenv/docs/devenv.lock’: 3 • Updated input ‘devenv’: 4 ‘github:cachix/devenv/895e8403410c3ec14d1e8cae94e88b4e7e2e8c2f?dir=src%2fmodules’ (2023-12-10) 5 → ‘github:cachix/devenv/0e68853bb27981a4ffd7a7225b59ed84f7180fc7?dir=src%2fmodules’ (2024-02-03) 6 • Updated input ‘nixpkgs’: 7 ‘github:NixOS/nixpkgs/29d6c96900b9b576c2fb89491452f283aa979819’ (2023-12-10) 8 → ‘github:NixOS/nixpkgs/8cc79aa39bbc6eaedaf286ae655b224c71e02907’ (2024-02-06) 9 • Updated input ‘pre-commit-hooks’: 10 ‘github:cachix/pre-commit-hooks.nix/e1d203c2fa7e2593c777e490213958ef81f71977’ (2023-12-11) 11 → ‘github:cachix/pre-commit-hooks.nix/0db2e67ee49910adfa13010e7f012149660af7f0’ (2024-02-07) 12 • Updated input ‘pre-commit-hooks/flake-compat’: 13 ‘github:edolstra/flake-compat/35bb57c0c8d8b62bbfd284272c928ceb64ddbde9’ (2023-01-17) 14 → ‘github:edolstra/flake-compat/0f9255e01c2351cc7d116c072cb317785dd33b33’ (2023-10-04) 15 • Updated input ‘pre-commit-hooks/flake-utils’: 16 ‘github:numtide/flake-utils/a1720a10a6cfe8234c0e93907ffe81be440f4cef’ (2023-05-31) 17 → ‘github:numtide/flake-utils/4022d587cbbfd70fe950c1e2083a02621806a725’ (2023-12-04) 18 • Updated input ‘pre-commit-hooks/gitignore’: 19 ‘github:hercules-ci/gitignore.nix/a20de23b925fd8264fd7fad6454652e142fd7f73’ (2022-08-14) 20 → ‘github:hercules-ci/gitignore.nix/43e1aa1308018f37118e34d3a9cb4f5e75dc11d5’ (2023-12-29) 21 • Updated input ‘pre-commit-hooks/nixpkgs-stable’: 22 ‘github:NixOS/nixpkgs/c37ca420157f4abc31e26f436c1145f8951ff373’ (2023-06-03) 23 → ‘github:NixOS/nixpkgs/3dc440faeee9e889fe2d1b4d25ad0f430d449356’ (2024-01-10)

Slide 60

Slide 60

Hello python

Slide 61

Slide 61

Lab Hello python • Ajouter le package python • Lancer le script hello.py Étape: 03-python

Slide 62

Slide 62

Lab Hello python v2 • Migrer vers le language python • Lancer le script hello.py • Mettre à jour l’environnement de dev Étape: 03-python

Slide 63

Slide 63

Devenv: Scripts, processes et services

Slide 64

Slide 64

Scripts Permet de définir des scripts utilitaires au projet { pkgs, … }: { packages = [ pkgs.curl pkgs.jq ]; scripts.silly-example.exec = ” curl “https://httpbin.org/get?$1” | jq ‘.args’ ”; }

Slide 65

Slide 65

Scripts On peut utiliser les binaires sans les inclure dans le packages { pkgs, … }: { packages = [pkgs.jq]; scripts.devenv-bump-version.exec = ” # TODO: ask for the new version # TODO: update the version in the mkdocs.yml echo assuming you bumped the version in mkdocs.yml, populating src/modules/latest-version cat mkdocs.yml | ${pkgs.yaml2json}/bin/yaml2json | jq -r ‘.extra.devenv.version’ > src/modules/latest-version ”; }

Slide 66

Slide 66

Processes Les processes sont tous démarrés par devenv up (honcho est utilisé sous le capot) { pkgs, … }: { processes = { silly-example.exec = “while true; do echo hello && sleep 1; done”; ping.exec = “ping example.com”; }; } $ devenv up Starting processes … 20:37:44 20:37:44 20:37:44 20:37:44 20:37:44 20:37:45 20:37:45 20:37:46 20:37:46 20:37:47 20:37:47 … system system silly-example.1 ping.1 ping.1 silly-example.1 ping.1 silly-example.1 ping.1 silly-example.1 ping.1 | | | | | | | | | | | ping.1 started (pid=4094686) silly-example.1 started (pid=4094688) hello PING example.com (93.184.216.34) 56(84) bytes of data. 64 bytes from 93.184.216.34 (93.184.216.34): icmp_seq=1 hello 64 bytes from 93.184.216.34 (93.184.216.34): icmp_seq=2 hello 64 bytes from 93.184.216.34 (93.184.216.34): icmp_seq=3 hello 64 bytes from 93.184.216.34 (93.184.216.34): icmp_seq=4 ttl=55 time=125 ms ttl=55 time=125 ms ttl=55 time=125 ms ttl=55 time=125 ms

Slide 67

Slide 67

Services • packages -> languages • processes -> services https://devenv.sh/services/#supported-services { pkgs, … }: { services.redis.enable = true; }

Slide 68

Slide 68

Hello Scripts, Processes et Services

Slide 69

Slide 69

Lab Script, process et service • Écrire un process docs qui lance mkdocs serve • Configurer le service postgres pour créer une DB workshop avec ./db/init.sql • Créer un script pour se connecter à la DB avec usql postgres://localhost:5432/workshop Étape: 04-scripts

Slide 70

Slide 70

Hello Realworld

Slide 71

Slide 71

Lab Realworld app • Backend + frontend • PostgreSQL en DB Étape: 05-realworld