Skip to content

Commit fea1370

Browse files
2025 07 01
1 parent e3429e3 commit fea1370

30 files changed

+2106
-938
lines changed

chromebox/chromebox3/configuration.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@
8585
description = "das";
8686
password = "admin123";
8787
extraGroups = [ "wheel" "libvirtd" "docker" "kubernetes" ];
88-
packages = with pkgs; [
89-
];
88+
# packages = with pkgs; [
89+
# ];
9090
# https://nixos.wiki/wiki/SSH_public_key_authentication
9191
openssh.authorizedKeys.keys = [
9292
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGMCFUMSCFJX95eLfm7P9r72NBp9I1FiXwNwJ+x/HGPV das@t"

desktop/l/configuration.nix

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,12 @@
139139

140140
services.pipewire = {
141141
enable = true;
142+
audio.enable = true;
142143
alsa.enable = true;
143144
alsa.support32Bit = true;
144145
pulse.enable = true;
145-
# Uncomment the following line if you want to use JACK applications
146-
# jack.enable = true;
146+
jack.enable = true;
147+
wireplumber.enable = true;
147148
};
148149

149150
services.openssh.enable = true;
@@ -250,6 +251,11 @@
250251
config.common.default = "gtk";
251252
};
252253

254+
services.dbus.packages = with pkgs; [
255+
xdg-desktop-portal
256+
xdg-desktop-portal-gtk
257+
];
258+
253259
# # https://wiki.hyprland.org/Nix/Hyprland-on-NixOS/
254260
# programs.hyprland = {
255261
# enable = true;

desktop/l/home.nix

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -475,8 +475,7 @@
475475
# Media
476476
vlc
477477
# ffmpeg moved to system package
478-
#ffmpeg_7-full
479-
#ffmpeg-full
478+
ffmpeg_7-full
480479

481480
# Go Development
482481
# https://nixos.wiki/wiki/Go
@@ -680,6 +679,11 @@
680679

681680
#gpu monitoring
682681
lact
682+
683+
# virtual camera control
684+
# v4l2-ctl --list-devices
685+
v4l-utils
686+
libsForQt5.kdenlive
683687
];
684688

685689
# vscode
@@ -753,7 +757,6 @@
753757
};
754758

755759
# https://nixos.wiki/wiki/OBS_Studio
756-
# TODO add kernel module for virtual camera
757760
programs.obs-studio = {
758761
enable = true;
759762
plugins = with pkgs.obs-studio-plugins; [

desktop/l/sysctl.nix

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
"net.ipv4.tcp_wmem" = "4096 1000000 16000000";
1818
#net.ipv4.tcp_rmem = 4096 131072 6291456
1919
#net.ipv4.tcp_wmem = 4096 16384 4194304
20+
"net.ipv6.tcp_rmem" = "4096 1000000 16000000";
21+
"net.ipv6.tcp_wmem" = "4096 1000000 16000000";
2022
# https://github.com/torvalds/linux/blob/master/Documentation/networking/ip-sysctl.rst?plain=1#L1042
2123
# https://lwn.net/Articles/560082/
2224
"net.ipv4.tcp_notsent_lowat" = "131072";
@@ -38,7 +40,7 @@
3840
#net.core.rmem_max = 212992
3941
#net.core.wmem_default = 212992
4042
#net.core.wmem_max = 212992
41-
"net.ipv4.ip_local_port_range" = "1025 65535";
43+
"net.ipv4.ip_local_port_range" = "1026 65535";
4244
#net.ipv4.ip_local_port_range ="32768 60999"
4345
#
4446
#net.ipv4.inet_peer_maxttl = 600
@@ -51,5 +53,14 @@
5153
#net.ipv4.tcp_reflect_tos = 0
5254
"net.ipv4.tcp_rto_min_us" = 50000; #50ms
5355
#net.ipv4.tcp_rto_min_us = 200000 #200ms
56+
57+
# TCP optimizations for high performance
58+
"net.ipv4.tcp_slow_start_after_idle" = 0; # Disable slow start after idle
59+
"net.ipv4.tcp_fastopen" = 3; # Enable TCP Fast Open
60+
61+
"net.ipv4.tcp_window_scaling" = 1;
62+
"net.ipv4.tcp_sack" = 1;
63+
"net.ipv4.tcp_fack" = 1;
64+
"net.ipv4.tcp_fin_timeout" = 30;
5465
};
5566
}

desktop/l2/CPU_and_IRQ_optimization.md

Lines changed: 200 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ On this architecture, each physical core is split into two logical processors (S
2626
- **8 MSI-X vectors** distributed across cores 16-23
2727
- **Current distribution**: Interrupts are clustered on cores 14, 15, 16, 17, 18, 20, 22, 23
2828
- **Issue**: Competing with storage I/O and userland processes
29+
- **Note**: LRO and GRO features are disabled due to compatibility issues with the Atlantic driver
2930

3031
#### WiFi Interfaces (4x Intel iwlwifi)
3132
- **wlp35s0**: 16 MSI-X vectors, mostly on CPU 21
@@ -56,6 +57,11 @@ On this architecture, each physical core is split into two logical processors (S
5657
- Heavy network processing concentrated on cores 14, 15, 21, 23
5758
- No dedicated cores for network processing
5859

60+
### 4. **Network Hardware Offload Limitations**
61+
- **Atlantic NIC LRO/GRO Issues**: The Atlantic driver has compatibility issues with Large Receive Offload (LRO) and Generic Receive Offload (GRO) features
62+
- **Impact**: Reduced CPU efficiency for packet processing, requiring software-based packet handling
63+
- **Mitigation**: Optimized interrupt coalescing and ring buffer settings to compensate for disabled hardware offloads
64+
5965
## Proposed Optimization Strategy
6066

6167
### Phase 1: Core Isolation and Dedication
@@ -79,7 +85,7 @@ On this architecture, each physical core is split into two logical processors (S
7985
#### Userland Processing Cores (8-23)
8086
**Remaining cores for system services and userland:**
8187
- **Cores 8,20,9,21,10,22,11,23**: Userland processes, system services
82-
- **Services**: hostapd, DHCP (Kea), DNS (PowerDNS), IPv6 RA (radvd)
88+
- **Services**: hostapd, DHCP (Kea), DNS (PowerDNS), IPv6 RA (radvd), CrowdSec
8389
- **Slice**: system.slice and network-services.slice
8490
- **Benefits**:
8591
- Isolated from network interrupt processing
@@ -152,7 +158,7 @@ done
152158
```nix
153159
systemd.slices = {
154160
network-services = {
155-
description = "Network services (DHCP, DNS, RA, hostapd)";
161+
description = "Network services (DHCP, DNS, RA, hostapd, CrowdSec)";
156162
sliceConfig = {
157163
CPUAffinity = "8,20,9,21,10,22,11,23"; # Userland cores only
158164
Nice = -5;
@@ -205,6 +211,18 @@ systemd.slices = {
205211
Slice = "network-services.slice";
206212
};
207213
};
214+
crowdsec = {
215+
description = "CrowdSec threat detection engine slice";
216+
sliceConfig = {
217+
Slice = "network-services.slice";
218+
};
219+
};
220+
crowdsec-firewall-bouncer = {
221+
description = "CrowdSec firewall bouncer slice";
222+
sliceConfig = {
223+
Slice = "network-services.slice";
224+
};
225+
};
208226
};
209227
```
210228

@@ -247,7 +265,157 @@ boot.kernel.sysctl = {
247265
};
248266
```
249267

250-
### Phase 5: NUMA Optimization
268+
### Phase 5: Network Hardware Optimization
269+
270+
#### Atlantic NIC Optimizations
271+
Due to compatibility issues with the Atlantic driver, certain hardware offload features are disabled:
272+
273+
```bash
274+
# Disabled features (causing issues with Atlantic driver)
275+
# - LRO (Large Receive Offload): Causes packet corruption/drops
276+
# - GRO (Generic Receive Offload): Causes stability issues
277+
278+
# Enabled optimizations
279+
ethtool -G enp1s0 rx 8184 tx 8184 # Maximum ring buffers
280+
ethtool -K enp1s0 tx-checksum-ipv4 on # IPv4 checksum offload
281+
ethtool -K enp1s0 tx-tcp-ecn-segmentation on # TCP ECN segmentation
282+
283+
# Interrupt coalescing optimization
284+
ethtool -C enp1s0 rx-usecs 512 rx-frames 32
285+
ethtool -C enp1s0 tx-usecs 1024 tx-frames 32
286+
```
287+
288+
**Impact and Mitigation:**
289+
- **Performance Impact**: Disabled LRO/GRO reduces CPU efficiency for packet processing
290+
- **Mitigation Strategy**:
291+
- Optimized interrupt coalescing to reduce CPU overhead
292+
- Maximum ring buffer sizes to handle burst traffic
293+
- Dedicated network cores to compensate for software processing
294+
- Enhanced interrupt distribution across isolated cores
295+
296+
### Phase 6: CrowdSec Integration
297+
298+
#### Dynamic Threat Detection
299+
CrowdSec provides real-time threat detection and automatic blocking using nftables:
300+
301+
```nix
302+
# CrowdSec engine configuration
303+
services.crowdsec = {
304+
enable = true;
305+
settings = {
306+
api = {
307+
server = {
308+
listen_uri = "[::1]:8080"; # IPv6 localhost
309+
trusted_ips = [ "127.0.0.1" "::1" ]; # No API key needed
310+
};
311+
};
312+
db_config = {
313+
type = "sqlite";
314+
db_path = "/var/lib/crowdsec/data/crowdsec.db";
315+
};
316+
};
317+
};
318+
319+
# Firewall bouncer for nftables integration
320+
services.crowdsec-firewall-bouncer = {
321+
enable = true;
322+
settings = {
323+
api_url = "http://[::1]:8080/";
324+
nftables = {
325+
enabled = true;
326+
table = "filter";
327+
chain = "input";
328+
set = "blacklist";
329+
ipv4 = true;
330+
ipv6 = true;
331+
};
332+
};
333+
};
334+
```
335+
336+
#### Resource Management for CrowdSec
337+
Both CrowdSec services are assigned to the network-services slice with memory limits:
338+
339+
```nix
340+
systemd.services = {
341+
# Network services (network-services slice, via per-daemon slices)
342+
hostapd = {
343+
serviceConfig = {
344+
Slice = "hostapd.slice";
345+
Nice = -10;
346+
IOSchedulingClass = 1; # Real-time I/O
347+
IOSchedulingPriority = 4;
348+
LimitNOFILE = 65536;
349+
Restart = "always";
350+
RestartSec = "5s";
351+
};
352+
};
353+
354+
kea-dhcp4-server = {
355+
serviceConfig = {
356+
Slice = "kea.slice";
357+
Nice = -5;
358+
LimitNOFILE = 65536;
359+
Restart = "always";
360+
RestartSec = "10s";
361+
};
362+
};
363+
364+
pdns-recursor = {
365+
serviceConfig = {
366+
Slice = "pdns.slice";
367+
Nice = -5;
368+
LimitNOFILE = 65536;
369+
Restart = "always";
370+
RestartSec = "10s";
371+
};
372+
};
373+
374+
radvd = {
375+
serviceConfig = {
376+
Slice = "radvd.slice";
377+
Nice = -5;
378+
Restart = "always";
379+
RestartSec = "10s";
380+
};
381+
};
382+
383+
# CrowdSec threat detection services
384+
crowdsec = {
385+
serviceConfig = {
386+
Slice = "crowdsec.slice";
387+
Nice = -5;
388+
LimitNOFILE = 65536;
389+
MemoryHigh = "512M";
390+
MemoryMax = "1G";
391+
Environment = [ "GOMEMLIMIT=460M" ];
392+
Restart = "always";
393+
RestartSec = "5s";
394+
};
395+
};
396+
397+
crowdsec-firewall-bouncer = {
398+
serviceConfig = {
399+
Slice = "crowdsec-firewall-bouncer.slice";
400+
Nice = -5;
401+
LimitNOFILE = 65536;
402+
MemoryHigh = "256M";
403+
MemoryMax = "512M";
404+
Environment = [ "GOMEMLIMIT=230M" ];
405+
Restart = "always";
406+
RestartSec = "5s";
407+
};
408+
};
409+
};
410+
```
411+
412+
**Benefits:**
413+
- **Real-time Protection**: Automatic blocking of malicious IPs
414+
- **Community Intelligence**: Leverages global threat intelligence
415+
- **Resource Efficiency**: Memory limits prevent resource exhaustion
416+
- **Integration**: Seamless nftables integration with dynamic blacklist sets
417+
418+
### Phase 7: NUMA Optimization
251419

252420
#### Memory Allocation
253421
```bash
@@ -330,6 +498,33 @@ systemd.services = {
330498
RestartSec = "10s";
331499
};
332500
};
501+
502+
# CrowdSec threat detection services
503+
crowdsec = {
504+
serviceConfig = {
505+
Slice = "crowdsec.slice";
506+
Nice = -5;
507+
LimitNOFILE = 65536;
508+
MemoryHigh = "512M";
509+
MemoryMax = "1G";
510+
Environment = [ "GOMEMLIMIT=460M" ];
511+
Restart = "always";
512+
RestartSec = "5s";
513+
};
514+
};
515+
516+
crowdsec-firewall-bouncer = {
517+
serviceConfig = {
518+
Slice = "crowdsec-firewall-bouncer.slice";
519+
Nice = -5;
520+
LimitNOFILE = 65536;
521+
MemoryHigh = "256M";
522+
MemoryMax = "512M";
523+
Environment = [ "GOMEMLIMIT=230M" ];
524+
Restart = "always";
525+
RestartSec = "5s";
526+
};
527+
};
333528
};
334529
```
335530

@@ -463,6 +658,8 @@ Core Allocation:
463658
| Kea | DHCP server | kea.slice (child of network-services.slice) | 8,20,9,21,10,22,11,23 | -5 |
464659
| PowerDNS | DNS resolver | pdns.slice (child of network-services.slice)| 8,20,9,21,10,22,11,23 | -5 |
465660
| radvd | IPv6 RA | radvd.slice (child of network-services.slice)| 8,20,9,21,10,22,11,23 | -5 |
661+
| CrowdSec | Threat detection | crowdsec.slice (child of network-services.slice) | 8,20,9,21,10,22,11,23 | -5 |
662+
| CrowdSec FW | Firewall bouncer | crowdsec-firewall-bouncer.slice (child of network-services.slice) | 8,20,9,21,10,22,11,23 | -5 |
466663

467664
**Note:** All services inherit CPU affinity and resource limits from their assigned slice. Only the two main parent slices (network-services and system) need explicit CPU affinity settings. **Network cores (0,12,1,13,2,14,3,15,4,5,6,7) are isolated by `isolcpus` and can only be used for IRQ affinity, not for systemd slice CPU affinity.** Kernel-level components like nftables and CAKE (QoS) are not managed by systemd slices; their performance is influenced by CPU isolation, IRQ affinity, and kernel boot parameters, not by systemd.
468665

0 commit comments

Comments
 (0)