aboutsummaryrefslogtreecommitdiff
path: root/2024-installfest/pres.typ
blob: 7572ff40d71010664ad5874c97bce497243b3509 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
#import "@preview/polylux:0.3.1": *
#import themes.metropolis: *
#show: metropolis-theme
#set text(size: 25pt)

#title-slide(
  title: [Instalace NixOS na Turris routery],
  subtitle: [Installfest 2024],
  author: [Karel Kočí],
  date: [16.03.2024],
)

#new-section-slide([Instalace na Turris Mox])

#slide(title: [Příprava SD karty])[
```console
~$ sudo parted /dev/mmcblk1
(parted) mktable gpt
(parted) mkpart NixTurris 0% 100%
(parted) set 1 boot on
(parted) quit
~$ sudo mkfs.btrfs /dev/mmcblk1p1
~$ mount /dev/mmcblk1p1 /mnt
~$ tar -xf nixos-system-aarch64-linux.tar.xz -C /mnt
~$ umount /mnt
```
]

#slide(title: [U-Boot])[
Nutné aktualizovat U-Boot: ```console
~# opkg update
~# opkg install turris-nor-update
~# nor-update
```
]

#slide(
  title: [První boot],
)[
```console
U-Boot 2022.07 (Aug 15 2022 - 12:25:08 +0000)
...
Hit any key to stop autoboot:  0
=> setenv ramdisk_addr_r 0x9000000
=> saveenv
Saving Environment to SPIFlash... Erasing SPI flash...Writing to SPI flash...done
OK
=> boot
```
]

#new-section-slide([Instalace na Turris Omnia])

#slide(title: [Příprava USB flash disku])[
```console
~$ sudo parted /dev/sdx
(parted) mktable gpt
(parted) mkpart NixTurris 0% 100%
(parted) set 1 boot on
(parted) quit
  ~$ sudo mkfs.btrfs /dev/sdx1
~$ mount /dev/sdx /mnt
~$ tar -xf nixos-system-armv7l-linux.tar.xz -C /mnt
~$ umount /mnt
```
]

#slide(title: [U-Boot])[
Nutné aktualizovat U-Boot: ```console
~# opkg update
~# opkg install turris-nor-update
~# nor-update
```
]

#slide(
  title: [První boot],
)[
```console
U-Boot 2022.10-rc4-OpenWrt-r16653+119-44ce70f0e2
...
Hit any key to stop autoboot:  0
=> setenv boot_targets usb0 mmc0 nvme0 scsi0 pxe dhcp
=> saveenv
Saving Environment to SPIFlash... Erasing SPI flash...Writing to SPI flash...done
OK
=> boot
```
]

#new-section-slide([Aktualizace])

#focus-slide[
#text(size: 35pt)[
```bash
nix flake init -t gitlab:cynerd/nixturris
nix build .#tarball
```
]
]

#slide(title: [Nasazení])[
```bash
  nix build .#toplevel
  nix copy --to root@192.168.1.142 $(readlink -f result)
  readlink -f result
  ```

`ssh root@192.168.1.142`:
#text(size: 24pt)[
```bash
  nix-env -p /nix/var/nix/profiles/system --set /nix/store/...
  /nix/var/nix/profiles/system/bin/switch-to-configuration switch
  ```
]
]

#new-section-slide([Intermezzo])

#slide(title: [Výhody])[
  - Je to server nebo router? Aktualizuje se to stejně..
  - Nastavení systému nebo monitoring všude stejné
  - Plošné nasazení konfigurace a její aktualizace
  - Spousta připraveného softwaru a jednotné balení pro Nix
  - Aktualizace je skoro to samé jako čistá instalace
  - ...
]

#slide(title: [Není to růžové])[
  - Ne vše co je v Nixpkgs jde cross-zkompilovat
  - Armv7l není oficiálně podporovaná platforma
  - Turris Omnia aktuálně jen Linux kernel 6.1
]

#slide(title: [NixDeploy])[
Nasazení na běžící systémy přes SSH z vývojářského PC s podporou
cross-kompilace. ```bash
  nix flake init -t gitlab:cynerd/nixdeploy
  nix run . -- --help
  nix run . laptop
  ```
]

#new-section-slide([SystemD-NetworkD])

#slide[
```nix
  networking = {
    useNetworkd = true;
    useDHCP = false;
  };
  systemd.network = {};
  ```
]
#slide(title: [Switch])[
#text(size: 17pt)[
```nix
  systemd.network = {
    netdevs = {
      "brlan".netdevConfig = {Kind = "bridge"; Name = "brlan";};
    };
    networks = {
      "brlan" = {
        matchConfig.Name = "brlan";
        networkConfig = {DHCP = "yes"; IPv6AcceptRA = "yes";};
      };
      "lan-brlan" = {
        matchConfig.Name = "lan* end0"; networkConfig.Bridge = "brlan";
      };
    };
  };
  ```
]
]

#slide(title: [Router])[
#text(size: 18pt)[
```nix
  systemd.network = {
    netdevs."brlan".netdevConfig = {
      Kind = "bridge";
      Name = "brlan";
    };
    networks."lan-brlan" = {
      matchConfig.Name = "lan*";
      networkConfig.Bridge = "brlan";
    };
    wait-online.anyInterface = true;
  };
  ```
]
]
#slide(title: [Router (end2 jako wan)])[
#text(size: 17pt)[
```nix
systemd.network.networks = {
  "end2" = {
    matchConfig.Name = "end2";
    networkConfig = {
      DHCP = "yes";
      IPv6AcceptRA = "yes"; DHCPPrefixDelegation = "yes";
    };
    dhcpV6Config.PrefixDelegationHint = "::/56";
    dhcpPrefixDelegationConfig = {
      UplinkInterface = ":self";
      Announce = "no";
    };
    linkConfig.RequiredForOnline = "routable";
  };
```
]
]
#slide(title: [Router (brlan network)])[
#text(size: 18pt)[
```nix
systemd.network.networks"brlan" = {
  matchConfig.Name = "brlan";
  networkConfig = {
    Address = "192.168.4.1/24";
    IPForward = "yes";
    DHCPServer = "yes";
    DHCPPrefixDelegation = "yes";
    IPv6SendRA = "yes";
    IPv6AcceptRA = "no";
  };
};
```
]
]
#slide(
  title: [Router (DHCP)],
)[
#text(
  size: 18pt,
)[
```nix
systemd.network.networks"brlan" = {
  dhcpServerConfig = {
    UplinkInterface = "end2";
    PoolOffset = 100; PoolSize = 100;
    EmitDNS = "yes"; DNS = "192.168.4.1";
  };
  dhcpServerStaticLeases = [
    { dhcpServerStaticLeaseConfig =
      { MACAddress = "a8:a1:59:10:32:c4"; Address = "192.168.4.20"; };
    }
  ];
  dhcpPrefixDelegationConfig = {UplinkInterface = "end2"; Announce = "yes"; };
};
```
]
]
#slide(
  title: [Router (DNS, Firewall)],
)[
#text(
  size: 17pt,
)[
```nix
  services.resolved = {
    enable = true;
    fallbackDns = ["1.1.1.1" "8.8.8.8"];
    extraConfig = ''
      DNSStubListenerExtra=192.168.4.1
    '';
  };
  networking = {
    firewall = {
      interfaces."brlan" = {allowedUDPPorts = [53 67 68];};
      filterForward = true;
    };
    nat = { enable = true; externalInterface = "end2"; internalInterfaces = ["brlan"]; };
  };
  ```
]
]

#new-section-slide([Hostapd (Wi-Fi access point)])

#slide(
  title: [AR9287],
)[
#text(
  size: 16pt,
)[
```nix
services.hostapd = { enable = true;
  radios = {
    "wlp3s0" = {
      channel = 7; countryCode = "CZ";
      wifi4 = { enable = true;
        inherit (lib.hostapd.qualcomAtherosAR9287.wifi4) capabilities;
      };
      networks."wlp3s0" = {
        ssid = "NixOSInstallFest";
        authentication = {
          mode = "wpa2-sha256"; wpaPassword = "InstallFest2024";
}; }; }; }; };
systemd.network.networks = {
  "lan-wlp3s0" = { matchConfig.Name = "wlp3s0"; networkConfig.Bridge = "brlan"; };
};
```
]
]

#slide(
  title: [QCA988x (Wi-Fi 5)],
)[
#text(
  size: 16pt,
)[
```nix
nixpkgs.config.allowUnfree = true;
hardware.enableAllFirmware = true;
services.hostapd.radios."wlp2s0" = {
  channel = 36; band = "5g"; countryCode = "CZ";
  wifi4 = { enable = true; inherit (lib.hostapd.qualcomAtherosQCA988x.wifi4) capabilities; };
  wifi5 = { enable = true; inherit (lib.hostapd.qualcomAtherosQCA988x.wifi5) capabilities; };
  networks."wlp2s0" = {
    ssid = "NixOSInstallFest5";
    authentication = { mode = "wpa2-sha256"; wpaPassword = "InstallFest2024"; };
  };
};
systemd.network.networks = {
  "lan-wlp2s0" = { matchConfig.Name = "wlp2s0"; networkConfig.Bridge = "brlan"; };
};
```
]
]

#new-section-slide([Síť pro hosty])

#slide(
  title: [VLANy (brlan)],
)[
#text(
  size: 16pt,
)[
```nix
systemd.network.netdevs = {
  "brlan" = { netdevConfig = { Kind = "bridge"; Name = "brlan"; };
    extraConfig = ''
      [Bridge]
      DefaultPVID=none
      VLANFiltering=yes
    ''; };
  "home" = { netdevConfig = { Kind = "vlan"; Name = "home"; }; vlanConfig.Id = 1; };
  "guest" = { netdevConfig = { Kind = "vlan"; Name = "guest"; }; vlanConfig.Id = 2; };
};
systemd.network.networks."brlan" = {
  matchConfig.Name = "brlan";
  networkConfig.VLAN = ["home" "guest"];
  bridgeVLANs = [ {bridgeVLANConfig.VLAN = 1;} {bridgeVLANConfig.VLAN = 2;} ];
};
```
]
]

#slide(title: [VLANy (brlan)])[
#text(size: 17pt)[
```nix
systemd.network.networks."lan-brlan" = {
  matchConfig.Name = "lan*";
  networkConfig.Bridge = "brlan";
  bridgeVLANs = [
    {
      bridgeVLANConfig = {
        EgressUntagged = 1;
        PVID = 1;
      };
    }
    {bridgeVLANConfig.VLAN = 2;}
  ];
};
```
]
]

#slide(title: [VLANy (home a guest)])[
#text(size: 16pt)[
```nix
systemd.network.networks = {
  "home" = {
    matchConfig.Name = "home";
    networkConfig = {
      Address = "192.168.4.1/24";
      IPForward = "yes";
      DHCPServer = "yes";
...
  "guest" = {
    matchConfig.Name = "guest";
    networkConfig = {
      Address = "192.168.5.1/24";
      IPForward = "yes";
...
};
```
]
]

#slide(
  title: [VLANy (Wi-Fi)],
)[
#text(
  size: 16pt,
)[
```nix
services.hostapd.raios."wlp3s0".networks = {
  "wlp3s0" = {
    ssid = "Home"; bssid = "12:f0:21:23:2b:00";
    authentication = { mode = "wpa2-sha256"; wpaPassword = "InstallFest2024"; }; };
  "wlp3s0.guest" = {
    ssid = "Guest"; bssid = "12:f0:21:23:2b:01"; authentication.mode = "none"; };
};
systemd.network.networks = {
  "lan-wlp3s0" = {
    matchConfig.Name = "wlp3s0"; networkConfig.Bridge = "brlan";
    bridgeVLANs = [ { bridgeVLANConfig = { EgressUntagged = 1; PVID = 1; }; } ]; };
  "lan-wlp3s0.guest" = {
    matchConfig.Name = "wlp3s0.guest"; networkConfig.Bridge = "brlan";
    bridgeVLANs = [ { bridgeVLANConfig = { EgressUntagged = 2; PVID = 2; }; } ]; };
};
```
]
]

#new-section-slide([Další tipy])

#slide(
  title: [PPPoE],
)[
#text(
  size: 16pt,
)[
```nix
services.pppd = { enable = true; peers."wan".config = ''
  plugin pppoe.so end2
  ifname pppoe-wan
  lcp-echo-interval 1
  lcp-echo-failure 5
  lcp-echo-adaptive
  +ipv6
  defaultroute
  defaultroute6
  usepeerdns
  maxfail 1
  user O2
  password 02
''; };
systemd.services."pppd-wan".after = ["sys-subsystem-net-devices-end2.device"];
```
]
]
#slide(title: [PPPoE (network)])[
#text(size: 19pt)[
```nix
systemd.network.networks."pppoe-wan" = {
  matchConfig.Name = "pppoe-wan";
  networkConfig = {
    BindCarrier = "end2";
    DHCP = "ipv6";
    IPv6AcceptRA = "no";
    DHCPPrefixDelegation = "yes";
  };
  ...
};
networking.firewall.extraForwardRules = ''
  tcp flags syn tcp option maxseg size set rt mtu comment "MSS clamping"
'';
```
]
]
#slide(
  title: [PPPoE na VLANě],
)[
#text(
  size: 19pt,
)[
```nix
systemd.network = {
   netdevs = {
     "end2.848" = {
       netdevConfig = { Kind = "vlan"; Name = "end2.848"; };
       vlanConfig.Id = 848;
   }; };
   networks = {
     "end2" = { matchConfig.Name = "end2"; networkConfig.VLAN = ["end2.848"]; };
     "end2.848" = {
       matchConfig.Name = "end2.848";
       networkConfig.BindCarrier = "end2";
   }; };
```
]
]

#slide(title: [Routable VPN - home])[
#text(size: 19pt)[
```nix
networking.firewall = {
  nftables.enable = true;
  extraForwardRules = ''
    iifname {"home", "vpn"} oifname {"home", "vpn"} accept
  '';
};
```
]
]
#slide(title: [Wi-Fi (problémy s připojením klientů])[
```nix
services.hostapd.radios."wlp3s0".networks."wlp3s0".settings = {
  wpa_key_mgmt = mkForce "WPA-PSK"; # force use without sha256
  ieee80211w = 0;
};
```
]
#slide(title: [Firewall: Reject spam])[
```nix
networking.firewall.logRefusedConnections = false;
```
]
#slide(title: [Omezení velikosti logů])[
```nix
services.journald.extraConfig = ''
  SystemMaxUse=512M
'';
```
]

#slide(title: [Co dál?])[
  - Dokumentace nastavení routeru na NixOS Wiki
  - systemd-resolved a DNSSEC do sítě
  - Podpora Turris Sentinel
  - Šifrovaný root disk (atsha a mox-otp)
  - Snazší nastavení pro routery
]

#focus-slide[
  Děkuji za pozornost

  Karel Kočí

  https://gitlab.com/cynerd/nixturris

  #text(size: 25pt)[https://git.cynerd.cz https://gitlab.com/cynerd]
]