Skip to content

Commit bafa796

Browse files
Merge pull request #15 from randomizedcoder/2025_04_17
2025 04 17
2 parents 31b947a + ea7c94f commit bafa796

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+3434
-406
lines changed

containers/nginx/flake.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
description = "OpenTechLab Docker Example";
33

44
inputs = {
5-
nixpkgs.url = github:NixOS/nixpkgs/nixos-24.05;
5+
nixpkgs.url = github:NixOS/nixpkgs/nixos-24.11;
66
};
77

88
outputs = { self, nixpkgs }: {

containers/nginx/old.flake.nix.old

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
{
2+
description = "OpenTechLab Docker Example";
3+
4+
inputs = {
5+
nixpkgs.url = github:NixOS/nixpkgs/nixos-24.05;
6+
};
7+
8+
outputs = { self, nixpkgs }: {
9+
packages."x86_64-linux" =
10+
let
11+
pkgs = import nixpkgs { system = "x86_64-linux"; };
12+
in
13+
rec {
14+
dockerImage =
15+
pkgs.dockerTools.buildLayeredImage (let
16+
nginxPort = "80";
17+
nginxConf = pkgs.writeText "nginx.conf" ''
18+
user nginx nginx;
19+
daemon off;
20+
events {}
21+
http {
22+
server {
23+
listen ${nginxPort};
24+
location / {
25+
root ${./html};
26+
}
27+
}
28+
}
29+
'';
30+
31+
in rec {
32+
name = "otl-nix-demo";
33+
tag = "latest";
34+
35+
contents = with pkgs; [
36+
# Set up users and groups
37+
(writeTextDir "etc/shadow" ''
38+
root:!x:::::::
39+
nginx:!:::::::
40+
'')
41+
(writeTextDir "etc/passwd" ''
42+
root:x:0:0::/root:${runtimeShell}
43+
nginx:x:999:999::/home/nginx:
44+
'')
45+
(writeTextDir "etc/group" ''
46+
root:x:0:
47+
nginx:x:999:
48+
'')
49+
(writeTextDir "etc/gshadow" ''
50+
root:x::
51+
nginx:x::
52+
'')
53+
54+
# Workaround: create directories required by nginx
55+
(writeTextDir "var/cache/nginx/.placeholder" "")
56+
(writeTextDir "var/log/nginx/.placeholder" "")
57+
];
58+
59+
config = {
60+
Cmd = [ "${pkgs.nginx}/bin/nginx" "-c" nginxConf ];
61+
ExposedPorts = {
62+
"${nginxPort}/tcp" = { };
63+
};
64+
};
65+
};
66+
};
67+
};
68+
}

go/konnect/flake.nix

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
description = "A very basic flake";
3+
4+
inputs = {
5+
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
6+
};
7+
8+
outputs = { self, nixpkgs }: {
9+
10+
packages.x86_64-linux.hello = nixpkgs.legacyPackages.x86_64-linux.hello;
11+
12+
packages.x86_64-linux.default = self.packages.x86_64-linux.hello;
13+
14+
};
15+
}

go/konnect/readme.md

Whitespace-only changes.

hp/hp1/Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,15 @@ rebuild:
2020
#sudo cp ./*.nix /etc/nixos/
2121
#sudo nix-channel --update
2222
#sudo nixos-rebuild switch
23-
sudo nix flake update;
2423
#sudo nix-channel --update;
2524
sudo nixos-rebuild switch --flake .
25+
sudo systemctl restart ffmpeg-stream
26+
27+
rebuild_trace:
28+
sudo nixos-rebuild switch --show-trace --flake .
29+
30+
update:
31+
sudo nix flake update;
2632

2733
sync:
2834
rsync -av /home/das/nixos/hp/hp1/ hp1:/home/das/nixos/hp/hp1/

hp/hp1/configuration.nix

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#./k3s_node.nix
3434
./systemd.services.ethtool-enp3s0f0.nix
3535
./systemd.services.ethtool-enp3s0f1.nix
36+
./ffmpeg_systemd_service.nix
3637
];
3738

3839
# https://nixos.wiki/wiki/Kubernetes#reset_to_a_clean_state
@@ -41,17 +42,22 @@
4142
# rm -rf /var/lib/kubernetes/ /var/lib/etcd/ /var/lib/cfssl/ /var/lib/kubelet/ /etc/kube-flannel/ /etc/kubernetes/
4243

4344
# Bootloader.
44-
boot.loader.systemd-boot = {
45-
enable = true;
46-
#consoleMode = "max"; # Sets the console mode to the highest resolution supported by the firmware.
47-
memtest86.enable = true;
48-
};
45+
boot = {
46+
loader.systemd-boot = {
47+
enable = true;
48+
#consoleMode = "max"; # Sets the console mode to the highest resolution supported by the firmware.
49+
memtest86.enable = true;
50+
};
4951

50-
boot.loader.efi.canTouchEfiVariables = true;
52+
loader.efi.canTouchEfiVariables = true;
5153

52-
# https://nixos.wiki/wiki/Linux_kernel
53-
boot.kernelPackages = pkgs.linuxPackages_latest;
54-
#boot.kernelPackages = pkgs.linuxPackages_rpi4
54+
# https://nixos.wiki/wiki/AMD_GPU
55+
initrd.kernelModules = [ "amdgpu" ];
56+
57+
# https://nixos.wiki/wiki/Linux_kernel
58+
kernelPackages = pkgs.linuxPackages_latest;
59+
#boot.kernelPackages = pkgs.linuxPackages_rpi4
60+
};
5561

5662
nix = {
5763
gc = {
@@ -67,6 +73,20 @@
6773
};
6874
};
6975

76+
# find /run/opengl-driver -name "libamfrt64.so.1"
77+
hardware.graphics = {
78+
enable = true;
79+
extraPackages = with pkgs; [
80+
amdvlk # AMD Vulkan driver, includes AMF runtime
81+
#rocm-opencl-runtime # Optional: ROCm OpenCL support
82+
#rocm-smi # AMD System Management Interface (for monitoring GPU)
83+
# https://nixos.wiki/wiki/AMD_GPU#OpenCL
84+
rocmPackages.clr.icd
85+
];
86+
};
87+
88+
services.xserver.videoDrivers = [ "amdgpu" ];
89+
7090
# https://nixos.wiki/wiki/Networking
7191
# https://nlewo.github.io/nixos-manual-sphinx/configuration/ipv4-config.xml.html
7292
networking.hostName = "hp1";
@@ -95,7 +115,7 @@
95115
users.users.das = {
96116
isNormalUser = true;
97117
description = "das";
98-
extraGroups = [ "wheel" "libvirtd" "docker" "kubernetes" ];
118+
extraGroups = [ "wheel" "libvirtd" "docker" "kubernetes" "video" ];
99119
packages = with pkgs; [
100120
];
101121
# https://nixos.wiki/wiki/SSH_public_key_authentication
@@ -122,6 +142,9 @@
122142

123143
services.fstrim.enable = true;
124144

145+
# AMD GPU power management
146+
#services.udev.packages = with pkgs; [ rocm-smi ];
147+
125148
# This value determines the NixOS release from which the default
126149
# settings for stateful data, like file locations and database versions
127150
# on your system were taken. It‘s perfectly fine and recommended to leave

hp/hp1/ffmpeg_systemd_service.nix

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
#
2+
# nixos/hp/hp1/ffmpeg_systemd_service.nix
3+
#
4+
# systemctl --user restart ffmpeg-stream
5+
# systemctl --user status ffmpeg-stream
6+
#
7+
# [das@hp1:~/nixos/hp/hp1]$ systemctl --user restart ffmpeg-stream
8+
9+
# [das@hp1:~/nixos/hp/hp1]$ systemctl --user status ffmpeg-stream
10+
# ● ffmpeg-stream.service
11+
# Loaded: loaded (/home/das/.config/systemd/user/ffmpeg-stream.service; enabled; preset: ignored)
12+
# Active: active (running) since Sun 2025-02-02 15:16:54 PST; 3min 41s ago
13+
# Invocation: ac9c5b7820cd40fe85f95d610a184c46
14+
# Main PID: 394915 (ffmpeg)
15+
# Tasks: 37 (limit: 37129)
16+
# Memory: 230.4M (peak: 230.9M)
17+
# CPU: 2min 13.669s
18+
# CGroup: /user.slice/user-1000.slice/[email protected]/app.slice/ffmpeg-stream.service
19+
# └─394915 /nix/store/hk1a30i7a4nhc16sc407z0fi1yxgfgjp-ffmpeg-7.1-bin/bin/ffmpeg -f lavfi -re -i testsrc2=rate=30:size=1920x1080 -codec:v libx264 -b:v 10240k -maxrate:v 10000k -bu>
20+
21+
# [das@hp1:~/nixos/hp/hp1]$ journalctl --user -u ffmpeg-stream -f
22+
# Feb 02 15:16:54 hp1 ffmpeg[394915]: [libx264 @ 0x352394c0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
23+
# Feb 02 15:16:54 hp1 ffmpeg[394915]: [libx264 @ 0x352394c0] profile Constrained Baseline, level 4.0, 4:2:0, 8-bit
24+
# Feb 02 15:16:54 hp1 ffmpeg[394915]: Output #0, mpegts, to 'udp://239.0.0.1:6000?ttl=4&pkt_size=1326&localddr=172.16.40.142':
25+
# Feb 02 15:16:54 hp1 ffmpeg[394915]: Metadata:
26+
# Feb 02 15:16:54 hp1 ffmpeg[394915]: encoder : Lavf61.7.100
27+
# Feb 02 15:16:54 hp1 ffmpeg[394915]: Stream #0:0: Video: h264, yuv420p(tv, progressive), 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 10240 kb/s, 25 fps, 90k tbn
28+
# Feb 02 15:16:54 hp1 ffmpeg[394915]: Metadata:
29+
# Feb 02 15:16:54 hp1 ffmpeg[394915]: encoder : Lavc61.19.100 libx264
30+
# Feb 02 15:16:54 hp1 ffmpeg[394915]: Side data:
31+
# Feb 02 15:16:54 hp1 ffmpeg[394915]: cpb: bitrate max/min/avg: 10000000/0/10240000 buffer size: 10240000 vbv_delay: N/A
32+
33+
# [das@hp1:~/nixos/hp/hp1]$ sudo tcpdump -ni eno1 -c 5 host 239.0.0.1
34+
# tcpdump: verbose output suppressed, use -v[v]... for full protocol decode
35+
# listening on eno1, link-type EN10MB (Ethernet), snapshot length 262144 bytes
36+
# 15:21:39.577834 IP 172.16.40.142.4032 > 239.0.0.1.6000: UDP, length 1326
37+
# 15:21:39.577866 IP 172.16.40.142.4032 > 239.0.0.1.6000: UDP, length 1326
38+
# 15:21:39.577885 IP 172.16.40.142.4032 > 239.0.0.1.6000: UDP, length 1326
39+
# 15:21:39.577907 IP 172.16.40.142.4032 > 239.0.0.1.6000: UDP, length 1326
40+
# 15:21:39.577927 IP 172.16.40.142.4032 > 239.0.0.1.6000: UDP, length 1326
41+
# 5 packets captured
42+
# 35 packets received by filter
43+
# 0 packets dropped by kernel
44+
45+
{
46+
config,
47+
lib,
48+
pkgs,
49+
...
50+
}:
51+
52+
# ${pkgs.ffmpeg}/bin/ffmpeg \
53+
# ${home.packages.ffmpeg-full}/bin/ffmpeg \
54+
# ffmpeg -f lavfi -i "sine=frequency=1000:duration=10" -c:a aac -b:a 128k /home/das/test_audio.aac
55+
let
56+
ffmpegCmd =
57+
''
58+
${pkgs.ffmpeg-full}/bin/ffmpeg -f lavfi -re -i testsrc2=rate=30:size=1920x1080 \
59+
-f lavfi -i "sine=frequency=1000" \
60+
-c:v libx264 -b:v 10000k -preset ultrafast -r 25 \
61+
-x264-params "nal-hrd=cbr:force-cfr=1:aud=1:intra-refresh=1" \
62+
-tune zerolatency \
63+
-bsf:v h264_mp4toannexb \
64+
-c:a aac -b:a 128k -ac 2 \
65+
-max_delay 500000 -bufsize 2000000 -fflags +genpts \
66+
-f rtp_mpegts "rtp://239.0.0.2:6000?pkt_size=1326&ttl=4&localaddr=172.16.40.142"
67+
'';
68+
# Ensures SPS/PPS is sent in every keyframe (prevents decoder from losing parameter sets).
69+
# Forces constant frame rate (force-cfr=1), improving stream stability.
70+
71+
# ''
72+
# ${pkgs.ffmpeg-full}/bin/ffmpeg \
73+
# -f lavfi -re -i testsrc2=rate=30:size=1920x1080 \
74+
# -f lavfi -i "sine=frequency=1000" \
75+
# -c:v libx264 -b:v 10000k -preset ultrafast -r 25 \
76+
# -c:a aac -b:a 128k -ac 2 \
77+
# -x264opts "keyint=50:min-keyint=50:no-scenecut" \
78+
# -bsf:v h264_mp4toannexb \
79+
# -max_delay 500000 -bufsize 2000000 -fflags +genpts \
80+
# -f rtp_mpegts "rtp://239.0.0.1:6000?pkt_size=1326&ttl=4&localaddr=172.16.40.142"
81+
# '';
82+
#-x264opts "keyint=50:min-keyint=50:no-scenecut" ensures regular keyframes.
83+
#-bsf:v h264_mp4toannexb converts H.264 to Annex B format, which is better for streaming.
84+
85+
# ''
86+
# ${pkgs.ffmpeg-full}/bin/ffmpeg \
87+
# -f lavfi -re -i testsrc2=rate=30:size=1920x1080 \
88+
# -f lavfi -i "sine=frequency=1000" \
89+
# -c:v libx264 -b:v 10000k -preset ultrafast -r 25 \
90+
# -c:a aac -b:a 128k -ac 2 \
91+
# -max_delay 500000 -bufsize 2000000 -fflags +genpts \
92+
# -f rtp_mpegts \
93+
# "rtp://239.0.0.1:6000?pkt_size=1326&ttl=4&localaddr=172.16.40.142"
94+
# '';
95+
96+
# ''
97+
# ${pkgs.ffmpeg-full}/bin/ffmpeg \
98+
# -f lavfi -re -i testsrc2=rate=30:size=1920x1080 \
99+
# -re -i /home/das/test_audio/test_audio.aac \
100+
# -c:v libx264 -b:v 10240k -maxrate:v 10000k -bufsize:v 10240k -preset ultrafast -r 25 -g 50 -pix_fmt yuv420p -flags2 local_header \
101+
# -c:a aac -b:a 128k -ac 2 \
102+
# -max_delay 500000 -bufsize 2000000 -fflags +genpts \
103+
# -f rtp_mpegts \
104+
# "rtp://239.0.0.1:6000?ttl=4&pkt_size=1326&localaddr=172.16.40.142"
105+
# '';
106+
# ''
107+
# ${pkgs.ffmpeg}/bin/ffmpeg \
108+
# -f lavfi \
109+
# -re \
110+
# -i testsrc2=rate=30:size=1920x1080 \
111+
# -codec:v libx264 \
112+
# -b:v 10240k \
113+
# -maxrate:v 10000k \
114+
# -bufsize:v 10240k \
115+
# -preset ultrafast \
116+
# -r 25 \
117+
# -g 50 \
118+
# -pix_fmt yuv420p \
119+
# -flags2 local_header \
120+
# -f mpegts \
121+
# -transtype live \
122+
# "rtp://239.0.0.1:6000?ttl=4&pkt_size=1326&localddr=172.16.40.142"
123+
# '';
124+
in
125+
{
126+
# sudo systemctl status ffmpeg-stream.service
127+
# sudo journalctl -u ffmpeg-stream.service
128+
# cat /etc/systemd/system/ffmpeg-stream.service
129+
systemd.services.ffmpeg-stream = {
130+
131+
description = "FFmpeg Multicast Service";
132+
after = [ "network.target" ];
133+
134+
serviceConfig = {
135+
ExecStart = "${ffmpegCmd}";
136+
Restart = "always";
137+
RestartSec = 10;
138+
StandardOutput = "journal";
139+
StandardError = "journal";
140+
141+
# https://www.freedesktop.org/software/systemd/man/latest/systemd.exec.html#Scheduling
142+
Nice = "-20";
143+
#CPUSchedulingPriority = "99";
144+
145+
### 🔐 Security Hardening Options ###
146+
NoNewPrivileges = true; # Prevents privilege escalation
147+
PrivateTmp = true; # Isolates service temporary files
148+
ProtectSystem = "full"; # Restricts access to system files
149+
#ProtectSystem = "strict"; # Restricts access to system files
150+
#ProtectHome = "read-only"; # Readonly access to home directory
151+
ProtectHome = "yes"; # Blocks access to home directory
152+
ProtectKernelModules = true; # Blocks module loading
153+
ProtectKernelLogs = true; # Prevents access to kernel logs
154+
ProtectControlGroups = true; # Restricts cgroup modifications
155+
MemoryDenyWriteExecute = true; # Prevents memory exploits
156+
RestrictRealtime = true; # Blocks real-time priority settings
157+
RestrictAddressFamilies = [ "AF_INET" "AF_INET6" ]; # Restricts network access
158+
SystemCallFilter = [ "~@mount" "~@privileged" "~@resources" ]; # Blocks dangerous system calls
159+
LockPersonality = true; # Prevents personality changes (defense against exploits)
160+
ReadOnlyPaths = "/usr"; # Makes important paths read-only
161+
#ReadOnlyPaths = "/etc /usr /home/das/test_audio/"; # Makes important paths read-only
162+
#wReadWritePaths = "/var/www/html"; # Only allow writing in this directory
163+
ProtectClock = true; # Blocks modification of system clock
164+
};
165+
166+
# # systemctl list-units --type target
167+
# Install = {
168+
# after = [ "network.target" ];
169+
# #WantedBy = [ "default.target" ];
170+
# };
171+
};
172+
}

hp/hp1/flake.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
{
22
description = "HP1 Flake";
33

4+
# https://nix.dev/manual/nix/2.24/command-ref/new-cli/nix3-flake.html#flake-inputs
45
inputs = {
56
nixpkgs.url = "github:nixos/nixpkgs/nixos-24.11";
7+
68
# https://nixos-and-flakes.thiscute.world/nixos-with-flakes/start-using-home-manager
79
home-manager = {
810
url = "github:nix-community/home-manager/release-24.11";

0 commit comments

Comments
 (0)