nixos/hosts/FredOS-Mediaserver.nix

91 lines
3.3 KiB
Nix
Raw Normal View History

2026-01-20 09:59:20 +00:00
{ config, pkgs, lib, ... }:
{
2026-01-20 14:35:20 +00:00
config = lib.mkIf (config.networking.hostName == "FredOS-Mediaserver") {
2026-01-20 14:42:21 +00:00
# Create symlink from home to storage
systemd.tmpfiles.rules = [
"L+ /home/fred/storage - - - - /mnt/storage"
];
2026-01-20 09:59:20 +00:00
2026-01-20 14:42:21 +00:00
# Basic system packages
2026-01-20 14:35:20 +00:00
environment.systemPackages = with pkgs; [
mergerfs
wget
util-linux
2026-01-25 16:01:40 +00:00
javaPackages.compiler.temurin-bin.jre-25
2026-01-25 16:06:34 +00:00
unzip
2026-01-25 16:40:19 +00:00
screen
2026-01-26 15:22:01 +00:00
yt-dlp
2026-04-09 10:07:38 +01:00
ghostty.terminfo
2026-04-20 11:19:11 +01:00
usbutils
2026-04-20 11:34:49 +01:00
lm_sensors
(pkgs.writeShellScriptBin "transcode-hevc" ''
export PATH="${pkgs.jellyfin-ffmpeg}/bin:${pkgs.coreutils}/bin:${pkgs.findutils}/bin:${pkgs.gnugrep}/bin:${pkgs.gawk}/bin:${pkgs.bc}/bin:${pkgs.curl}/bin:$PATH"
exec ${pkgs.bash}/bin/bash ${../scripts/transcode-hevc.sh} "$@"
'')
(pkgs.writeShellScriptBin "record-update" ''
export PATH="${pkgs.nvd}/bin:${pkgs.coreutils}/bin:${pkgs.gnugrep}/bin:${pkgs.gnused}/bin:$PATH"
exec ${pkgs.bash}/bin/bash ${../scripts/record-update.sh} "$@"
'')
# Stats stream for the quickshell server monitor on the desktops:
# `ssh mediaserver qs-stats` = top's 2s batch stream, interleaved with
# one @STAT line per tick (hottest coretemp across both sockets, WAN
# byte rates from eno1). Everything rides one SSH connection.
(pkgs.writeShellScriptBin "qs-stats" ''
# Single writer: the loop re-emits top's lines itself and injects a
# @STAT line at each frame header. top writing the pipe directly in
# parallel raced the injected lines (pipe writes aren't line-atomic)
# and spliced @STAT mid-frame, where the client parser never saw it.
C=${pkgs.coreutils}/bin
export LC_ALL=C
prev_rx=""
${pkgs.procps}/bin/top -b -d 2 -w 512 | while IFS= read -r line; do
printf '%s\n' "$line"
case $line in
"top - "*)
t=0
for h in /sys/class/hwmon/*; do
[ "$($C/cat "$h/name" 2>/dev/null)" = coretemp ] || continue
for f in "$h"/temp*_input; do
v=$($C/cat "$f" 2>/dev/null || echo 0)
[ "$v" -gt "$t" ] && t=$v
done
done
read -r rx tx < <(${pkgs.gawk}/bin/awk '$1 == "eno1:" {print $2, $10}' /proc/net/dev)
if [ -n "$prev_rx" ]; then
printf '@STAT temp=%s rxbps=%s txbps=%s\n' "$((t / 1000))" "$(( (rx - prev_rx) / 2 ))" "$(( (tx - prev_tx) / 2 ))"
fi
prev_rx=$rx
prev_tx=$tx
;;
esac
done
'')
2026-01-20 14:35:20 +00:00
];
2026-01-20 09:59:20 +00:00
2026-01-20 14:42:21 +00:00
# Basic networking
networking.useDHCP = lib.mkForce false;
2026-01-20 14:42:21 +00:00
2026-05-14 12:54:19 +01:00
# Allow fred to act as a remote Nix builder (trusted users can import
# unsigned store paths sent by the build client).
nix.settings.trusted-users = [ "root" "fred" ];
2026-05-19 17:10:17 +01:00
# Automatic daily system updates
system.autoUpgrade = {
enable = true;
flake = "git+https://forg.gregersen.it/rope/nixos";
dates = "05:15";
2026-05-19 17:10:17 +01:00
allowReboot = true;
};
# WAN exposure is controlled by nftables in services/router.nix +
# ports.toml (networking.firewall is disabled on this host).
2026-01-20 14:42:21 +00:00
services.openssh = {
enable = true;
settings = {
PermitRootLogin = "no";
PasswordAuthentication = false;
};
2026-01-20 14:42:21 +00:00
};
2026-01-20 14:35:20 +00:00
};
2026-01-20 09:59:20 +00:00
}