Declare a clan.core.vars.generators.cloudflare-tunnel generator that
prompts for the tunnel token on first run and stores it SOPS-encrypted
under vars/per-machine/sunken-ship/cloudflare-tunnel/tunnel-token.
systemd.services.cloudflare-tunnel ExecStart now reads the decrypted
secret at runtime from \${config.clan.core.vars...path} (lives at
/run/secrets/vars/...) instead of the unmanaged
/home/danny/.secrets/cloudflare-tunnel-token file.
Stage 4c of the clan migration. The tunnel itself is slated for
retirement in 4d — ZeroTier-only access after that. Cloudflare token
was rotated during this migration; old value no longer valid.
202 lines
7.8 KiB
Nix
202 lines
7.8 KiB
Nix
# NixOS server: hostname, user, SSH, auto-rebuild from dotfiles repo.
|
|
#
|
|
# One-time on server: clone repo to /etc/dotfiles (root needs git access).
|
|
# If private repo: use SSH (ssh:// or git@) and add root's key to GitHub, or use HTTPS + token.
|
|
# Then: sudo nixos-rebuild switch --flake /etc/dotfiles#sunken-ship
|
|
# If sudo git is not found: sudo nix run nixpkgs#git -- -C /etc/dotfiles pull origin main
|
|
# Timer runs every 15 min: git fetch, pull if origin/main changed, rebuild.
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
{
|
|
imports = [ ./sunken-ship-hardware.nix ];
|
|
|
|
networking.hostName = "sunken-ship";
|
|
# No networks defined => uses /etc/wpa_supplicant.conf on the server
|
|
networking.wireless.enable = true;
|
|
time.timeZone = "Europe/Copenhagen";
|
|
|
|
boot.kernelParams = [ "consoleblank=60" ]; # blank TTY after 60s to reduce burn-in
|
|
|
|
# Turn off panel backlight after boot so the screen actually dims (consoleblank only blanks framebuffer).
|
|
# At the console, run: brightnessctl set 100% (or `brightnessctl max`) to restore brightness.
|
|
systemd.services.server-backlight-off = {
|
|
description = "Turn off panel backlight after console idle (reduce burn-in)";
|
|
after = [ "multi-user.target" ];
|
|
wantedBy = [ "multi-user.target" ];
|
|
serviceConfig.Type = "oneshot";
|
|
script = ''
|
|
${pkgs.coreutils}/bin/sleep 65
|
|
for d in /sys/class/backlight/*; do
|
|
[ -f "$d/brightness" ] && echo 0 > "$d/brightness" 2>/dev/null || true
|
|
done
|
|
'';
|
|
};
|
|
|
|
nix.settings.experimental-features = [ "nix-command" "flakes" ];
|
|
programs.nix-ld.enable = true; # run dynamically linked binaries (e.g. Claude Code remote CLI)
|
|
system.stateVersion = "24.11";
|
|
|
|
users.users.danny = {
|
|
isNormalUser = true;
|
|
extraGroups = [ "wheel" "video" "audio" ]; # video: backlight; audio: sound devices
|
|
# SSH keys: push via scp, don't commit. NixOS does not manage authorized_keys so scp'd keys persist.
|
|
# Example: scp ~/.ssh/id_ed25519_sunken_ship.pub danny@server:/tmp/ then on server: mkdir -p ~/.ssh; cat /tmp/*.pub >> ~/.ssh/authorized_keys
|
|
};
|
|
|
|
# Key-only auth; no password or keyboard-interactive.
|
|
services.openssh = {
|
|
enable = true;
|
|
settings = {
|
|
PasswordAuthentication = false;
|
|
KbdInteractiveAuthentication = false;
|
|
};
|
|
# Optionally restrict to LAN: settings.ListenAddress = "10.0.0.1"; or similar.
|
|
};
|
|
|
|
# Passwordless sudo for wheel.
|
|
security.sudo.wheelNeedsPassword = false;
|
|
environment.systemPackages = with pkgs; [
|
|
git # clone/bootstrap and dotfiles-rebuild timer
|
|
brightnessctl # manual backlight; replaces removed `light` from nixpkgs
|
|
uxplay # AirPlay mirroring receiver
|
|
alsa-utils # aplay, amixer, arecord for audio debugging
|
|
cloudflared # Cloudflare Tunnel for external access
|
|
];
|
|
|
|
# Avahi (mDNS) — required for AirPlay discovery.
|
|
services.avahi = {
|
|
enable = true;
|
|
nssmdns4 = true;
|
|
publish = { enable = true; userServices = true; };
|
|
};
|
|
|
|
# Open firewall for AirPlay (mDNS + UxPlay default ports) + Navidrome.
|
|
networking.firewall = {
|
|
allowedTCPPorts = [ 7000 7001 7100 4533 ];
|
|
allowedUDPPorts = [ 5353 6000 6001 7011 ];
|
|
};
|
|
|
|
# Navidrome — self-hosted music streaming server (Subsonic API).
|
|
# Music library: /srv/music (bind-mounted from /home/danny/music).
|
|
# Web UI + Substreamer client on port 4533.
|
|
services.navidrome = {
|
|
enable = true;
|
|
settings = {
|
|
Address = "0.0.0.0";
|
|
Port = 4533;
|
|
MusicFolder = "/srv/music";
|
|
};
|
|
};
|
|
|
|
# Persist the bind mount so navidrome can read music outside ProtectHome.
|
|
fileSystems."/srv/music" = {
|
|
device = "/home/danny/music";
|
|
fsType = "none";
|
|
options = [ "bind" "ro" ];
|
|
};
|
|
|
|
# Cloudflare Tunnel — exposes services to the internet without port forwarding.
|
|
# Token managed as a clan var (see generator below); prompted interactively
|
|
# on first `clan vars generate` and stored SOPS-encrypted under vars/.
|
|
# Routes configured in Cloudflare Zero Trust dashboard:
|
|
# music.dannydannydanny.me → http://localhost:4533
|
|
# Scheduled for retirement in stage 4d — ZeroTier-only access after that.
|
|
clan.core.vars.generators.cloudflare-tunnel = {
|
|
files.tunnel-token = {
|
|
secret = true;
|
|
deploy = true;
|
|
owner = "danny";
|
|
};
|
|
prompts.tunnel-token = {
|
|
description = "Cloudflare Tunnel token (Zero Trust dashboard → Networks → Tunnels → your tunnel → refresh token)";
|
|
type = "hidden";
|
|
persist = true;
|
|
};
|
|
script = "cp $prompts/tunnel-token $out/tunnel-token";
|
|
};
|
|
|
|
systemd.services.cloudflare-tunnel = {
|
|
description = "Cloudflare Tunnel for sunken-ship";
|
|
after = [ "network-online.target" ];
|
|
wants = [ "network-online.target" ];
|
|
wantedBy = [ "multi-user.target" ];
|
|
serviceConfig = {
|
|
ExecStart = "/bin/sh -c '${pkgs.cloudflared}/bin/cloudflared tunnel --no-autoupdate run --token $(cat ${config.clan.core.vars.generators.cloudflare-tunnel.files.tunnel-token.path})'";
|
|
Restart = "on-failure";
|
|
RestartSec = 10;
|
|
User = "danny";
|
|
};
|
|
};
|
|
|
|
# UxPlay AirPlay receiver — audio-only, outputs directly to Scarlett Solo via ALSA.
|
|
# Runs as a system service (no PipeWire needed on a headless server).
|
|
systemd.services.uxplay = {
|
|
description = "UxPlay AirPlay receiver";
|
|
after = [ "network-online.target" "avahi-daemon.service" ];
|
|
wants = [ "network-online.target" "avahi-daemon.service" ];
|
|
wantedBy = [ "multi-user.target" ];
|
|
serviceConfig = {
|
|
ExecStart = ''${pkgs.uxplay}/bin/uxplay -n sunken-ship -p -vs 0 -as "audioconvert ! audioresample ! alsasink device=plughw:USB,0 buffer-time=200000"'';
|
|
Restart = "on-failure";
|
|
RestartSec = 5;
|
|
User = "danny";
|
|
SupplementaryGroups = [ "audio" ];
|
|
};
|
|
};
|
|
|
|
# BigBiggerBiggestBot — Telegram fitness tracker with Mini App.
|
|
# Code: https://github.com/DannyDannyDanny/bigbiggerbiggestbot cloned at /home/danny/tg_fitness_bot
|
|
# Bot token: ~danny/.secrets/bigbiggerbiggestbot
|
|
# Deployment: fitness-bot-pull timer below runs every 15 min, git pulls, restarts service on changes.
|
|
systemd.services.fitness-bot = let
|
|
pythonEnv = pkgs.python3.withPackages (ps: with ps; [
|
|
python-telegram-bot
|
|
python-dotenv
|
|
aiohttp
|
|
]);
|
|
in {
|
|
description = "BigBiggerBiggestBot Telegram fitness tracker";
|
|
after = [ "network-online.target" ];
|
|
wants = [ "network-online.target" ];
|
|
wantedBy = [ "multi-user.target" ];
|
|
path = [ pythonEnv pkgs.cloudflared ];
|
|
serviceConfig = {
|
|
WorkingDirectory = "/home/danny/tg_fitness_bot";
|
|
ExecStart = "${pythonEnv}/bin/python start.py";
|
|
Restart = "on-failure";
|
|
RestartSec = 10;
|
|
User = "danny";
|
|
};
|
|
};
|
|
|
|
# Pull fitness bot from GitHub and restart the service if the repo has new commits.
|
|
# Code lives at /home/danny/tg_fitness_bot (git clone of DannyDannyDanny/bigbiggerbiggestbot).
|
|
# workouts.db is gitignored — preserved across pulls.
|
|
systemd.services.fitness-bot-pull = {
|
|
description = "Pull fitness bot and restart service if repo changed";
|
|
path = with pkgs; [ git systemd ];
|
|
environment.GIT_CONFIG_COUNT = "1";
|
|
environment.GIT_CONFIG_KEY_0 = "safe.directory";
|
|
environment.GIT_CONFIG_VALUE_0 = "/home/danny/tg_fitness_bot";
|
|
script = ''
|
|
set -euo pipefail
|
|
cd /home/danny/tg_fitness_bot
|
|
git fetch origin
|
|
if [ "$(git rev-parse HEAD)" = "$(git rev-parse origin/main)" ]; then
|
|
exit 0
|
|
fi
|
|
git pull origin main
|
|
systemctl restart fitness-bot
|
|
'';
|
|
serviceConfig.Type = "oneshot";
|
|
};
|
|
|
|
systemd.timers.fitness-bot-pull = {
|
|
wantedBy = [ "timers.target" ];
|
|
timerConfig.OnCalendar = "*-*-* *:07/15:00"; # every 15 minutes, offset from dotfiles-rebuild
|
|
timerConfig.RandomizedDelaySec = "2min";
|
|
};
|
|
|
|
# Auto-rebuild service/timer + safe.directory provided by the
|
|
# shared dotfiles-rebuild NixOS module (see nixos/modules/dotfiles-rebuild.nix).
|
|
}
|