Compare commits

...
8 Commits
Author SHA1 Message Date
Jan-Bulthuis 9100eca4c8 feat: self signed SSL web 2026-11-20 17:16:41 +01:00
Jan-Bulthuis 1715876ea7 chore: reduce slopments 2026-11-20 16:52:12 +01:00
Jan-Bulthuis f41867b5bf fix: vpn 2026-11-18 13:18:55 +01:00
Jan-Bulthuis 781ac510fb fix: web access 2026-11-18 12:51:48 +01:00
Jan-Bulthuis 36dc96d86f chore: update flake 2026-11-18 12:44:58 +01:00
Jan-Bulthuis ed2d2731d6 feat: steam frame setup 2026-11-18 12:27:31 +01:00
Jan-Bulthuis 91ea6863d7 fix: boot 2026-11-18 12:26:28 +01:00
Jan-Bulthuis 341a168dc0 feat: chrome xr package 2026-11-18 12:26:07 +01:00
9 changed files with 374 additions and 52 deletions

No files matched your search

Generated
+4 -4
View File
@@ -176,11 +176,11 @@
},
"secrets": {
"locked": {
"lastModified": 1795000895,
"narHash": "sha256-DzTRUpiuhSmPJm/MjcUwNLxVbhWxjC1TGLyj41kXnr4=",
"lastModified": 1795002280,
"narHash": "sha256-PpeywbmyLrlliMSLvNCLT3L6Mmu5xHCGERrYuFIEM2s=",
"ref": "refs/heads/main",
"rev": "557ab40690eb4320e36c5e57b73bfba1ecb73393",
"revCount": 23,
"rev": "0b61e4b871c3bb33d25fdb5493a995dfef14f8e5",
"revCount": 24,
"type": "git",
"url": "ssh://gitea@git.bulthuis.dev/Jan/nixos-secrets"
},
+67 -45
View File
@@ -6,23 +6,17 @@
...
}:
# Always-on torrent client, confined to a VPN-only network namespace, plus a
# read-only, password-protected WebDAV share of its downloads for the local network.
#
# Everything provider-specific lives in secrets:
# seedbox/wireguard wg-quick style config (keys, peer, Address, DNS, MTU)
# seedbox/port the incoming port forwarded by the VPN
# seedbox/share-password password for the share (user "seedbox")
#
# Web interface: only on this host's localhost, e.g. `ssh -L 8081:127.0.0.1:8081 ws-home`
# Torrent client confined to a VPN-only network namespace, plus a WebDAV share.
# See seedbox.md.
let
netns = "seedbox";
wgIf = "wg-seedbox";
dataDir = "/var/lib/seedbox";
downloadsDir = "${dataDir}/downloads";
webuiProxyPort = 8081; # localhost of this host only
webuiPort = 8080; # inside the namespace
certDir = "${dataDir}/webui-tls";
webuiPort = 8081;
sharePort = 8091;
inherit (config.networking) hostName;
secret = name: config.sops.secrets."seedbox/${name}".path;
secretFile = "${inputs.secrets}/secrets/ws-home.enc.yaml";
@@ -34,6 +28,7 @@ let
};
netnsDeps = {
bindsTo = [ "seedbox-netns.service" ];
partOf = [ "seedbox-netns.service" ];
after = [ "seedbox-netns.service" ];
};
in
@@ -59,15 +54,15 @@ in
];
systemd.tmpfiles.rules = [ "d ${downloadsDir} 0750 ${user} ${group} -" ];
# Network namespace whose only route out is the WireGuard interface. The interface
# is created here and moved into the namespace, so its encrypted traffic uses the
# host's network, but nothing inside the namespace can reach anything else.
boot.kernelModules = [ "tcp_bbr" ];
systemd.services.seedbox-netns = {
description = "Network namespace for the seedbox";
wants = [ "network-online.target" ];
after = [ "network-online.target" ];
path = with pkgs; [
iproute2
procps
wireguard-tools
gnugrep
gnused
@@ -90,8 +85,19 @@ in
ip netns add ${netns}
ip -n ${netns} link set lo up
# wg-quick strip requires a .conf file name
stripped=$(grep -viE '^\s*(Address|DNS|MTU|Table|SaveConfig|(Pre|Post)(Up|Down))\s*=' "$conf")
if ! grep -qi '^\s*PrivateKey' <<<"$stripped" || ! grep -qi '^\s*\[Peer\]' <<<"$stripped"; then
echo "seedbox/wireguard has no PrivateKey or [Peer]" >&2
exit 1
fi
ip link add ${wgIf} type wireguard
wg setconf ${wgIf} <(wg-quick strip "$conf")
wg setconf ${wgIf} <(printf '%s\n' "$stripped")
if ! wg show ${wgIf} peers | grep -q .; then
echo "WireGuard peer was not configured" >&2
exit 1
fi
ip link set ${wgIf} netns ${netns}
for addr in $(field Address); do
ip -n ${netns} addr add "$addr" dev ${wgIf}
@@ -103,7 +109,13 @@ in
ip -n ${netns} -6 route add default dev ${wgIf}
fi
# DNS only through the tunnel
# Faster TCP to distant peers
ip netns exec ${netns} sysctl -q -w \
net.ipv4.tcp_congestion_control=bbr \
net.ipv4.tcp_wmem="4096 65536 16777216" \
net.ipv4.tcp_rmem="4096 131072 16777216" \
net.ipv4.tcp_slow_start_after_idle=0
field DNS | grep -v ':' | sed 's/^/nameserver /' > /run/seedbox/resolv.conf
echo 'hosts: files dns' > /run/seedbox/nsswitch.conf
'';
@@ -121,8 +133,7 @@ in
systemd.services.qbittorrent = netnsDeps // {
serviceConfig = inNetns // {
# Resolve names only with the tunnel's DNS. The host's nscd would resolve them
# outside the namespace, so it is hidden.
# nscd would bypass the tunnel's DNS
BindReadOnlyPaths = [
"/run/seedbox/resolv.conf:/etc/resolv.conf"
"/run/seedbox/nsswitch.conf:/etc/nsswitch.conf"
@@ -130,8 +141,6 @@ in
InaccessiblePaths = [ "-/run/nscd" ];
ReadWritePaths = [ dataDir ];
# Initial settings, and the incoming port from the secret on every start. Other
# settings are left to the web interface.
ExecStartPre = pkgs.writeShellScript "seedbox-config" ''
set -euo pipefail
PATH=${
@@ -139,41 +148,53 @@ in
with pkgs;
[
coreutils
gnused
crudini
openssl
]
)
}
port=$(tr -dc 0-9 < ${secret "port"})
cfg=${dataDir}/qBittorrent/config/qBittorrent.conf
mkdir -p ${downloadsDir} "$(dirname "$cfg")"
if [ ! -f "$cfg" ]; then
cat > "$cfg" <<EOF
[BitTorrent]
Session\DefaultSavePath=${downloadsDir}
Session\Interface=${wgIf}
Session\InterfaceName=${wgIf}
Session\LSDEnabled=false
Session\QueueingSystemEnabled=false
Session\Port=$port
set_() { crudini --ini-options=nospace --set "$cfg" "$@"; }
[Network]
PortForwardingEnabled=false
[Preferences]
WebUI\Address=127.0.0.1
WebUI\Port=${toString webuiPort}
EOF
else
sed -i -E "s|^Session\\\\Port=.*|Session\\\\Port=$port|" "$cfg"
if [ ! -f ${certDir}/cert.pem ]; then
mkdir -p ${certDir}
openssl req -x509 -newkey ec -pkeyopt ec_paramgen_curve:prime256v1 -nodes \
-days 3650 -subj /CN=${hostName} -addext subjectAltName=DNS:${hostName},DNS:seedbox.bulthuis.dev \
-keyout ${certDir}/key.pem -out ${certDir}/cert.pem
chmod 600 ${certDir}/key.pem
fi
if [ ! -f "$cfg" ]; then
touch "$cfg"
set_ BitTorrent 'Session\DefaultSavePath' ${downloadsDir}
set_ BitTorrent 'Session\LSDEnabled' false
set_ BitTorrent 'Session\QueueingSystemEnabled' false
fi
set_ BitTorrent 'Session\Port' "$(tr -dc 0-9 < ${secret "port"})"
set_ BitTorrent 'Session\Interface' ${wgIf}
set_ BitTorrent 'Session\InterfaceName' ${wgIf}
set_ Network PortForwardingEnabled false
# qBittorrent 5 reads these from [WebUI], drop the old keys
for k in Address Port HostHeaderValidation LocalHostAuth 'HTTPS\Enabled' 'HTTPS\CertificatePath' 'HTTPS\KeyPath'; do
crudini --del "$cfg" Preferences "WebUI\\$k"
done
set_ WebUI 'Address' 127.0.0.1
set_ WebUI 'Port' ${toString webuiPort}
set_ WebUI 'HostHeaderValidation' false
# Proxied clients appear as localhost, so they must not skip the login
set_ WebUI 'LocalHostAuth' true
set_ WebUI 'HTTPS\Enabled' true
set_ WebUI 'HTTPS\CertificatePath' ${certDir}/cert.pem
set_ WebUI 'HTTPS\KeyPath' ${certDir}/key.pem
'';
};
};
# Web interface on this host's localhost, proxied into the namespace
systemd.sockets.seedbox-webui = {
wantedBy = [ "sockets.target" ];
listenStreams = [ "127.0.0.1:${toString webuiProxyPort}" ];
listenStreams = [ (toString webuiPort) ];
};
systemd.services.seedbox-webui = netnsDeps // {
requires = [ "qbittorrent.service" ];
@@ -185,8 +206,6 @@ in
};
};
# Read-only share of the downloads on the local network, password protected and
# not announced anywhere
systemd.services.seedbox-share = {
description = "Seedbox downloads share";
wantedBy = [ "multi-user.target" ];
@@ -209,5 +228,8 @@ in
--addr :${toString sharePort} --read-only --dir-cache-time 15s
'';
};
networking.firewall.interfaces.eno1.allowedTCPPorts = [ sharePort ];
networking.firewall.interfaces.eno1.allowedTCPPorts = [
webuiPort
sharePort
];
}
+7
View File
@@ -27,9 +27,16 @@
"wireshark"
"podman"
"libvirtd"
"networkmanager"
];
};
# Steam Frame wireless adapter
modules.steam-frame = {
enable = true;
regulatoryDomain = "NL";
};
# Set up impermanence
modules.impermanence = {
enable = true;
+12
View File
@@ -8,6 +8,18 @@
modules.profiles.jan.enable = true;
# Open Beat Saber OneClick links on the Steam Frame
modules.beatsaber-oneclick = {
enable = true;
host = "steamos@frame.local";
};
# Larger text while the desktop is streamed to the Steam Frame
modules.steam-frame-desktop = {
enable = true;
streamingTextScale = 1.2;
};
# home.packages = with pkgs; [
# opencloud-desktop
# code-nautilus
@@ -0,0 +1,41 @@
{
lib,
config,
pkgs,
...
}:
with lib;
let
cfg = config.modules.beatsaber-oneclick;
in
{
options.modules.beatsaber-oneclick = {
enable = mkEnableOption "forwarding Beat Saber OneClick links to a Steam Frame";
host = mkOption {
type = types.str;
example = "steamos@frame.local";
description = "SSH destination of the Steam Frame. Needs key auth, as there is no terminal to ask for a password.";
};
};
config = mkIf cfg.enable {
# The schemes BSManager handles on the Frame. Registering them here makes
# browsers on this machine hand the links to the Frame.
xdg.desktopEntries.beatsaber-oneclick = {
name = "Beat Saber OneClick (Steam Frame)";
comment = "Install Beat Saber maps and playlists on the Steam Frame";
type = "Application";
exec = "${pkgs.beatsaber-oneclick}/bin/beatsaber-oneclick ${escapeShellArg cfg.host} %u";
terminal = false;
noDisplay = true;
mimeType = [
"x-scheme-handler/beatsaver"
"x-scheme-handler/bsplaylist"
"x-scheme-handler/web+bsmap"
"x-scheme-handler/modelsaber"
];
};
};
}
@@ -0,0 +1,61 @@
{
lib,
config,
pkgs,
...
}:
with lib;
let
cfg = config.modules.steam-frame-desktop;
log = "${config.xdg.dataHome}/Steam/logs/streaming_log.txt";
setScale = scale: "${pkgs.glib}/bin/gsettings set org.gnome.desktop.interface text-scaling-factor ${toString scale}";
# Follows Steam's streaming log, which marks when a desktop stream starts and stops
# (Remote Play "Connect" on the Frame, or the desktop view in PC VR)
watcher = pkgs.writeShellScript "steam-frame-desktop-scale" ''
${pkgs.coreutils}/bin/tail -n 0 -F ${escapeShellArg log} 2>/dev/null | while IFS= read -r line; do
case "$line" in
*">>> Starting desktop stream"*)
${setScale cfg.streamingTextScale} ;;
# Also reset when Steam restarts, in case it quit mid-stream
*">>> Stopped desktop stream"* | *"Client version:"*)
${setScale cfg.normalTextScale} ;;
esac
done
'';
in
{
options.modules.steam-frame-desktop = {
enable = mkEnableOption "larger text while the desktop is streamed to a Steam Frame";
streamingTextScale = mkOption {
type = types.float;
default = 1.44;
description = "GNOME text scaling factor while the desktop is being streamed.";
};
normalTextScale = mkOption {
type = types.float;
default = 1.0;
description = "GNOME text scaling factor otherwise.";
};
};
config = mkIf cfg.enable {
systemd.user.services.steam-frame-desktop-scale = {
Unit = {
Description = "Scale text up while the desktop is streamed to a Steam Frame";
PartOf = [ "graphical-session.target" ];
After = [ "graphical-session.target" ];
};
Service = {
ExecStart = "${watcher}";
Restart = "on-failure";
};
Install.WantedBy = [ "graphical-session.target" ];
};
};
}
-3
View File
@@ -16,8 +16,5 @@ in
systemd-boot.editor = false;
efi.canTouchEfiVariables = true;
};
# Initrd
boot.initrd.systemd.enable = true;
};
}
+100
View File
@@ -0,0 +1,100 @@
{
lib,
config,
pkgs,
...
}:
with lib;
let
cfg = config.modules.steam-frame;
kernel = config.boot.kernelPackages.kernel;
# Out-of-tree rtw89 driver, as the in-tree rtw89_8852cu driver needs Linux 7.0+,
# which ZFS does not support yet
rtw89 = pkgs.stdenv.mkDerivation {
pname = "rtw89-morrownr";
version = "0-unstable-2026-11-09-${kernel.version}";
src = pkgs.fetchFromGitHub {
owner = "morrownr";
repo = "rtw89";
rev = "f2ce66eda6277e5505d5914a8a08454440518702";
hash = "sha256-u2sJ/1tvDM6MloulU7l3w9eLCc2GZqOBebI7/eQbeC8=";
};
nativeBuildInputs = kernel.moduleBuildDependencies;
makeFlags = kernel.commonMakeFlags ++ [
"KDIR=${kernel.dev}/lib/modules/${kernel.modDirVersion}/build"
];
buildFlags = [ "modules" ];
# Install through Kbuild so the modules are signed (produces the .ko.cer files)
installPhase = ''
runHook preInstall
local flagsArray=()
concatTo flagsArray makeFlags
make "''${flagsArray[@]}" -C ${kernel.dev}/lib/modules/${kernel.modDirVersion}/build M=$PWD \
modules_install INSTALL_MOD_PATH=$out INSTALL_MOD_DIR=updates/rtw89
runHook postInstall
'';
meta.platforms = platforms.linux;
};
in
{
options.modules.steam-frame = {
enable = mkEnableOption "Steam Frame wireless streaming adapter";
regulatoryDomain = mkOption {
type = types.str;
description = "Country code to use for Wi-Fi, needed to unlock the 6 GHz band.";
};
};
config = mkIf cfg.enable {
# Driver for the adapter (Realtek RTL8832CU, 28de:2432)
# Firmware comes from linux-firmware (hardware.enableRedistributableFirmware)
boot.extraModulePackages = [ rtw89 ];
boot.extraModprobeConfig = ''
options cfg80211 ieee80211_regdom=${cfg.regulatoryDomain}
# The adapter tends to stall when it enters power saving
options rtw89_core_git disable_ps_mode=y
# Prevent the in-tree drivers from claiming the adapter
blacklist rtw89_core
blacklist rtw89_usb
blacklist rtw89_8852c
blacklist rtw89_8852cu
'';
# Never let the adapter doze. In power save the Frame (the access point) buffers
# traffic for the PC until it wakes up, which stalls streams towards the PC
# such as spectating. This overrides the global wifi.powersave for this driver only.
networking.networkmanager.settings."connection-steam-frame" = {
match-device = "driver:rtw89_8852cu_git";
"wifi.powersave" = 2;
};
# Udev rules for Valve devices
hardware.steam-hardware.enable = true;
# Streaming ports
networking.firewall = {
allowedTCPPorts = [ 27036 ];
allowedUDPPortRanges = [
{
from = 10400;
to = 10401;
}
{
from = 27031;
to = 27036;
}
];
};
environment.systemPackages = [ pkgs.iw ];
};
}
+82
View File
@@ -0,0 +1,82 @@
{
pkgs,
lib,
# Render node of the GPU the OpenXR runtime uses, for hybrid graphics laptops
# (e.g. "/dev/dri/by-path/pci-0000:01:00.0-render"). Only NVIDIA is supported.
nvidiaRenderNode ? null,
...
}:
# Google Chrome with WebXR over OpenXR. nixpkgs' Chromium sets checkout_openxr = false,
# so it is built without the OpenXR backend.
let
chrome = pkgs.google-chrome;
flags = [
"--enable-features=OpenXR"
# The broker reports the wrong pid to SteamVR, which then fails xrCreateInstance
"--disable-seccomp-filter-sandbox"
"--ozone-platform=wayland"
"--use-angle=gl"
]
++ lib.optionals (nvidiaRenderNode != null) [
# The compositor runs on the integrated GPU and can't import NVIDIA buffers,
# so the window is composited in software while WebGL and WebXR stay on NVIDIA
"--render-node-override=${nvidiaRenderNode}"
"--disable-gpu-compositing"
];
desktopItem = pkgs.makeDesktopItem {
name = "chrome-xr";
exec = "chrome-xr %U";
icon = "google-chrome";
desktopName = "Chrome XR";
genericName = "WebXR Browser";
comment = "Google Chrome with WebXR through OpenXR";
categories = [
"Network"
"WebBrowser"
];
mimeTypes = [
"text/html"
"x-scheme-handler/http"
"x-scheme-handler/https"
];
};
in
pkgs.symlinkJoin {
name = "chrome-xr-${chrome.version}";
paths = [
(pkgs.writeShellScriptBin "chrome-xr" ''
# SteamVR's vrclient.so needs these, which NixOS doesn't provide globally
export LD_LIBRARY_PATH=${
lib.makeLibraryPath [
pkgs.libuuid
pkgs.libglvnd
]
}''${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
${lib.optionalString (nvidiaRenderNode != null) ''
# Render on the NVIDIA GPU, which the OpenXR runtime also uses
export __NV_PRIME_RENDER_OFFLOAD=1
export __NV_PRIME_RENDER_OFFLOAD_PROVIDER=NVIDIA-G0
export __GLX_VENDOR_LIBRARY_NAME=nvidia
export __EGL_VENDOR_LIBRARY_FILENAMES=/run/opengl-driver/share/glvnd/egl_vendor.d/10_nvidia.json
export __VK_LAYER_NV_optimus=NVIDIA_only
''}
# Separate profile, as the seccomp sandbox is disabled
exec ${chrome}/bin/google-chrome-stable \
${lib.escapeShellArgs flags} \
--user-data-dir="''${XDG_CONFIG_HOME:-$HOME/.config}/chrome-xr" \
"$@"
'')
desktopItem
];
meta = chrome.meta // {
description = "Google Chrome with WebXR through OpenXR";
mainProgram = "chrome-xr";
};
}