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-09-27 08:21:32 +01:00
|
|
|
|
# Default max-jobs = 56 × cores = all let a from-source build thrash 31G
|
|
|
|
|
|
# into a 10h livelock, taking routing down with it. Cap parallelism and
|
|
|
|
|
|
# fence builds in a cgroup so the kernel OOM-kills a compiler, not the LAN.
|
|
|
|
|
|
nix.settings.max-jobs = 8;
|
|
|
|
|
|
nix.settings.cores = 8;
|
|
|
|
|
|
nix.daemonCPUSchedPolicy = "batch";
|
|
|
|
|
|
systemd.services.nix-daemon.serviceConfig = {
|
|
|
|
|
|
MemoryHigh = "12G";
|
|
|
|
|
|
MemoryMax = "16G";
|
|
|
|
|
|
OOMPolicy = "continue"; # a killed build shouldn't stop the daemon
|
|
|
|
|
|
};
|
|
|
|
|
|
|
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-09-12 13:09:51 +01:00
|
|
|
|
# This host is the router (services/router.nix) but shipped without any
|
|
|
|
|
|
# way to see a packet, so "is that nftables rule actually matching?" was
|
|
|
|
|
|
# unanswerable. Counters tell you a rule fired; these tell you what it
|
|
|
|
|
|
# fired on.
|
|
|
|
|
|
tcpdump
|
|
|
|
|
|
conntrack-tools
|
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-08-27 14:32:39 +01:00
|
|
|
|
# Audible library -> /mnt/storage/torrents/audiobooks for Jellyfin.
|
|
|
|
|
|
# audible-cli pulls the .aaxc + voucher, AAXtoMP3 decrypts to m4b.
|
|
|
|
|
|
audible-cli
|
|
|
|
|
|
aaxtomp3
|
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
|
2026-04-15 10:25:36 +01:00
|
|
|
|
(pkgs.writeShellScriptBin "transcode-hevc" ''
|
2026-04-15 19:31:37 +01:00
|
|
|
|
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"
|
2026-04-15 10:25:36 +01:00
|
|
|
|
exec ${pkgs.bash}/bin/bash ${../scripts/transcode-hevc.sh} "$@"
|
|
|
|
|
|
'')
|
2026-07-28 20:32:43 +01:00
|
|
|
|
# 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" ''
|
2026-07-28 20:47:39 +01:00
|
|
|
|
# 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.
|
2026-07-28 20:32:43 +01:00
|
|
|
|
C=${pkgs.coreutils}/bin
|
|
|
|
|
|
export LC_ALL=C
|
|
|
|
|
|
prev_rx=""
|
2026-07-28 20:47:39 +01:00
|
|
|
|
${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
|
2026-07-28 20:32:43 +01:00
|
|
|
|
done
|
2026-07-28 20:47:39 +01:00
|
|
|
|
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
|
2026-07-28 20:32:43 +01:00
|
|
|
|
done
|
|
|
|
|
|
'')
|
2026-08-01 17:14:04 +01:00
|
|
|
|
# Instant-answer backend for the quickshell launcher on the desktops:
|
qs-ask: answer via Claude Code on the subscription, not an API key
No API key and no separate billing: qs-ask now shells out to `claude -p`,
which draws on the existing subscription already authenticated on this
host. The trade is latency — Claude Code boots a Node process per
question, ~6s measured against the raw API's ~1s — so the launcher now
races Wikipedia and Claude instead of chaining them. Wikipedia fills the
card in under a second and Claude supersedes it on arrival; chaining
would have left the card blank for six seconds on every question.
Isolation, verified: --safe-mode drops CLAUDE.md, skills, hooks, plugins
and MCP while leaving auth working, which matters for correctness and not
just speed — the global CLAUDE.md here asks for caveman-mode replies and
that would have leaked into answers. --no-session-persistence writes no
transcript, and a dedicated empty cwd keeps launcher questions out of any
project's history or auto-memory. Confirmed no project namespace, no
transcript and no memory write after a run.
Not --bare, which looks right and is a trap: its auth is strictly
ANTHROPIC_API_KEY, so it cannot use the subscription at all.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-01 17:34:50 +01:00
|
|
|
|
# `printf '%s' "question" | ssh mediaserver qs-ask`.
|
|
|
|
|
|
#
|
2026-09-17 17:49:24 +01:00
|
|
|
|
# Runs through Codex CLI using fred's ChatGPT subscription. Sign in on
|
|
|
|
|
|
# the server as fred with `codex login` once; no API key is needed.
|
|
|
|
|
|
# The launcher shows Wikipedia first and replaces it when this answers.
|
2026-08-01 17:14:04 +01:00
|
|
|
|
#
|
|
|
|
|
|
# Reads the question from stdin — passing it as an ssh argv element would
|
|
|
|
|
|
# send it through the remote shell for a second round of word splitting.
|
|
|
|
|
|
#
|
2026-09-17 17:49:24 +01:00
|
|
|
|
# Luna at low reasoning effort is enough for a short fact. The CLI runs
|
|
|
|
|
|
# read-only, without web search, shell access, user config, exec rules,
|
|
|
|
|
|
# or session persistence.
|
2026-08-01 17:14:04 +01:00
|
|
|
|
#
|
qs-ask: answer via Claude Code on the subscription, not an API key
No API key and no separate billing: qs-ask now shells out to `claude -p`,
which draws on the existing subscription already authenticated on this
host. The trade is latency — Claude Code boots a Node process per
question, ~6s measured against the raw API's ~1s — so the launcher now
races Wikipedia and Claude instead of chaining them. Wikipedia fills the
card in under a second and Claude supersedes it on arrival; chaining
would have left the card blank for six seconds on every question.
Isolation, verified: --safe-mode drops CLAUDE.md, skills, hooks, plugins
and MCP while leaving auth working, which matters for correctness and not
just speed — the global CLAUDE.md here asks for caveman-mode replies and
that would have leaked into answers. --no-session-persistence writes no
transcript, and a dedicated empty cwd keeps launcher questions out of any
project's history or auto-memory. Confirmed no project namespace, no
transcript and no memory write after a run.
Not --bare, which looks right and is a trap: its auth is strictly
ANTHROPIC_API_KEY, so it cannot use the subscription at all.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-01 17:34:50 +01:00
|
|
|
|
# STDOUT is the launcher's channel: the answer, or nothing at all if the
|
2026-09-17 17:49:24 +01:00
|
|
|
|
# call fails or the model doesn't know — silence means "keep Wikipedia".
|
|
|
|
|
|
# Reasons go to STDERR and the journal (`journalctl -t qs-ask`).
|
2026-08-01 17:14:04 +01:00
|
|
|
|
(pkgs.writeShellScriptBin "qs-ask" ''
|
2026-08-02 11:27:08 +01:00
|
|
|
|
# Every line carries this script's pid, because the launcher fires a
|
|
|
|
|
|
# fresh call per debounce and concurrent runs otherwise interleave with
|
|
|
|
|
|
# no way to pair a question with its outcome. The pid goes in the
|
|
|
|
|
|
# message text rather than through logger's --id: --id sets SYSLOG_PID,
|
|
|
|
|
|
# which journalctl does not display — it shows the pid of the logger
|
|
|
|
|
|
# process itself, a different number on every line.
|
|
|
|
|
|
log() {
|
|
|
|
|
|
printf 'qs-ask: %s\n' "$*" >&2
|
|
|
|
|
|
${pkgs.util-linux}/bin/logger -t qs-ask -- "[$$] $*"
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-08-01 17:14:04 +01:00
|
|
|
|
q=$(${pkgs.coreutils}/bin/cat)
|
2026-08-02 11:27:08 +01:00
|
|
|
|
[ -z "$q" ] && { log "no question on stdin"; exit 0; }
|
|
|
|
|
|
log "ask: $q"
|
2026-08-01 17:14:04 +01:00
|
|
|
|
|
2026-09-17 17:49:24 +01:00
|
|
|
|
# Keep repository instructions and project files out of this invocation.
|
qs-ask: answer via Claude Code on the subscription, not an API key
No API key and no separate billing: qs-ask now shells out to `claude -p`,
which draws on the existing subscription already authenticated on this
host. The trade is latency — Claude Code boots a Node process per
question, ~6s measured against the raw API's ~1s — so the launcher now
races Wikipedia and Claude instead of chaining them. Wikipedia fills the
card in under a second and Claude supersedes it on arrival; chaining
would have left the card blank for six seconds on every question.
Isolation, verified: --safe-mode drops CLAUDE.md, skills, hooks, plugins
and MCP while leaving auth working, which matters for correctness and not
just speed — the global CLAUDE.md here asks for caveman-mode replies and
that would have leaked into answers. --no-session-persistence writes no
transcript, and a dedicated empty cwd keeps launcher questions out of any
project's history or auto-memory. Confirmed no project namespace, no
transcript and no memory write after a run.
Not --bare, which looks right and is a trap: its auth is strictly
ANTHROPIC_API_KEY, so it cannot use the subscription at all.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-01 17:34:50 +01:00
|
|
|
|
work="$HOME/.cache/qs-ask"
|
2026-08-02 11:27:08 +01:00
|
|
|
|
${pkgs.coreutils}/bin/mkdir -p "$work" || { log "cannot create $work"; exit 0; }
|
|
|
|
|
|
cd "$work" || { log "cannot enter $work"; exit 0; }
|
2026-08-01 17:21:05 +01:00
|
|
|
|
|
2026-09-17 17:49:24 +01:00
|
|
|
|
ans=$(printf 'Answer the question in one or two short sentences, under 240 characters. Lead with the specific fact asked for, including units. The query is often bare keywords rather than a question ("shadow hunter knife classic wow"); treat that as a request for the key facts about that thing. No preamble, caveats, markdown, or follow-up offers. Do not use tools. Reply with exactly UNKNOWN only when you genuinely do not know, or the answer depends on live data you do not have.\n\nQuestion: %s\n' "$q" | \
|
|
|
|
|
|
${pkgs.coreutils}/bin/timeout 30s ${pkgs.codex}/bin/codex exec \
|
|
|
|
|
|
--model gpt-5.6-luna \
|
|
|
|
|
|
--config model_reasoning_effort=low \
|
|
|
|
|
|
--config web_search=disabled \
|
|
|
|
|
|
--disable shell_tool \
|
|
|
|
|
|
--sandbox read-only \
|
|
|
|
|
|
--skip-git-repo-check \
|
|
|
|
|
|
--ephemeral \
|
|
|
|
|
|
--ignore-user-config \
|
|
|
|
|
|
--ignore-rules \
|
|
|
|
|
|
- \
|
qs-ask: answer via Claude Code on the subscription, not an API key
No API key and no separate billing: qs-ask now shells out to `claude -p`,
which draws on the existing subscription already authenticated on this
host. The trade is latency — Claude Code boots a Node process per
question, ~6s measured against the raw API's ~1s — so the launcher now
races Wikipedia and Claude instead of chaining them. Wikipedia fills the
card in under a second and Claude supersedes it on arrival; chaining
would have left the card blank for six seconds on every question.
Isolation, verified: --safe-mode drops CLAUDE.md, skills, hooks, plugins
and MCP while leaving auth working, which matters for correctness and not
just speed — the global CLAUDE.md here asks for caveman-mode replies and
that would have leaked into answers. --no-session-persistence writes no
transcript, and a dedicated empty cwd keeps launcher questions out of any
project's history or auto-memory. Confirmed no project namespace, no
transcript and no memory write after a run.
Not --bare, which looks right and is a trap: its auth is strictly
ANTHROPIC_API_KEY, so it cannot use the subscription at all.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-01 17:34:50 +01:00
|
|
|
|
2>/dev/null) \
|
2026-09-17 17:49:24 +01:00
|
|
|
|
|| { log "codex exited non-zero (check 'codex login status' as fred)"; exit 0; }
|
2026-08-01 17:21:05 +01:00
|
|
|
|
|
qs-ask: answer via Claude Code on the subscription, not an API key
No API key and no separate billing: qs-ask now shells out to `claude -p`,
which draws on the existing subscription already authenticated on this
host. The trade is latency — Claude Code boots a Node process per
question, ~6s measured against the raw API's ~1s — so the launcher now
races Wikipedia and Claude instead of chaining them. Wikipedia fills the
card in under a second and Claude supersedes it on arrival; chaining
would have left the card blank for six seconds on every question.
Isolation, verified: --safe-mode drops CLAUDE.md, skills, hooks, plugins
and MCP while leaving auth working, which matters for correctness and not
just speed — the global CLAUDE.md here asks for caveman-mode replies and
that would have leaked into answers. --no-session-persistence writes no
transcript, and a dedicated empty cwd keeps launcher questions out of any
project's history or auto-memory. Confirmed no project namespace, no
transcript and no memory write after a run.
Not --bare, which looks right and is a trap: its auth is strictly
ANTHROPIC_API_KEY, so it cannot use the subscription at all.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-01 17:34:50 +01:00
|
|
|
|
ans=$(printf '%s' "$ans" | ${pkgs.coreutils}/bin/tr -d '\r' | ${pkgs.gnused}/bin/sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
|
2026-08-01 17:21:05 +01:00
|
|
|
|
|
|
|
|
|
|
case "$ans" in
|
2026-08-02 11:27:08 +01:00
|
|
|
|
"") log "empty answer"; exit 0 ;;
|
|
|
|
|
|
UNKNOWN*) log "model replied UNKNOWN"; exit 0 ;;
|
2026-08-01 17:21:05 +01:00
|
|
|
|
esac
|
2026-08-02 11:27:08 +01:00
|
|
|
|
log "ok: $ans"
|
2026-08-01 17:14:04 +01:00
|
|
|
|
printf '%s' "$ans"
|
|
|
|
|
|
'')
|
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
|
2026-05-22 09:27:10 +01:00
|
|
|
|
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-09-14 11:50:22 +01:00
|
|
|
|
# services/deployment.nix owns the 05:15 update and conditional reboot,
|
|
|
|
|
|
# using the same health-checked transaction as manual and router UI applies.
|
2026-05-19 17:10:17 +01:00
|
|
|
|
|
2026-06-11 10:00:02 +01:00
|
|
|
|
# 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;
|
2026-04-06 21:48:08 +01:00
|
|
|
|
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
|
|
|
|
}
|