Skip to content

Commit d556dbb

Browse files
sync
1 parent b204a34 commit d556dbb

18 files changed

+545
-122
lines changed

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ rebuild:
2222
#sudo nixos-rebuild switch
2323
#sudo nix-channel --update;
2424
sudo nixos-rebuild switch --flake .
25-
systemctl --user restart ffmpeg-stream
25+
sudo systemctl restart ffmpeg-stream
2626

2727
rebuild_trace:
2828
sudo nixos-rebuild switch --show-trace --flake .

hp/hp1/configuration.nix

Lines changed: 19 additions & 9 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 = {
@@ -74,9 +80,13 @@
7480
amdvlk # AMD Vulkan driver, includes AMF runtime
7581
#rocm-opencl-runtime # Optional: ROCm OpenCL support
7682
#rocm-smi # AMD System Management Interface (for monitoring GPU)
83+
# https://nixos.wiki/wiki/AMD_GPU#OpenCL
84+
rocmPackages.clr.icd
7785
];
7886
};
7987

88+
services.xserver.videoDrivers = [ "amdgpu" ];
89+
8090
# https://nixos.wiki/wiki/Networking
8191
# https://nlewo.github.io/nixos-manual-sphinx/configuration/ipv4-config.xml.html
8292
networking.hostName = "hp1";

hp/hp1/ffmpeg_systemd_service.nix

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
# ffmpeg -f lavfi -i "sine=frequency=1000:duration=10" -c:a aac -b:a 128k /home/das/test_audio.aac
5555
let
5656
ffmpegCmd =
57-
5857
''
5958
${pkgs.ffmpeg-full}/bin/ffmpeg -f lavfi -re -i testsrc2=rate=30:size=1920x1080 \
6059
-f lavfi -i "sine=frequency=1000" \
@@ -64,7 +63,7 @@ let
6463
-bsf:v h264_mp4toannexb \
6564
-c:a aac -b:a 128k -ac 2 \
6665
-max_delay 500000 -bufsize 2000000 -fflags +genpts \
67-
-f rtp_mpegts "rtp://239.0.0.1:6000?pkt_size=1326&ttl=4&localaddr=172.16.40.142"
66+
-f rtp_mpegts "rtp://239.0.0.2:6000?pkt_size=1326&ttl=4&localaddr=172.16.40.142"
6867
'';
6968
# Ensures SPS/PPS is sent in every keyframe (prevents decoder from losing parameter sets).
7069
# Forces constant frame rate (force-cfr=1), improving stream stability.
@@ -124,25 +123,32 @@ let
124123
# '';
125124
in
126125
{
127-
systemd.user.services.ffmpeg-stream = {
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 = {
128130

129-
Unit = {
130-
description = "FFmpeg Multicast Service";
131-
};
131+
description = "FFmpeg Multicast Service";
132+
after = [ "network.target" ];
132133

133-
Service = {
134+
serviceConfig = {
134135
ExecStart = "${ffmpegCmd}";
135136
Restart = "always";
136-
RestartSec = 2;
137+
RestartSec = 10;
137138
StandardOutput = "journal";
138139
StandardError = "journal";
139140

141+
# https://www.freedesktop.org/software/systemd/man/latest/systemd.exec.html#Scheduling
142+
Nice = "-20";
143+
#CPUSchedulingPriority = "99";
144+
140145
### 🔐 Security Hardening Options ###
141146
NoNewPrivileges = true; # Prevents privilege escalation
142147
PrivateTmp = true; # Isolates service temporary files
143-
ProtectSystem = "strict"; # Restricts access to system files
144-
ProtectHome = "read-only"; # Readonly access to home directory
145-
#ProtectHome = "yes"; # Blocks access to home directory
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
146152
ProtectKernelModules = true; # Blocks module loading
147153
ProtectKernelLogs = true; # Prevents access to kernel logs
148154
ProtectControlGroups = true; # Restricts cgroup modifications
@@ -151,14 +157,16 @@ in
151157
RestrictAddressFamilies = [ "AF_INET" "AF_INET6" ]; # Restricts network access
152158
SystemCallFilter = [ "~@mount" "~@privileged" "~@resources" ]; # Blocks dangerous system calls
153159
LockPersonality = true; # Prevents personality changes (defense against exploits)
154-
ReadOnlyPaths = "/etc /usr /home/das/test_audio/"; # Makes important paths read-only
160+
ReadOnlyPaths = "/usr"; # Makes important paths read-only
161+
#ReadOnlyPaths = "/etc /usr /home/das/test_audio/"; # Makes important paths read-only
155162
#wReadWritePaths = "/var/www/html"; # Only allow writing in this directory
156163
ProtectClock = true; # Blocks modification of system clock
157164
};
158165

159-
Install = {
160-
after = [ "network.target" ];
161-
WantedBy = [ "default.target" ];
162-
};
166+
# # systemctl list-units --type target
167+
# Install = {
168+
# after = [ "network.target" ];
169+
# #WantedBy = [ "default.target" ];
170+
# };
163171
};
164172
}

hp/hp1/home.nix

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
home.username = "das";
88
home.homeDirectory = "/home/das";
99

10-
imports = [
11-
./ffmpeg_systemd_service.nix
12-
];
10+
# imports = [
11+
# #./ffmpeg_systemd_service.nix
12+
# ];
1313

1414
# https://nix-community.github.io/home-manager/index.xhtml#ch-installation
1515
#home-manager.users.das = { pkgs, ... }: {

hp/hp1/systemPackages.nix

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
{ config, pkgs, ... }:
2-
1+
{
2+
config,
3+
pkgs,
4+
...
5+
}:
36
{
47
# Allow unfree packages
58
nixpkgs.config.allowUnfree = true;
@@ -28,5 +31,7 @@
2831
#
2932
ffmpeg-full
3033
radeontop # GPU monitoring tool
34+
# https://nixos.wiki/wiki/AMD_GPU#OpenCL
35+
clinfo
3136
];
3237
}

hp/hp5/ffmpeg-hls-service.nix

Lines changed: 69 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -68,35 +68,72 @@ let
6868
# a=rtpmap:33 MP2T/90000
6969
# '';
7070

71+
# https://developer.nvidia.com/blog/nvidia-ffmpeg-transcoding-guide/#processing_filters
7172
ffmpegCmd = ''
7273
${pkgs.ffmpeg-full}/bin/ffmpeg \
73-
-hwaccel cuda -hwaccel_output_format cuda \
74+
-vsync 0 \
75+
-hwaccel cuda \
76+
-hwaccel_output_format cuda \
7477
-protocol_whitelist "file,udp,rtp" \
7578
-analyzeduration 200000000 \
7679
-probesize 150M \
7780
-fflags +genpts -max_delay 5000000 \
7881
-f mpegts \
7982
-i /hls/stream.sdp \
80-
-filter_complex "[0:v]hwupload_cuda,split=3[v10_in][v5_in][v1_in]; \
81-
[v10_in]scale_cuda=w=1920:h=1080,hwdownload,format=yuv420p[v10_scaled]; \
82-
[v5_in]scale_cuda=w=1280:h=720,hwdownload,format=yuv420p[v5_scaled]; \
83-
[v1_in]scale_cuda=w=640:h=360,hwdownload,format=yuv420p[v1_scaled]" \
84-
-map "[v10_scaled]" -map 0:a:0 -c:v h264_nvenc -pix_fmt nv12 -b:v 10M -bufsize 20M -preset p5 -g 50 -keyint_min 50 -c:a aac -b:a 128k -ac 2 \
85-
-f hls -hls_time 4 -hls_list_size 20 -hls_delete_threshold 2 \
86-
-hls_flags delete_segments+independent_segments+temp_file+discont_start+omit_endlist \
87-
-strftime 1 -hls_segment_filename "/hls/hls_10Mbps/stream-%Y%m%d%H%M%S.ts" \
88-
"/hls/hls_10Mbps/stream_10.m3u8" \
89-
-map "[v5_scaled]" -map 0:a:0 -c:v h264_nvenc -pix_fmt nv12 -b:v 5M -bufsize 10M -preset p5 -g 50 -keyint_min 50 -c:a aac -b:a 128k -ac 2 \
90-
-f hls -hls_time 4 -hls_list_size 20 -hls_delete_threshold 2 \
91-
-hls_flags delete_segments+independent_segments+temp_file+discont_start+omit_endlist \
92-
-strftime 1 -hls_segment_filename "/hls/hls_5Mbps/stream-%Y%m%d%H%M%S.ts" \
93-
"/hls/hls_5Mbps/stream_5.m3u8" \
94-
-map "[v1_scaled]" -map 0:a:0 -c:v h264_nvenc -pix_fmt nv12 -b:v 1M -bufsize 2M -preset p5 -g 50 -keyint_min 50 -c:a aac -b:a 128k -ac 2 \
95-
-f hls -hls_time 4 -hls_list_size 20 -hls_delete_threshold 2 \
96-
-hls_flags delete_segments+independent_segments+temp_file+discont_start+omit_endlist \
97-
-strftime 1 -hls_segment_filename "/hls/hls_1Mbps/stream-%Y%m%d%H%M%S.ts" \
98-
"/hls/hls_1Mbps/stream_1.m3u8"
83+
-filter_complex "[0:v]split=2[v2][v3]; \
84+
[v2]scale_npp=1280:720:interp_algo=super[vout2]; \
85+
[v3]scale_npp=640:360:interp_algo=super[vout3]" \
86+
-map 0:v -c:v hevc_nvenc -b:v 10M -preset p1 -tune hq -rc cbr -maxrate 10M -bufsize 20M -g 50 -pix_fmt yuv420p \
87+
-f hls -hls_time 4 -hls_list_size 20 -hls_delete_threshold 2 \
88+
-hls_flags delete_segments+independent_segments+temp_file+discont_start+omit_endlist \
89+
-strftime 1 -hls_segment_filename "/hls/hls_10Mbps/stream-%Y%m%d%H%M%S.ts" \
90+
"/hls/hls_10Mbps/stream_10.m3u8" \
91+
-map "[vout2]" -c:v hevc_nvenc -b:v 5M -preset p1 -tune hq -rc cbr -maxrate 5M -bufsize 10M -g 50 -pix_fmt yuv420p \
92+
-f hls -hls_time 4 -hls_list_size 20 -hls_delete_threshold 2 \
93+
-hls_flags delete_segments+independent_segments+temp_file+discont_start+omit_endlist \
94+
-strftime 1 -hls_segment_filename "/hls/hls_5Mbps/stream-%Y%m%d%H%M%S.ts" \
95+
"/hls/hls_5Mbps/stream_5.m3u8" \
96+
-map "[vout3]" -c:v hevc_nvenc -b:v 1M -preset p1 -tune hq -rc cbr -maxrate 1M -bufsize 2M -g 50 -pix_fmt yuv420p \
97+
-f hls -hls_time 4 -hls_list_size 20 -hls_delete_threshold 2 \
98+
-hls_flags delete_segments+independent_segments+temp_file+discont_start+omit_endlist \
99+
-strftime 1 -hls_segment_filename "/hls/hls_1Mbps/stream-%Y%m%d%H%M%S.ts" \
100+
"/hls/hls_1Mbps/stream_1.m3u8" \
101+
-map a:0 -c:a aac -b:a 128k -ac 2 -f hls -hls_time 4 -hls_list_size 20 \
102+
-hls_segment_filename "/hls/audio/stream-%Y%m%d%H%M%S.ts" "/hls/audio/stream_audio.m3u8" \
103+
-master_pl_name "/hls/master.m3u8"
99104
'';
105+
106+
# ffmpegCmd = ''
107+
# ${pkgs.ffmpeg-full}/bin/ffmpeg \
108+
# -vsync 0 \
109+
# -hwaccel cuda -hwaccel_output_format cuda \
110+
# -protocol_whitelist "file,udp,rtp" \
111+
# -analyzeduration 200000000 \
112+
# -probesize 150M \
113+
# -fflags +genpts -max_delay 5000000 \
114+
# -f mpegts \
115+
# -i /hls/stream.sdp \
116+
# -filter_complex "[0:v]hwupload_cuda,split=3[v10_in][v5_in][v1_in]; \
117+
# [v10_in]scale_cuda=w=1920:h=1080,hwdownload,format=yuv420p[v10_scaled]; \
118+
# [v5_in]scale_cuda=w=1280:h=720,hwdownload,format=yuv420p[v5_scaled]; \
119+
# [v1_in]scale_cuda=w=640:h=360,hwdownload,format=yuv420p[v1_scaled]" \
120+
# -map "[v10_scaled]" -map 0:a:0 -c:v h264_nvenc -pix_fmt nv12 -b:v 10M -bufsize 20M -preset p5 -g 50 -keyint_min 50 -c:a aac -b:a 128k -ac 2 \
121+
# -f hls -hls_time 4 -hls_list_size 20 -hls_delete_threshold 2 \
122+
# -hls_flags delete_segments+independent_segments+temp_file+discont_start+omit_endlist \
123+
# -strftime 1 -hls_segment_filename "/hls/hls_10Mbps/stream-%Y%m%d%H%M%S.ts" \
124+
# "/hls/hls_10Mbps/stream_10.m3u8" \
125+
# -map "[v5_scaled]" -map 0:a:0 -c:v h264_nvenc -pix_fmt nv12 -b:v 5M -bufsize 10M -preset p5 -g 50 -keyint_min 50 -c:a aac -b:a 128k -ac 2 \
126+
# -f hls -hls_time 4 -hls_list_size 20 -hls_delete_threshold 2 \
127+
# -hls_flags delete_segments+independent_segments+temp_file+discont_start+omit_endlist \
128+
# -strftime 1 -hls_segment_filename "/hls/hls_5Mbps/stream-%Y%m%d%H%M%S.ts" \
129+
# "/hls/hls_5Mbps/stream_5.m3u8" \
130+
# -map "[v1_scaled]" -map 0:a:0 -c:v h264_nvenc -pix_fmt nv12 -b:v 1M -bufsize 2M -preset p5 -g 50 -keyint_min 50 -c:a aac -b:a 128k -ac 2 \
131+
# -f hls -hls_time 4 -hls_list_size 20 -hls_delete_threshold 2 \
132+
# -hls_flags delete_segments+independent_segments+temp_file+discont_start+omit_endlist \
133+
# -strftime 1 -hls_segment_filename "/hls/hls_1Mbps/stream-%Y%m%d%H%M%S.ts" \
134+
# "/hls/hls_1Mbps/stream_1.m3u8 \
135+
# -master_pl_name /hls/master.m3u8"
136+
# '';
100137
# -i "rtp://239.0.0.1:6000" \
101138
# -i /hls/stream.sdp \
102139
# -filter_complex "[0:v]split=3[v10][v5][v1]; \
@@ -120,11 +157,13 @@ in
120157
}
121158
];
122159

160+
# https://www.freedesktop.org/software/systemd/man/latest/tmpfiles.d.html
123161
systemd.tmpfiles.rules = [
162+
#Type Path Mode User Group Age Argument…
124163
"d /hls 0770 nginx nginx -"
125-
"d /hls/hls_10Mbps 0770 nginx nginx -"
126-
"d /hls/hls_5Mbps 0770 nginx nginx -"
127-
"d /hls/hls_1Mbps 0770 nginx nginx -"
164+
"d /hls/hls_10Mbps 0770 nginx nginx 5m"
165+
"d /hls/hls_5Mbps 0770 nginx nginx 5m"
166+
"d /hls/hls_1Mbps 0770 nginx nginx 5m"
128167
];
129168

130169
# sudo systemctl restart create-stream-sdp.service
@@ -178,6 +217,13 @@ in
178217
StandardError = "journal";
179218
LimitNOFILE = 1048576;
180219

220+
# https://www.freedesktop.org/software/systemd/man/latest/systemd.exec.html#Scheduling
221+
Nice = "-20";
222+
#CPUSchedulingPriority = "99";
223+
# https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/8/html/managing_monitoring_and_updating_the_kernel/assembly_configuring-cpu-affinity-and-numa-policies-using-systemd_managing-monitoring-and-updating-the-kernel#assembly_configuring-cpu-affinity-and-numa-policies-using-systemd_managing-monitoring-and-updating-the-kernel
224+
#CPUAffinity=
225+
#NUMAMask=
226+
181227
Environment = [
182228
"CUDA_PATH=${pkgs.linuxPackages.nvidia_x11}/lib"
183229
"EXTRA_LDFLAGS=-L/lib -L${pkgs.linuxPackages.nvidia_x11}/lib"

laptops/t/configuration.nix

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
{
2323
# https://nixos.wiki/wiki/NixOS_modules
2424
# https://nixos-and-flakes.thiscute.world/nixos-with-flakes/start-using-home-manager
25-
#<home-manager/nixos>
2625
imports =
2726
[
2827
./hardware-configuration.nix
@@ -87,7 +86,7 @@
8786
# https://gist.github.com/chrisheib/162c8cad466638f568f0fb7e5a6f4f6b#file-config_working-nix-L19
8887
extraModprobeConfig =
8988
"options nvidia "
90-
""
89+
#""
9190
+ lib.concatStringsSep " " [
9291
# nvidia assume that by default your CPU does not support PAT,
9392
# but this is effectively never the case in 2023
@@ -164,9 +163,20 @@
164163
# https://nixos.wiki/wiki/Printing
165164
services.printing.enable = true;
166165

166+
# https://wiki.nixos.org/wiki/Flameshot
167+
# services.flameshot = {
168+
# enable = true;
169+
# settings.General = {
170+
# showStartupLaunchMessage = false;
171+
# saveLastRegion = true;
172+
# };
173+
# };
174+
167175
systemd.services.modem-manager.enable = false;
168176
systemd.services."dbus-org.freedesktop.ModemManager1".enable = false;
169177

178+
services.clickhouse.enable = true;
179+
170180
# environment.variables defined in hardware-graphics.nix
171181
environment.sessionVariables = {
172182
TERM = "xterm-256color";
@@ -178,7 +188,6 @@
178188
isNormalUser = true;
179189
description = "das";
180190
extraGroups = [ "wheel" "networkmanager" "kvm" "libvirtd" "docker" "video" ];
181-
# users.extraGroups.docker.members = [ "das" ];
182191
packages = with pkgs; [
183192
];
184193
# https://nixos.wiki/wiki/SSH_public_key_authentication
@@ -187,11 +196,9 @@
187196
];
188197
};
189198

190-
191199
# package moved to systemPackages.nix
192200
# environment.systemPackages = with pkgs; [
193201

194-
195202
# Some programs need SUID wrappers, can be configured further or are
196203
# started in user sessions.
197204
# programs.mtr.enable = true;

0 commit comments

Comments
 (0)