--- # NixOS Vorstellung NixOS und Nix für Interessierte
[Johannes Bornhold](https://mastodon.social/@johbo) --- # Warum bist Du hier? Notes: - Kurze Runde durch die Teilnehmer --- ## Überblick - Nix Universum - Beispiele anhand von GNU Hello - Wo anfangen? - Hilfreiche Quellen [Nixmap](https://vimjoyer.com/nixmap/): Yurii M., [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/) Notes: - Einmal umreißen welche Themen wir besprechen müssten - Vorbereitung für die Fragerunde --- ## Nix Universum * Theorie * Anwendungsfälle * Erst einmal nur ein Überblick * Danach probieren wir das an kleinen Beispielen --- # Ohne Nix geht nix! Notes: - Nix ist die Basis - von allem - Hier müssen wir einmal durch - hilft nix! -v- ## Das CLI Tool ```sh nix --help ``` > nix - a tool for reproducible and declarative configuration management Notes: - Gibt es noch Fragen? -v- ## Das Handbuch > Nix is a purely functional package manager. This means that it treats packages like values in a purely functional programming language — packages are built by functions that don’t have side-effects, and they never change after they have been built. Nix stores packages in the Nix store, usually the directory /nix/store, where each package has its own unique subdirectory such as > > /nix/store/q06x3jll2yfzckz2bzqak089p43ixkkq-firefox-33.1/ > > where b6gvzjyb2pg0… is a unique identifier for the package that captures all its dependencies (it’s a cryptographic hash of the package’s build dependency graph). This enables many powerful features. Aus dem Handbuch, [nixos.org](https://nixos.org) Notes: - Jetzt wird es klar - purely functional package manager - values in a purely functional programming language - functions without side-effects - never change after built (immutable) - gespeichert im Nix Store - hash of build dependency graph - Mitnehmen - This enables many powerful features. - Die Handbücher sind gut! - Nix, Nixpkgs, NixOS - Aber auch umfangreich. - https://nixos.org - Learn, Scrollen, "Full ... Manual" -v- ## Eelco Dolstra > This thesis is about getting computer programs from one machine to another—and > having them still work when they get there. > > [...] > > This thesis describes a system for software deployment called Nix that > addresses many of the problems that plague existing deployment systems. 2006, The Purely Functional Software Deployment Model, Eelco Dolstra, [nixos.org/research](https://nixos.org/research/) Notes: - Forschungspapiere sind lesbar und lesenswert. -v- ## Nix - Was ist das? - baut Dinge - Build Tool - reproduzierbar - reproducible - deklarativ - declarative - configuration management - package manager - purely functional Notes: - Zusammenfassung - Dann ist Theorie auch vorbei - Build tool - baut Dinge - reproducible - reproduzierbar - Wenn ich die gleichen Inputs verwende - dann kommt auch das gleiche Ergebnis raus - declarative - deklarativ - Beschreibe einen Soll-Zustand - Nix kann dass dann bauen und als Ergebnis liefern --- # Anwendungsfälle Notes: - Einmal durchatmen! --- ## Pakete bauen * Nix * Nixpkgs
Beispiel: ```sh $ nix build nixpkgs#hello # Oder ausführen $ nix run nixpkgs#hello Hello, world! ```
Notes: - Bitte unbedingt ausprobieren - Wer Pakete bauen versteht und beherrscht hat es in allen anderen Bereichen leichter. - Die anderen Layer bauen alle hierauf auf. - Handbücher - Für Nix und auch Nixpkgs gibt es Handbücher (Erinnerung) --- ## Exkurs - Flakes ```nix { description = "home-ops NixOS machines and docs"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-26.05"; # [ ... ] }; outputs = { self, ... }@inputs: let lib = nixpkgs.lib; in { nixosConfigurations = { nextcloud = lib.nixosSystem { specialArgs = { inherit self inputs; }; modules = [ base-users.nixosModules.base-users inputs.microvm.nixosModules.microvm ./hosts/nextcloud.nix ]; }; }; }; } ``` Notes: - Flakes - Ist so ein "Thema" - Sehr verbreitet, sehr nützlich und sehr experimentell - My take - Aktiviert Flakes und nutzt sie. - Wenn Ihr tief drin seid, dann bildet Euch eine eigene Meinung dazu. -v- ## Exkurs - Flakes 2 ```sh $ nix flake show git+file:///home/joh/wbt/infra/home-ops?dir=nixos&ref=refs/heads/main&rev=75597ceac0557f2c533ead64e28add603063fb6f ├───checks │ └───x86_64-linux │ ├───docker-host-runner: derivation 'docker-host-runner-eval-ok' │ └───nextcloud-runner: derivation 'nextcloud-runner-eval-ok' ├───nixosConfigurations │ ├───anduril: NixOS configuration │ ├───builder-aarch64-hetzner: NixOS configuration │ ├───colossus: NixOS configuration │ ├───docker-host: NixOS configuration │ ├───glamdring: NixOS configuration │ ├───hobbit: NixOS configuration │ ├───jonathan: NixOS configuration │ ├───jonathan-vm: NixOS configuration │ ├───mithril: NixOS configuration │ ├───nextcloud: NixOS configuration │ ├───samwise: NixOS configuration │ └───sting: NixOS configuration └───packages ├───aarch64-linux │ ├───hobbit-sd-image omitted (use '--all-systems' to show) │ ├───installer omitted (use '--all-systems' to show) │ └───samwise-sd-image omitted (use '--all-systems' to show) └───x86_64-linux ├───diagnostic-installer: package 'nixos-installer-x86_64-linux.iso' └───installer: package 'nixos-installer-x86_64-linux.iso' ``` Notes: - Beispiel wie man mit `nix flake` interagiert - Zeigt was in der Flake drin ist. --- ## NixOS - Betriebssystem ```nix { pkgs, ... }: { imports = [ ../profiles/microvm-guest.nix ]; networking.hostName = "nextcloud"; networking.interfaces.eth0.ipv4.addresses = [ { address = "192.168.100.33"; prefixLength = 24; } ]; networking.firewall.allowedTCPPorts = [ 80 ]; services.nextcloud = { enable = true; package = pkgs.nextcloud35; hostName = "192.168.100.33"; configureRedis = true; database.createLocally = true; config = { dbtype = "pgsql"; adminpassFile = "/var/lib/nextcloud/admin-pass"; }; }; microvm = { vcpu = 2; mem = 8192; interfaces = [ { type = "bridge"; id = "vm-nextcloud"; bridge = "br0"; mac = "02:00:00:64:21:01"; } ]; volumes = [ { mountPoint = "/var"; image = "nextcloud-var.img"; size = 40960; } ]; }; } ``` Notes: - Beispiel - Ziel - Konfigurationssprache einmal sehen - Erstes Gefühl für die Syntax - Virtuelle Maschine die ich für Nextcloud Experimente verwendet habe - Spannende Punkte - Konfiguration der Maschine - Netzwerk und Firewall - Nextcloud service ist eingeschaltet - Speziell: microvm.nix -v- ## NixOS ```sh $ nixos-rebuild build --flake .#nextcloud building the system configuration... Done. The new configuration is /nix/store/2s0zc21iazqgwz1nvkn6bk5spcahfsp5-nixos-system-nextcloud-26.05.20261102.7dcdd87 $ ls -l result [...] result -> /nix/store/2s0zc21iazqgwz1nvkn6bk5spcahfsp5-nixos-system-nextcloud-26.05.20261102.7dcdd87 ```
Die Basis ist Nix: ```sh nix build .#nixosConfigurations.nextcloud.config.system.build.toplevel ```
Notes: - Eine Maschine "bauen" ist auch nur wie ein Paket bauen - Mit `nixos-rebuild` kann man auch auf die lokale oder eine entfernte Machine deployen - Besonderheit Cache - Die Ziel-Maschine kann sich auch die nötigen Dinge aus cache.nixos.org ziehen - Und nur dass hochladen, was dort nicht verfügbar ist - Relevant: Server vom Notebook aus deployen --- ## Beispiel Inventarsystem ```sh $ nix flake show git+file:///home/joh/wspace/ktt-inventory-system?ref=refs/heads/deployment-docs&rev=aca8f3ae3dd31d81eaf290c35e97700410a907b3 ├───devShells │ ├───aarch64-darwin │ │ └───default omitted (use '--all-systems' to show) │ ├───aarch64-linux │ │ └───default omitted (use '--all-systems' to show) │ ├───x86_64-darwin │ │ └───default omitted (use '--all-systems' to show) │ └───x86_64-linux │ └───default: development environment 'nix-shell' └───packages ├───aarch64-darwin │ ├───container omitted (use '--all-systems' to show) │ └───container-nginx omitted (use '--all-systems' to show) ├───aarch64-linux │ ├───container omitted (use '--all-systems' to show) │ └───container-nginx omitted (use '--all-systems' to show) ├───x86_64-darwin │ ├───container omitted (use '--all-systems' to show) │ └───container-nginx omitted (use '--all-systems' to show) └───x86_64-linux ├───container: package 'stream-ktt-inventory' └───container-nginx: package 'stream-ktt-inventory-nginx' ``` Repository online:
Notes: - Der Code ist auf Github - Entwicklungsumgebung - Container - Könnte auch ein NixOS Modul enthalten -v- ## Entwicklungsumgebung ```sh nix develop # Beispiel Inventarsystem ./manage.py runserver 8001 ``` -v- ## Container bauen ```sh nix build .#container # Image in Podman laden ./result | podman load ``` -v- ## Container bauen 2 ```sh $ ./result | podman load Creating layer 1 from paths: ['/nix/store/hlsqbimvy4r0hcr45ig0vlilbr9cwmzx-group'] Creating layer 2 from paths: ['/nix/store/qzml9f4na9gbs67f9gmd7y32ark37n12-nsswitch.conf'] Creating layer 3 from paths: ['/nix/store/az3fllnyyjchak44ia1cd3bpc3wr9k98-passwd'] Creating layer 4 from paths: ['/nix/store/5pb3alylm5g7gppaq1img6bl6iqgqh4y-compiled-locale'] Creating layer 5 from paths: ['/nix/store/h13i4ll3mjswm4sswhrqai6crkn886jp-mailcap-2.1.54'] Creating layer 6 from paths: ['/nix/store/jwlz3mk67xb5jldfmnpw1ibhs1lbc0qr-asgiref-3.11.1'] Creating layer 7 from paths: ['/nix/store/80v5n8kdscr9r2ls8h72s8ppwmccwrgm-xgcc-16.2.0-libgcc'] Creating layer 8 from paths: ['/nix/store/qk6cz4ba571znqrsyhma192y8h50yi05-gcc-16.2.0-libgcc'] Creating layer 9 from paths: ['/nix/store/ikblldifkfy18y5x7hw2dcyz71j11xdk-ktt-inventory-system-0.1.0'] Creating layer 10 from paths: ['/nix/store/9zvya2jaw06hhmiq5i88izjdfgc7py5w-certifi-2026.10.23'] Creating layer 11 from paths: ['/nix/store/m1mymgabzk1prlcnpmgkdikmhjbyy5x8-requests-2.26.0'] Creating layer 12 from paths: ['/nix/store/d56p3jpksslx6pqypzl53xidcxxrz2kc-nss-cacert-3.131.1'] Creating layer 13 from paths: ['/nix/store/2ai7l8ddrcam899hcax4ljhcjx6bcyh0-packaging-26.2'] Creating layer 14 from paths: ['/nix/store/3485815ns07l7insrqhldb6w7cgysjy8-urllib3-1.26.20'] Creating layer 15 from paths: ['/nix/store/4r0d1hm8458zz59xrh22ga2p0nkwvbpy-libunistring-1.4.2'] Creating layer 16 from paths: ['/nix/store/s92hlmg73b3zlw38dfgm13v9cah2bm80-tzdata-2026f'] Creating layer 17 from paths: ['/nix/store/rwq5g35321vg407qwg7ynsqfz77iyrrp-libidn2-2.3.8'] Creating layer 18 from paths: ['/nix/store/r3hvhzl5fxhrgn0rfy5g7rda17702pj4-glibc-2.44-57'] Creating layer 19 from paths: ['/nix/store/930sd5x7lp8xnwvzk2fpzg5ffwbjgbcz-bzip2-1.0.8'] Creating layer 20 from paths: ['/nix/store/zy879gpqy4w1yyzf1q0cbfkpa9fvs7xf-libffi-3.8.0'] Creating layer 21 from paths: ['/nix/store/kp68n1q6r8lzpf5mxjmfasn3zq2pql4x-zlib-1.3.2'] Creating layer 22 from paths: ['/nix/store/ymmqql116m1913hq53piscjy6k2qm8rs-mpdecimal-4.0.1'] Creating layer 23 from paths: ['/nix/store/40ixrl4ppcv6xa7r17pqxrllb9wj3b6s-expat-2.9.0'] Creating layer 24 from paths: ['/nix/store/d7pn11xv3qyfdfx33fgwvcqlnxhlnhpj-libpng-apng-1.6.59'] Creating layer 25 from paths: ['/nix/store/saajq6cqys61zwg8lrcmfz0v2vx6ivnp-gdbm-1.26-lib'] Creating layer 26 from paths: ['/nix/store/7pqd3hafa9cbcy426lnx4qnb05psr4mf-libdeflate-1.26'] Creating layer 27 from paths: ['/nix/store/w4cjyk294i1h68z75z46dgws7hmma7m6-giflib-6.1.3'] Creating layer 28 from paths: ['/nix/store/28z11yz990sjcd8hh73r66mfk3mc4gab-lcms2-2.19.1'] Creating layer 29 from paths: ['/nix/store/5n1qsd423q10dlscj3k4np04imfv4nm2-xz-5.8.4'] Creating layer 30 from paths: ['/nix/store/sx0fyd6228r3m84d5bccs6d5kz81lh9n-brotli-1.2.1-lib'] Creating layer 31 from paths: ['/nix/store/hasnvc0j36gg6qrdsfcx7yivx3c2bpqr-bash-5.3p20'] Creating layer 32 from paths: ['/nix/store/459kh2fvd4n7ayy4jbmsafq64pm4yyhj-util-linux-minimal-2.42.4-lib'] Creating layer 33 from paths: ['/nix/store/254b1mxrkhfykqrrw4fhzf4ks9scgm1q-libjpeg-turbo-3.2.0'] Creating layer 34 from paths: ['/nix/store/92ymwd3gpjn4gf4gs9rhddmy3wi4zsb4-freetype-2.14.3'] Creating layer 35 from paths: ['/nix/store/adz753psjvfr4j597fprrh4p0cvjylx9-ncurses-6.6'] Creating layer 36 from paths: ['/nix/store/ga33b6wdnwl7lzkizgxfs9fraramsajy-readline-8.3p3'] Creating layer 37 from paths: ['/nix/store/b0gpq7815bq5bssdv0fkk8kpxrnjhcbm-libwebp-1.6.0'] Creating layer 38 from paths: ['/nix/store/da0jhl7dj82flrp9wld11jp3pvs9raxa-sqlite-3.54.0'] Creating layer 39 from paths: ['/nix/store/3h4ifcg10i9j0kj5c0cmas23v15pc7cl-openssl-3.5.9'] Creating layer 40 from paths: ['/nix/store/myhwfdgqm39yms5clinafii9i1nmq43h-gcc-16.2.0-lib'] Creating layer 41 from paths: ['/nix/store/ja8mqzwv5qclf4kc009y7pchx8cnkn3w-lerc-4.2.0'] Creating layer 42 from paths: ['/nix/store/2a69456iqj6rzzc2ys7l2yypsv1w6l5m-zstd-1.5.7'] Creating layer 43 from paths: ['/nix/store/v154wvscivq3j7cizhnfccyi8b1ws0kl-libtiff-4.7.2'] Creating layer 44 from paths: ['/nix/store/a2824bxrgxwn3p2lf91nmf6wi1pd882k-pillow-11.3.0'] Creating layer 45 from paths: ['/nix/store/rm0rvb03awsc448vj2sifkynqjpz158x-python3-3.13.18'] Creating layer 46 from paths: ['/nix/store/ln8s3x8rbylg8fw7zakxl8yc59pp2gha-charset-normalizer-2.0.12'] Creating layer 47 from paths: ['/nix/store/sqg1wh2gfsb4rgaaw1qqgs20kf1dkda5-sqlparse-0.5.5'] Creating layer 48 from paths: ['/nix/store/h0x4fbr18c87jb8kgdj66viiy80jwgv3-idna-3.18'] Creating layer 49 from paths: ['/nix/store/bdhp7chc1x61fbhj8l40r2sd36zm573y-gunicorn-23.0.0'] Creating layer 50 from paths: ['/nix/store/whx02npdmjaq885qdnx6sz7d2s21qaqn-django-5.2.15'] Creating layer 51 from paths: ['/nix/store/d5jkc9f1sznr1knrwamcbi9abhai1v66-container-env'] Creating layer 52 with customisation... ``` --- ## Home Manager * Dotfiles * User services * Einstellungen -v- ## Home Manager - Einbindung ```nix { sting = lib.nixosSystem { specialArgs = { inherit self inputs disko; }; modules = [ # [ ... ] home-manager.nixosModules.home-manager homeManagerDefaults { home-manager.users.joh = { imports = [ ./home/users/joh.nix ]; custom.packages.rust = true; home-ops.packages.languageServers = true; dconf.settings."org/gnome/settings-daemon/plugins/power" = { power-button-action = "nothing"; }; }; home-manager.users.jonathan = import ./home/users/jonathan.nix; } ./hosts/sting.nix ]; }; } ``` -v- ## Home Manager - Anpassungen ```nix # [ ... ] let # Element's Wayland app_id is `element`; GNOME matches it case-sensitively. element-desktop-wayland-wmclass = pkgs.symlinkJoin { name = "element-desktop-wayland-wmclass"; paths = [ pkgs.element-desktop ]; postBuild = '' rm $out/share/applications/element-desktop.desktop sed 's/^StartupWMClass=Element$/StartupWMClass=element/' \ ${pkgs.element-desktop}/share/applications/element-desktop.desktop \ > $out/share/applications/element-desktop.desktop ''; }; in { # [ ... ] home.packages = with pkgs; [ # Communication element-desktop-wayland-wmclass # [ ... ] ]; } ``` --- ## MacOS * Nix * Paketmanager * Läuft * Pakete auf Darwin sind nicht identisch mit Linux * `nix-darwin` * Systemkonfiguration mit Nix managen Notes: - `nix-darwin` habe ich noch nicht probiert - Nix habe ich viele Jahre auf dem Mac verwendet - Ab und an ist das speziell --- # Pause - Lüften - Luft holen - Durchatmen --- # Ausprobiert --- ## Kontext - GNU Hello - Beispiele aus `nix --help` - Wenn Nix installiert ist, dann kann man die direkt durchprobieren -v- ## GNU Hello ```raw · Create a new flake: │ # nix flake new hello │ # cd hello · Build the flake in the current directory: │ # nix build │ # ./result/bin/hello │ Hello, world! · Run the flake in the current directory: │ # nix run │ Hello, world! · Start a development shell for hacking on this flake: │ # nix develop │ # unpackPhase │ # cd hello-* │ # configurePhase │ # buildPhase │ # ./hello │ Hello, world! │ # installPhase │ # ../outputs/out/bin/hello │ Hello, world! ``` --- ## Loslegen - Empfehlung: Nix kennen lernen, dann NixOS --- ## Secrets - Bitte keine Passwörter in die Nix Dateien legen - Bitte auch nicht drauf verweisen - was im Nix Store landet ist öffentlich - Tools wie `sops-nix` verwenden -
--- ## Gute Quellen - Handbücher via
- Nixmap zur Orientierung
- Matrix Space
- Discourse
--- ## Kontakt Johannes Bornhold - Matrix: [@jbornhold:matrix.org](https://matrix.to/#/@jbornhold:matrix.org) - XMPP: [johbo@conversations.im](xmpp:johbo@conversations.im) - Mastodon: [@johbo@mastodon.social](https://mastodon.social/@johbo)