Your browser doesn't support the features required by impress.js, so you are presented with a simplified version of this presentation.

For the best experience please use the latest Chrome, Safari or Firefox browser.

NixOS
Eine Einführung

Datenspuren 2022

by winzlieb (c3d2)

Any element with the class="notes" will not be displayed. This can be used for speaker notes. In fact, the impressConsole plugin will show it in the speaker console!
# Was is NixOS? ![NixOS Logo](images/nix_icon_136356.svg) > Betriebssystem basierend auf > dem Nix Paketmanager, > welcher Build-Anweisungen in der > Nix-Expression-Language auswertet
# Was is NixOS? ** Gar nicht so schwer ** aber anderes Paradigma teilweise veraltete Dokumentation zu viele Wege etwas zu tun
# Was is NixOS? - pur - deklarativ - reproduzierbar - FUN ----- # Motivation ## Warum auch DU es willst - single point of truth - Roll-Back - Wiederverwendbarkeit - Code = Dokumentation - Infrastruktur als Code ----- # Perfekt für ... ## Anwendende - mehrere Systeme einheitlich verwalten - System-Generationen - Nutzerverwaltung - "Experimente" sauber abschließen ----- # Perfekt für ... ## DevOps - reproduzierbare Deployments - CI, Testing (z.B. [garnix-CI](https://garnix.io/)) - Build Isolation - Build und Binary-Cache (Hydra) ----- # Perfekt für ... ## Administration - Containerisierung - microvms statt Docker oder LXC - deklarative Infrastruktur - Komponentenbasierte Deployments ----- # Perfekt für ... ## Entwicklung - reproduzierbare Build-Umgebung - Service Puzzeling - vereint Paketmanager (npm, pip, pear, CPAN, go.get,..) - Dev-Shells - Pakete überschreiben
# Nix Expression Language - **pure ** - keine Seiteneffekte - **functional ** - Funktionen an erster Stelle - **maximum laziness ** - call-by-need
Nix Javascript
"Hello world!"
"Hello world!"
2/3
require("path").join("2", "3")
2/ 3
Math.ceil(2/3)
2/ 3.
2/3
(a: { a = a; }) 2
(a => ({ a: a }))(2)
(a: { inherit a; }) 2
(a => ({ a }))(2)
(a: b: { a = a; b = b; }) 2 3
((a, b) => ({ a: a, b: b }))(2, 3)
((a: b: { inherit a b; }) 2) 3
(a => b => ({ a, b }))(2)(3)
({ a }: { inherit a; }) { a = 2; }
(({ a }) => ({ a }))({ a: 2 })
({ a, b, ... }: { inherit a b; }) { a = 2; b = 3; c = 4; }
(({ a, b }) => ({ a, b }))({ a: 2, b: 3, c: 4 })
(a: { c = a.b.c; }) { b = { c = 2; }; }
(a => ({ c: a.b.c }))({ b: { c: 2 } })
(a: { inherit (a.b) c; }) { b = { c = 2; }; }
(a => ({ c: a.b.c }))({ b: { c: 2 } })
({ a ? 2 }: a) {}
(({ a = 2 }) => a)({})
let double = x: x*2; in double 3
const double = x => x*2; console.log(double(3));
let mul = a: (b: a*b); in (mul 2) 3
const mul = a => b => a*b; console.log(mul(2)(3));
let x = 3; mul = a: (b: a*b); in (mul 2) 3
const x = 3, mul = a => b => a*b; console.log(mul(x)(3));
if true then 3 else 2
true ? 3: 2
Quelle: github.com/rofrol/nix-for-javascript-developers

Nix Expressions

tour of Nix


nix eval --exp '(x: y: { a = x + "-" + y; }) "Datenspuren" "2022"'
        

❯ nix repl
Welcome to Nix 2.9.1. Type :? for help.

nix-repl> (x: y: { a = x + "-" + y; }) "Datenspuren" "2022"
{ a = "Datenspuren-2022"; }
        

Nix Derivation

with import <nixpkgs> {}; stdenv.mkDerivation {
   name = "hello";
   src = ./src;
   buildInputs = [ coreutils gcc ];
   configurePhase = ''
     declare -xp
   '';
   buildPhase = ''
     gcc "$src/hello.c" -o ./hello
   '';
   installPhase = ''
     mkdir -p "$out/bin"
     cp ./hello "$out/bin/"
   '';
}
default.nix

Trivial Builder

with import <nixpkgs> {};
  runCommand "name" {envVariable = true;} ''echo hello > $out''
default.nix

Nix Store

/nix/store/$(cryptographic-hash)-$(package-name)-$(version)/$(package-contents)

❯ ls /nix/store/*hello*
/nix/store/g4dl2djh719933klf04bmmrjdswfpzip-hello-2.10.tar.gz.drv
/nix/store/qpskxiffl94sy3awnwprra2id9r911zr-hello-2.10.drv
/nix/store/dd617z4bscvvv6i0d9d1x2ml96pi04nk-hello-2.10:
    bin share
        
        

Nix Store

graph TD A(/nix/var/nix/profiles/
-> system
-> system-1) B(/nix/store/874apvv5hvnvg2qgr2m3vx392803i7h4-nixos-system-T15g-22.05.20220614.9ff91ce
->kernel
->initrd
->etc
->sw ) C(/nix/store/qcnwsysqmj5xvvr2w5lfksx3r9syxbhs-system-path
->bin
->lib
->sbin) D(/nix/store/6ycia1xk500pxssx5nk1hppxh6c0rl99-git-2.36.2/bin/git) A-->B B-->C C-->D

Nix Store

Nix Store Quelle: www.infoq.com/articles/configuration-management-with-nix/

Nix Modules

Organisationsstruktur für Betriebssystem-komponenten und Dienste mit Konfigurationsoptionen


search.nixos.org/options

oder

man configuration.nix

Nix Modules

{ config, lib, pkgs, ... }:
with lib;
let
  cfg = config.services.uptimed;
  stateDir = "/var/lib/uptimed";
in
{
  options = {
    services.uptimed = {
      enable = mkOption {
        type = types.bool;
        default = false;
        description = lib.mdDoc ''
          Enable `uptimed`, allowing you to track
          your highest uptimes.
        '';
      };
    };
  };

  config = mkIf cfg.enable {
    environment.systemPackages = [ pkgs.uptimed ];
    users.users.uptimed = {
      description = "Uptimed daemon user";
      home        = stateDir;
      uid         = config.ids.uids.uptimed;
      group       = "uptimed";
    };
    users.groups.uptimed = {};
    systemd.services.uptimed = {
      description = "uptimed service";
      wantedBy    = [ "multi-user.target" ];
      serviceConfig = {
        Restart                 = "on-failure";
        User                    = "uptimed";
        StateDirectory          = [ "uptimed" ];
        ExecStart               = "${pkgs.uptimed}/sbin/uptimed -f -p ${stateDir}/pid";
      };
    };
  };
}
        
# Nixpkgs Hauptverzeichnis Community-Verwalteter Pakete und Module [github:NixOS/nixpkgs](https://github.com/NixOS/nixpkgs/) - unstable - 22.05 - 21.11 ;-) beste Nix-Dokumentation
# Nix Flakes Lösen nix-channels ab - inputs - outputs - lock-Datei - Version-pinning - ähnlich crates, go-modules

Nix Flakes

{
  outputs = { self }: {
    foo = "Datenspuren";
  };
}
{
  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs";
  };

  outputs = { self, nixpkgs }: {
    packages.x86_64-linux.hello = nixpkgs.legacyPackages.x86_64-linux.hello;
  };
}

Nix Flakes

flake Kommandos
  • nix shell
  • nix build
  • nix run
  • nix develop
  • nix flake show
"alte" Kommandos
  • nix-shell
  • nix-run
  • nix-env
# Install Party QEmu oder Stick