Compare commits

...
18 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
Jan-Bulthuis 4f3a25fa14 feat: beatsaber oneclick 2026-11-18 12:24:44 +01:00
Jan-Bulthuis 0c06237cac feat: seedbox setup 2026-11-18 12:24:18 +01:00
Jan-Bulthuis 2d6a7329ac fix: update helix-git 2026-11-18 12:24:02 +01:00
Jan-Bulthuis 02e738d0b4 chore: update flake 2026-11-18 12:23:27 +01:00
Jan-Bulthuis 9bcb89edac feat: vibed helix-git 2026-11-18 12:23:13 +01:00
Jan-Bulthuis 20fb312d40 chore: update flake 2026-11-09 22:13:41 +01:00
Jan-Bulthuis 12a61ac093 feat: git commit signing 2026-10-30 20:14:32 +01:00
Jan-Bulthuis d3c6f9b1d1 feat: setup attic 2026-10-28 15:03:17 +01:00
Jan-Bulthuis 9c07d9e047 feat: add thread support to HA 2026-10-23 03:51:20 +02:00
Jan-Bulthuis 0decd25b07 feat: add mobile app support to HA 2026-10-23 03:43:21 +02:00
19 changed files with 4774 additions and 30 deletions

No files matched your search

Generated
+25 -25
View File
@@ -7,11 +7,11 @@
]
},
"locked": {
"lastModified": 1781152676,
"narHash": "sha256-RxWs5ND31KzTG7wvMM+PMfUjyNpmIEr999lqNARaM5o=",
"lastModified": 1792526520,
"narHash": "sha256-3hSJlv8mUVnZPMWK2+CM7a9O+nR6Z4mCh27NfLCmTPc=",
"owner": "nix-community",
"repo": "disko",
"rev": "ff8702b4de27f72b4c78573dfb89ec74e36abdf1",
"rev": "cedd626e11b635470fa6f9fdb8ad79b0075dd7f9",
"type": "github"
},
"original": {
@@ -27,11 +27,11 @@
]
},
"locked": {
"lastModified": 1788355065,
"narHash": "sha256-gAz5oTI7ur34CfuakQduiQd/2ZhO62Bn2XXg08nZYYQ=",
"lastModified": 1794252721,
"narHash": "sha256-sD1rhEjMghSyWSUG2xEOw+FOVd2wnoWwi/809w8fRkI=",
"owner": "nix-community",
"repo": "home-manager",
"rev": "d9d750e4fc11c10cab2da677bdd31e427f3a3a71",
"rev": "f1db7c474bb49babfe9d8def532939e0c7404327",
"type": "github"
},
"original": {
@@ -67,11 +67,11 @@
"nixpkgs": "nixpkgs"
},
"locked": {
"lastModified": 1769548169,
"narHash": "sha256-03+JxvzmfwRu+5JafM0DLbxgHttOQZkUtDWBmeUkN8Y=",
"lastModified": 1792739756,
"narHash": "sha256-s0TeXWG5Ci75Y/Hzon0Z7NrN/fG773Rc54/z6oPFszQ=",
"owner": "nix-community",
"repo": "impermanence",
"rev": "7b1d382faf603b6d264f58627330f9faa5cba149",
"rev": "fa627f4c8b8e92f58f58a73d99ee4e1304e64eb2",
"type": "github"
},
"original": {
@@ -85,11 +85,11 @@
"nixpkgs": "nixpkgs_2"
},
"locked": {
"lastModified": 1791695179,
"narHash": "sha256-m4AV3cIczSMgWJpF85UhqCea5FilfvwrIJm5UwLZbmA=",
"lastModified": 1794202607,
"narHash": "sha256-foUWdIx5HTEopoOHXzTy7uhbZYYl1BdjZKPQpkR+pgg=",
"owner": "nix-community",
"repo": "nix-vscode-extensions",
"rev": "f91eac91132b84a439a04ff983aabafa039bedd6",
"rev": "934620178cf8eed2058484c24b5db62dbf4f08b1",
"type": "github"
},
"original": {
@@ -116,11 +116,11 @@
},
"nixpkgs-stable": {
"locked": {
"lastModified": 1788297115,
"narHash": "sha256-Z+vUNbfd2FIKkWOTkcT7RYlh3oFCnig/d2eXD1SWf2E=",
"lastModified": 1793865203,
"narHash": "sha256-/cpdPHaySDIyCgZI6EWngiM6jK3YLUNzv1b7lTzy6Bk=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "a3116115851d68b8952a2a4221cc25a84e56b532",
"rev": "c56a87d8e41ce69bd2af57eb35dcc117a9dfca33",
"type": "github"
},
"original": {
@@ -148,11 +148,11 @@
},
"nixpkgs_3": {
"locked": {
"lastModified": 1789785513,
"narHash": "sha256-B44WL6h0XoLjJ41bUPJk0X5SDinLCII//6EcBLXKiJ0=",
"lastModified": 1794042290,
"narHash": "sha256-ziZn2PvCJE5JEEpqTdxXwJpPB+L3YqoCpTAMCzyaP3U=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "20b1ddd1aa5ace70c9468305030aa4f9ef79671b",
"rev": "f4a03c008967841f2a0b3cb7c436fc6fc31671f6",
"type": "github"
},
"original": {
@@ -176,11 +176,11 @@
},
"secrets": {
"locked": {
"lastModified": 1766822527,
"narHash": "sha256-0qNxAxr7LQ8C6MjSxV2FkMSfdVmOVRq7Yz/wCea8plo=",
"lastModified": 1795002280,
"narHash": "sha256-PpeywbmyLrlliMSLvNCLT3L6Mmu5xHCGERrYuFIEM2s=",
"ref": "refs/heads/main",
"rev": "695e36891b5de248993845e1435df5e4116a26f2",
"revCount": 21,
"rev": "0b61e4b871c3bb33d25fdb5493a995dfef14f8e5",
"revCount": 24,
"type": "git",
"url": "ssh://gitea@git.bulthuis.dev/Jan/nixos-secrets"
},
@@ -196,11 +196,11 @@
]
},
"locked": {
"lastModified": 1789890976,
"narHash": "sha256-GKwH3zpy7tartuJMG0Rv/xUsdetG1QLmTVv8UKgJLmA=",
"lastModified": 1793995029,
"narHash": "sha256-ZlE4BtMjWhfC6rFXLO9Qimn36Ene1INqCgKDDvazjhc=",
"owner": "Mic92",
"repo": "sops-nix",
"rev": "7214124c20c1542c90deb54af50e2f53ae02711f",
"rev": "89a234ce2daf6e568a7d4b4fe250afdd23d84e20",
"type": "github"
},
"original": {
+33 -2
View File
@@ -1,4 +1,6 @@
{
config,
inputs,
...
}:
@@ -32,6 +34,7 @@
};
modules.impermanence.directories = [
"/var/lib/private/matterjs-server"
"/var/lib/private/atticd"
{
directory = "/var/lib/hass";
user = "hass";
@@ -41,6 +44,7 @@
];
systemd.tmpfiles.rules = [
"d /var/lib/private 0700 root root -"
"d /persist/system/var/lib/private 0700 root root -"
];
networking.firewall.allowedUDPPorts = [
5353 # mDNS
@@ -50,9 +54,15 @@
# Home Assistant
services.home-assistant = {
enable = true;
extraComponents = [ "matter" ];
extraComponents = [
"matter"
"mobile_app"
"otbr"
"thread"
];
config = {
homeassistant = { };
mobile_app = { };
http = {
use_x_forwarded_for = true;
# TODO: Narrow down to the address the internal gateway connects from
@@ -62,8 +72,29 @@
};
networking.firewall.allowedTCPPorts = [
8123 # Home Assistant
8080 # Attic
];
# Attic binary cache, served as cache.ib.baksteeninc.net behind the reverse proxy
sops.secrets."atticd/env".sopsFile = "${inputs.secrets}/secrets/ws-home.enc.yaml";
services.atticd = {
enable = true;
environmentFile = config.sops.secrets."atticd/env".path;
settings = {
listen = "[::]:8080";
api-endpoint = "https://cache.ib.baksteeninc.net/";
compression.type = "zstd";
garbage-collection = {
interval = "12 hours";
# Drop paths that have not been accessed for this long
default-retention-period = "3 months";
};
};
};
# Set up hardware
imports = [ ./hardware-configuration.nix ];
imports = [
./hardware-configuration.nix
./seedbox.nix
];
}
+235
View File
@@ -0,0 +1,235 @@
{
config,
inputs,
lib,
pkgs,
...
}:
# 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";
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";
user = config.services.qbittorrent.user;
group = config.services.qbittorrent.group;
inNetns = {
NetworkNamespacePath = "/run/netns/${netns}";
};
netnsDeps = {
bindsTo = [ "seedbox-netns.service" ];
partOf = [ "seedbox-netns.service" ];
after = [ "seedbox-netns.service" ];
};
in
{
sops.secrets = {
"seedbox/wireguard".sopsFile = secretFile;
"seedbox/port" = {
sopsFile = secretFile;
owner = user;
};
"seedbox/share-password" = {
sopsFile = secretFile;
owner = user;
};
};
modules.impermanence.directories = [
{
directory = dataDir;
inherit user group;
mode = "0750";
}
];
systemd.tmpfiles.rules = [ "d ${downloadsDir} 0750 ${user} ${group} -" ];
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
coreutils
];
serviceConfig = {
Type = "oneshot";
RemainAfterExit = true;
RuntimeDirectory = "seedbox";
RuntimeDirectoryPreserve = true;
};
script = ''
set -euo pipefail
conf=${secret "wireguard"}
field() { grep -iE "^\s*$1\s*=" "$conf" | cut -d= -f2- | tr ',' '\n' | sed 's/ //g'; }
ip netns del ${netns} 2>/dev/null || true
ip link del ${wgIf} 2>/dev/null || true
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} <(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}
done
mtu=$(field MTU | head -1)
ip -n ${netns} link set ${wgIf} mtu "''${mtu:-1420}" up
ip -n ${netns} route add default dev ${wgIf}
if field Address | grep -q ':'; then
ip -n ${netns} -6 route add default dev ${wgIf}
fi
# 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
'';
preStop = ''
ip netns del ${netns} || true
'';
};
services.qbittorrent = {
enable = true;
profileDir = dataDir;
inherit webuiPort;
extraArgs = [ "--confirm-legal-notice" ];
};
systemd.services.qbittorrent = netnsDeps // {
serviceConfig = inNetns // {
# nscd would bypass the tunnel's DNS
BindReadOnlyPaths = [
"/run/seedbox/resolv.conf:/etc/resolv.conf"
"/run/seedbox/nsswitch.conf:/etc/nsswitch.conf"
];
InaccessiblePaths = [ "-/run/nscd" ];
ReadWritePaths = [ dataDir ];
ExecStartPre = pkgs.writeShellScript "seedbox-config" ''
set -euo pipefail
PATH=${
lib.makeBinPath (
with pkgs;
[
coreutils
crudini
openssl
]
)
}
cfg=${dataDir}/qBittorrent/config/qBittorrent.conf
mkdir -p ${downloadsDir} "$(dirname "$cfg")"
set_() { crudini --ini-options=nospace --set "$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
'';
};
};
systemd.sockets.seedbox-webui = {
wantedBy = [ "sockets.target" ];
listenStreams = [ (toString webuiPort) ];
};
systemd.services.seedbox-webui = netnsDeps // {
requires = [ "qbittorrent.service" ];
after = [ "qbittorrent.service" ];
serviceConfig = inNetns // {
ExecStart = "${pkgs.systemd}/lib/systemd/systemd-socket-proxyd 127.0.0.1:${toString webuiPort}";
DynamicUser = true;
PrivateTmp = true;
};
};
systemd.services.seedbox-share = {
description = "Seedbox downloads share";
wantedBy = [ "multi-user.target" ];
after = [ "network-online.target" ];
wants = [ "network-online.target" ];
serviceConfig = {
User = user;
Group = group;
ProtectSystem = "strict";
ProtectHome = true;
PrivateTmp = true;
NoNewPrivileges = true;
ReadOnlyPaths = [ dataDir ];
};
script = ''
export RCLONE_USER=seedbox
RCLONE_PASS=$(cat ${secret "share-password"})
export RCLONE_PASS
exec ${lib.getExe pkgs.rclone} serve webdav ${downloadsDir} \
--addr :${toString sharePort} --read-only --dir-cache-time 15s
'';
};
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
+22
View File
@@ -28,6 +28,18 @@ in
default = [ ];
description = "Paths to globally ignore";
};
signingKey = mkOption {
type = types.nullOr types.str;
default = null;
description = "Path to the SSH public key used to sign commits and tags.";
};
allowedSigners = mkOption {
type = types.listOf types.str;
default = [ ];
description = "Trusted signers for verifying SSH signatures, as \"<email> <public key>\" lines.";
};
};
config = mkIf cfg.enable {
@@ -48,6 +60,16 @@ in
settings.user.name = cfg.user;
settings.user.email = cfg.email;
ignores = cfg.ignores;
signing = mkIf (cfg.signingKey != null) {
format = "ssh";
key = cfg.signingKey;
signByDefault = true; # commit.gpgsign and tag.gpgSign
};
settings.gpg.ssh.allowedSignersFile = mkIf (cfg.allowedSigners != [ ]) (
toString (pkgs.writeText "git-allowed-signers" (concatLines cfg.allowedSigners))
);
};
};
}
@@ -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 ];
};
}
@@ -0,0 +1,134 @@
# Forwards a Beat Saber OneClick link to the Steam Frame, where BSManager downloads it,
# and keeps a desktop notification up to date until the install is done.
# Usage: beatsaber-oneclick <ssh-host> <url>
# $remote_script (remote.sh) is set by the package.
host=${1:?usage: beatsaber-oneclick <ssh-host> <url>}
url=${2:?usage: beatsaber-oneclick <ssh-host> <url>}
api=https://api.beatsaver.com
# One notification, updated in place
notification_id=
notify() {
local id
if id=$(notify-send --print-id ${notification_id:+--replace-id="$notification_id"} \
--app-name="Beat Saber OneClick" --icon=input-gaming "$@"); then
notification_id=$id
fi
}
# Only forward the OneClick schemes, and only plain URL characters, since the URL
# ends up in a remote shell command line.
if [[ ! $url =~ ^(beatsaver|bsplaylist|web\+bsmap|modelsaber):// ]] ||
[[ ! $url =~ ^[A-Za-z0-9+.:/?#\&=%_~@!,\;-]+$ ]]; then
notify --urgency=critical "Not a OneClick link" "$url"
exit 1
fi
fetch() {
curl -sfL --max-time 20 "$@"
}
# Look up what the link installs, to know which map folders to watch for. If that
# fails, the link is still sent, just without tracking.
ids=()
label=$url
playlist=
case $url in
beatsaver://* | web+bsmap://*)
ref=${url#*://}
ref=${ref%%[/?#]*}
if [[ $url == beatsaver://* ]]; then
map=$(fetch "$api/maps/id/$ref") || map=
else
map=$(fetch "$api/maps/hash/$ref") || map=
fi
if [[ -n $map ]]; then
ids=("$(jq -r '.id | ascii_downcase' <<<"$map")")
label=$(jq -r '"\(.metadata.songName) – \(.metadata.levelAuthorName)"' <<<"$map")
fi
;;
bsplaylist://playlist/*)
playlist=1
label="Playlist"
if bplist=$(fetch "${url#bsplaylist://playlist/}"); then
label=$(jq -r '.playlistTitle // "Playlist"' <<<"$bplist")
# Entries with a key need no lookup; resolve the rest by hash, 50 at a time
mapfile -t ids < <(jq -r '.songs[] | .key // empty | ascii_downcase' <<<"$bplist")
mapfile -t hashes < <(jq -r '.songs[] | select(.key == null) | .hash // empty | ascii_downcase' <<<"$bplist")
for ((i = 0; i < ${#hashes[@]}; i += 50)); do
batch=$(
IFS=,
echo "${hashes[*]:i:50}"
)
if found=$(fetch "$api/maps/hash/$batch"); then
# A single hash returns the map itself instead of a hash → map object
mapfile -t -O "${#ids[@]}" ids < <(jq -r 'if has("id") then .id else (.[] | select(. != null) | .id) end | ascii_downcase' <<<"$found")
fi
done
fi
;;
esac
notify "Sending to Steam Frame…" "$label"
total=${#ids[@]}
done_count=0
new=0
already=0
missing=0
last_error=
stderr_file=$(mktemp)
trap 'rm -f "$stderr_file"' EXIT
exec {events}< <(ssh -T -o BatchMode=yes -o ConnectTimeout=5 "$host" \
bash -s -- "$(printf '%q' "$url")" "${ids[@]}" <"$remote_script" 2>"$stderr_file")
ssh_pid=$!
while IFS= read -r -u "$events" event; do
case $event in
received)
notify "Downloading on Steam Frame…" "$label"
;;
"done "*)
done_count=$((done_count + 1))
if ((total > 1)); then
notify "Downloading on Steam Frame… $done_count/$total" "$label"
fi
;;
"error "*)
last_error=${event#error }
;;
"result "*" new") new=$((new + 1)) ;;
"result "*" already") already=$((already + 1)) ;;
"result "*" missing") missing=$((missing + 1)) ;;
esac
done
if ! wait "$ssh_pid"; then
err=$(tr -d '\r' <"$stderr_file" | grep -v 'X11 forwarding' || true)
notify --urgency=critical "Couldn't send to Steam Frame" "${err:-ssh failed}"
exit 1
fi
failure_hint=${last_error:-BSManager didn\'t finish within 2 minutes. Check it on the Frame.}
if ((total == 0)); then
notify "Sent to Steam Frame" "$label"$'\n(Not tracked: couldn\'t look it up on BeatSaver.)'
elif [[ -z $playlist ]]; then
if ((new > 0)); then
notify "Installed on Steam Frame" "$label"
elif ((already > 0)); then
notify "Already on Steam Frame" "$label"
else
notify --urgency=critical "Not installed on Steam Frame" "$label"$'\n'"$failure_hint"
fi
else
summary="$label: $new new, $already already there"
if ((missing > 0)); then
notify --urgency=critical "Playlist partly installed on Steam Frame" \
"$summary, $missing failed"$'\n'"$failure_hint"
else
notify "Playlist installed on Steam Frame" "$summary"
fi
fi
+25
View File
@@ -0,0 +1,25 @@
{
writeShellApplication,
openssh,
libnotify,
curl,
jq,
}:
# Forwards Beat Saber OneClick links (BeatSaver, BeatLeader, ScoreSaber, playlists)
# to a Steam Frame over SSH and opens them there, so BSManager on the Frame does the
# download, and shows the install progress as a notification.
# Usage: beatsaber-oneclick <ssh-host> <url>
writeShellApplication {
name = "beatsaber-oneclick";
runtimeInputs = [
openssh
libnotify
curl
jq
];
text = ''
remote_script=${./remote.sh}
''
+ builtins.readFile ./beatsaber-oneclick.sh;
}
+186
View File
@@ -0,0 +1,186 @@
#!/usr/bin/env bash
# Runs on the Steam Frame (piped over SSH): opens a OneClick link in the graphical
# session, so the Frame's own handler (BSManager) downloads and installs it.
#
# Usage: remote.sh <url> [<beatsaver map id>...]
#
# With map ids, it then watches BSManager's log and map folders until those maps are
# installed, and reports on stdout, one event per line:
# received BSManager got the link
# downloading <id> BSManager started downloading a map
# done <id> the map's folder was (re)written and is complete
# error <message> BSManager logged an error (may be unrelated)
# result <id> new|already|missing
set -euo pipefail
url=$1
shift
ids=("$@")
uid=$(id -u)
# BSManager's default locations (installation folder not changed)
bsm=$HOME/.local/share/BSManager
logs=$HOME/.config/bs-manager/logs
# Give up when nothing has happened for this long (BSManager may need to start first)
timeout=120
# With maps that were already installed, finish once BSManager is quiet for this long
quiet=10
for id in "${ids[@]}"; do
if [[ ! $id =~ ^[0-9a-f]+$ ]]; then
echo "Invalid map id: $id" >&2
exit 1
fi
done
# An SSH session has no display. Borrow the display variables from a process in
# the graphical session, preferring the Steam client.
session_env() {
local pid env
for pid in $(pgrep -u "$uid" -x steam || true) $(pgrep -u "$uid"); do
env=$(tr '\0' '\n' <"/proc/$pid/environ" 2>/dev/null) || continue
if grep -qE '^(DISPLAY|WAYLAND_DISPLAY)=' <<<"$env"; then
printf '%s\n' "$env"
return 0
fi
done
return 1
}
if ! env=$(session_env); then
echo "No graphical session found on the Frame (is it signed in?)" >&2
exit 1
fi
while IFS= read -r line; do
export "${line?}"
done < <(grep -E '^(DISPLAY|WAYLAND_DISPLAY|XAUTHORITY|XDG_CURRENT_DESKTOP|XDG_SESSION_TYPE|DBUS_SESSION_BUS_ADDRESS)=' <<<"$env")
opener=
for candidate in gio xdg-open kde-open; do
if command -v "$candidate" >/dev/null; then
opener=$candidate
break
fi
done
if [[ -z $opener ]]; then
echo "No gio, xdg-open or kde-open on the Frame" >&2
exit 1
fi
open_cmd=("$opener")
[[ $opener == gio ]] && open_cmd+=(open)
map_dirs=("$bsm"/BSInstances/*/"Beat Saber_Data"/CustomLevels "$bsm"/SharedContent/SharedMaps/CustomLevels)
# Prints "<newest change time> <total size>" over a map's folders in all instances,
# or "none". Change time (not mtime), as extracting may keep the zip's mtimes.
map_state() {
local d f t s newest=0 size=0 found=
for d in "${map_dirs[@]}"; do
for f in "$d/$1 ("*; do
[[ -d $f ]] || continue
found=1
t=$(find "$f" -printf '%C@\n' | sort -n | tail -n1)
t=${t%.*}
((t > newest)) && newest=$t
s=$(du -sb "$f" | cut -f1)
size=$((size + s))
done
done
if [[ -n $found ]]; then echo "$newest $size"; else echo none; fi
}
# BSManager log lines written since we started. Continuation lines (stack traces)
# don't start with a timestamp and are left out.
log_since_start() {
find "$logs" -name '*.log' -newermt "@$start" -print0 2>/dev/null |
xargs -0r cat |
awk -v s="[$start_log" 'substr($0, 1, 20) >= s'
}
declare -A pre state prev
for id in "${ids[@]}"; do
pre[$id]=$(map_state "$id")
state[$id]=pending
prev[$id]=
done
start=$(date +%s)
start_log=$(date -d "@$start" '+%Y-%m-%d %H:%M:%S')
# gio comes first: xdg-open (generic mode) mangles the quoted path in BSManager's Exec line.
# Run it in its own scope, detached from this SSH session: if BSManager isn't running
# yet, the handler starts it, and it must outlive the connection. Output goes to the
# journal: journalctl --user -t beatsaber-oneclick
systemd-run --user --scope --collect --quiet \
setsid -f systemd-cat -t beatsaber-oneclick "${open_cmd[@]}" "$url" \
</dev/null >/dev/null 2>&1
((${#ids[@]} > 0)) || exit 0
received=
errors_seen=0
last_activity=$start
while :; do
sleep 1
now=$(date +%s)
lines=$(log_since_start)
if [[ -z $received ]] && grep -q 'DEEP-LINK RECEIVED' <<<"$lines"; then
received=1
last_activity=$now
echo received
fi
mapfile -t errors < <(grep -F '[error]' <<<"$lines" || true)
for err in "${errors[@]:errors_seen}"; do
echo "error ${err#*\[error\] }"
done
errors_seen=${#errors[@]}
waiting=0
all_done=1
for id in "${ids[@]}"; do
[[ ${state[$id]} == installed ]] && continue
all_done=
if [[ ${state[$id]} == pending ]] && grep -qF " $id https://" <<<"$lines"; then
state[$id]=downloading
last_activity=$now
echo "downloading $id"
fi
# Done once the folder changed since we started and stayed the same for a second
cur=$(map_state "$id")
if [[ $cur != none ]] && ((${cur%% *} >= start)); then
if [[ $cur == "${prev[$id]}" ]]; then
state[$id]=installed
last_activity=$now
echo "done $id"
continue
fi
prev[$id]=$cur
last_activity=$now
fi
# Maps that weren't installed yet, or are being downloaded, are worth waiting for
if [[ ${state[$id]} == downloading || ${pre[$id]} == none ]]; then
waiting=$((waiting + 1))
fi
done
[[ -n $all_done ]] && break
[[ -n $received ]] && ((waiting == 0 && now - last_activity >= quiet)) && break
((now - last_activity >= timeout)) && break
done
for id in "${ids[@]}"; do
if [[ ${state[$id]} == installed ]]; then
echo "result $id new"
elif [[ ${pre[$id]} != none ]]; then
echo "result $id already"
else
echo "result $id missing"
fi
done
+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";
};
}
+78
View File
@@ -0,0 +1,78 @@
{
lib,
fetchFromGitHub,
rustPlatform,
helix,
helix-unwrapped,
tree-sitter,
pkgs,
}:
# Helix from git, built with nixpkgs' packaging instead of the upstream flake. The
# flake fetches every tree-sitter grammar without a hash at evaluation time. Here
# they are pinned in grammars.json, so they are fetched once and kept in the store.
#
# To update: change rev and hash, set cargoHash to lib.fakeHash, build and copy the
# expected hash, then run ./update-grammars.sh.
let
lockedGrammars = lib.importJSON ./grammars.json;
unwrapped = helix-unwrapped.overrideAttrs (
final: prev: {
version = "25.07.1-unstable-${final.src.rev}";
src = fetchFromGitHub {
owner = "helix-editor";
repo = "helix";
rev = "f6f3eb1fe4a73933466f30175843059a4381a985";
hash = "sha256-yfNBfV6HWAQU/xZXwrFoedsSYsDmCDIlTHRxAZI6teY=";
};
cargoDeps = rustPlatform.fetchCargoVendor {
inherit (final) src pname version;
hash = "sha256-oo59HhwOS3EeV/YI+NWirEkdzD9pzMot2lgphZeOxfc=";
};
# The mdbook 0.5 patch from nixpkgs targets the release
patches = [ ];
# Report the commit in `hx --version`
env = prev.env // {
HELIX_NIX_BUILD_REV = final.src.rev;
};
# The version check expects the release version string
doInstallCheck = false;
}
);
in
(helix.override {
helix-unwrapped = unwrapped;
inherit lockedGrammars;
grammarsOverlay = lib.composeManyExtensions [
# Keep nixpkgs' fixes for its pinned grammars
helix.defaultGrammarsOverlay
(final: prev: {
# The tree-sitter.json fix is already included upstream
tree-sitter-tlaplus = prev.tree-sitter-tlaplus.overrideAttrs { patches = [ ]; };
})
# Grammars Helix uses that nixpkgs doesn't package yet
(
final: prev:
lib.mapAttrs' (
name: grammar:
lib.nameValuePair "tree-sitter-${name}" (
lib.makeOverridable tree-sitter.buildGrammar {
language = name;
version = lib.sources.shortRev grammar.nurl.args.rev;
src = pkgs.${grammar.nurl.fetcher} grammar.nurl.args;
location = grammar.subpath;
}
)
) (lib.filterAttrs (name: _: !(prev ? "tree-sitter-${name}")) lockedGrammars)
)
];
}).overrideAttrs
{ passthru.unwrapped = unwrapped; }
+79
View File
@@ -0,0 +1,79 @@
"""
Lock the tree-sitter grammars of a Helix languages.toml into grammars.json, in the
format nixpkgs' helix package takes as `lockedGrammars`.
Based on nixpkgs' pkgs/by-name/he/helix/generate_grammars.py, but each fetch gets a
timeout and falls back to fetching over git. Some forges (e.g. Codeberg) can hang
while generating archives.
Usage: generate-grammars.py <languages.toml> <grammars.json>
"""
import asyncio
import json
import os
import sys
import tomllib
TIMEOUT = 120
async def nurl(url, rev, *extra):
proc = await asyncio.create_subprocess_exec(
"nurl", *extra, url, rev, "--json",
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
)
try:
stdout, stderr = await asyncio.wait_for(proc.communicate(), TIMEOUT)
except asyncio.TimeoutError:
proc.kill()
await proc.wait()
raise RuntimeError(f"timed out after {TIMEOUT}s")
if proc.returncode != 0:
raise RuntimeError(stderr.decode().strip())
return json.loads(stdout)
async def lock(grammar, semaphore):
source = grammar["source"]
async with semaphore:
try:
result = await nurl(source["git"], source["rev"])
except RuntimeError as e:
print(f" {grammar['name']}: {e}, retrying over git", file=sys.stderr)
result = await nurl(source["git"], source["rev"], "-f", "fetchgit")
print(f" locked {grammar['name']}", file=sys.stderr)
return grammar["name"].replace("_", "-"), {
"nurl": result,
"subpath": source.get("subpath"),
}
async def main(languages_toml, output):
with open(languages_toml, "rb") as f:
grammars = [
g
for g in tomllib.load(f).get("grammar", [])
if "git" in g.get("source", {}) and "rev" in g["source"]
]
print(f"Locking {len(grammars)} grammars", file=sys.stderr)
semaphore = asyncio.Semaphore(os.cpu_count() or 4)
results = await asyncio.gather(
*(lock(g, semaphore) for g in grammars), return_exceptions=True
)
failed = [(g["name"], r) for g, r in zip(grammars, results) if isinstance(r, Exception)]
if failed:
for name, error in failed:
print(f"failed: {name}: {error}", file=sys.stderr)
sys.exit(1)
with open(output, "w") as f:
json.dump(dict(sorted(results)), f, indent=2)
f.write("\n")
if __name__ == "__main__":
asyncio.run(main(*sys.argv[1:3]))
File diff suppressed because it is too large. Load diff
+11
View File
@@ -0,0 +1,11 @@
#!/usr/bin/env bash
# Regenerate grammars.json for the Helix revision pinned in default.nix
set -euo pipefail
dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
flake="$(git -C "$dir" rev-parse --show-toplevel)"
src="$(nix build --no-link --print-out-paths "$flake#helix-git.unwrapped.src")"
nix shell --inputs-from "$flake" nixpkgs#nurl nixpkgs#nix-prefetch-git nixpkgs#python3 -c \
python3 -I "$dir/generate-grammars.py" "$src/languages.toml" "$dir/grammars.json"
+4
View File
@@ -264,6 +264,10 @@ in
enable = true;
user = "Jan-Bulthuis";
email = "git@bulthuis.dev";
signingKey = "${config.home.homeDirectory}/.ssh/id_ed25519.pub";
allowedSigners = [
"git@bulthuis.dev ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKKxoQSxfYqf9ITN8Fhckk8WbY4dwtBAXOhC9jxihJvq"
];
# TODO: Move
ignores = [
".envrc"