bye ssh notify and hi buzz
This commit is contained in:
1 parent
9b79667d94
commit
f1d907a438
14 files changed
+85
-305
No files matched your search
Generated
+4
-4
@@ -2471,11 +2471,11 @@
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1789255361,
|
||||
"narHash": "sha256-u0N1zS2PjsP+Er73et2wWKqKjxbm2lUPA9mRmu8dfTM=",
|
||||
"lastModified": 1790000959,
|
||||
"narHash": "sha256-9fY+e5/Yi5r3yvvQzpmOnuGmeheam5RTLRlUvuAahYQ=",
|
||||
"ref": "refs/heads/main",
|
||||
"rev": "ed75fa0db90a6666165f0fb5d0441bdac21a8a1a",
|
||||
"revCount": 12,
|
||||
"rev": "d4684f337f2a7133a66e7ec2f36f4d6238166cd4",
|
||||
"revCount": 15,
|
||||
"type": "git",
|
||||
"url": "ssh://gitea@minipc1.lab.internal:22/ari/skygqts.git"
|
||||
},
|
||||
|
||||
@@ -62,10 +62,6 @@ in
|
||||
};
|
||||
};
|
||||
};
|
||||
common.ssh-notify = {
|
||||
enable = true;
|
||||
role = "client";
|
||||
};
|
||||
};
|
||||
networkDrives = {
|
||||
enable = false;
|
||||
|
||||
+78
-28
@@ -1,7 +1,6 @@
|
||||
{ config, ... }:
|
||||
let
|
||||
ports = {
|
||||
audiobookshelf = 8000;
|
||||
nixServe = 5000;
|
||||
dockerRegistry = 5001;
|
||||
postgresIU = 7491;
|
||||
@@ -18,16 +17,23 @@ let
|
||||
openPorts = [
|
||||
ports.nixServe
|
||||
ports.dockerRegistry
|
||||
ports.audiobookshelf
|
||||
gitea.sshPort
|
||||
gitea.httpPort
|
||||
ports.postgresIU
|
||||
ports.ssh
|
||||
ports.iu
|
||||
];
|
||||
# Audiobookshelf stack
|
||||
audiobookshelf = {
|
||||
domain = "audiobooks.app.internal";
|
||||
ip = "10.0.101.4";
|
||||
port = 80;
|
||||
image = "ghcr.io/advplyr/audiobookshelf:latest";
|
||||
dataDir = "/mnt/Data/audiobookshelf";
|
||||
};
|
||||
# Buzz stack
|
||||
buzz = {
|
||||
domain = "buzz.lab.internal";
|
||||
domain = "buzz.app.internal";
|
||||
port = 3000;
|
||||
ip = "10.0.101.3";
|
||||
bucket = "buzz-media";
|
||||
@@ -39,14 +45,15 @@ let
|
||||
mc = "quay.io/minio/mc:RELEASE.2025-08-13T08-35-41Z@sha256:a7fe349ef4bd8521fb8497f55c6042871b2ae640607cf99d9bede5e9bdf11727";
|
||||
};
|
||||
};
|
||||
# NFS-backed volume on tnas1 (repo pattern: compose volume with nfs driver_opts).
|
||||
# The server must be in `device` (the local driver uses it as the mount source);
|
||||
# `o = addr=...` alone is not honoured here.
|
||||
# NFS-backed volume on tnas1 (compose volume with nfs driver_opts).
|
||||
# Docker's `local` driver calls mount(2) itself, so it cannot resolve a
|
||||
# `host:/path` device: the server belongs in `o = addr=...` (the daemon
|
||||
# resolves that name) and `device` must be the bare `:/export/path`.
|
||||
nfsVolume = subpath: {
|
||||
driver_opts = {
|
||||
type = "nfs";
|
||||
o = "rw,nfsvers=4.0,nolock,hard,noatime";
|
||||
device = "tnas1.lab.internal:/mnt/SmallG/buzz/${subpath}";
|
||||
o = "addr=tnas1.lab.internal,rw,nfsvers=4.0,nolock,hard,noatime";
|
||||
device = ":/mnt/SmallG/buzz/${subpath}";
|
||||
};
|
||||
};
|
||||
in
|
||||
@@ -58,7 +65,7 @@ in
|
||||
openFirewall = true;
|
||||
addressesSecretName = "dns-addresses.conf";
|
||||
};
|
||||
skyg.nixos.common.containers.runtime = "podman";
|
||||
skyg.nixos.common.containers.runtime = "docker";
|
||||
skyg.nixos.common.containers.openMetricsPort = true;
|
||||
|
||||
# One shared macvlan network, created once at boot.
|
||||
@@ -89,14 +96,27 @@ in
|
||||
# firmware updater
|
||||
services.fwupd.enable = true;
|
||||
# # Services
|
||||
skyg.nixos.server.services = {
|
||||
audiobookshelf = {
|
||||
enable = false;
|
||||
host = "0.0.0.0";
|
||||
openFirewall = true;
|
||||
port = ports.audiobookshelf;
|
||||
configDir = "/mnt/Data/audiobookshelf/config";
|
||||
metadataDir = "/mnt/Data/audiobookshelf/metadata";
|
||||
# Audiobookshelf — containerised, own macvlan IP, reachable as
|
||||
# http://audiobooks.app.internal
|
||||
skyg.nixos.common.container-services.audiobookshelf = {
|
||||
enable = false;
|
||||
autoUpdate.enable = true;
|
||||
|
||||
networks.lan = config.skyg.nixos.common.containers.networks.lab.compose;
|
||||
|
||||
services.audiobookshelf = {
|
||||
image = audiobookshelf.image;
|
||||
networks.lan.ipv4_address = audiobookshelf.ip;
|
||||
dns.names = [ audiobookshelf.domain ];
|
||||
environment = {
|
||||
PORT = toString audiobookshelf.port;
|
||||
};
|
||||
volumes = [
|
||||
"${audiobookshelf.dataDir}/config:/config"
|
||||
"${audiobookshelf.dataDir}/metadata:/metadata"
|
||||
"${audiobookshelf.dataDir}/audiobooks:/audiobooks"
|
||||
"${audiobookshelf.dataDir}/podcasts:/podcasts"
|
||||
];
|
||||
};
|
||||
};
|
||||
services.dockerRegistry = {
|
||||
@@ -233,9 +253,7 @@ in
|
||||
};
|
||||
};
|
||||
|
||||
# Buzz — relay + postgres + redis + minio (S3). Reachable at
|
||||
# http://buzz.lab.internal:3000 on its own macvlan IP (10.0.101.3).
|
||||
# Data lives on tnas1 via NFS-backed compose volumes (/mnt/SmallG/buzz).
|
||||
# Buzz — relay + postgres + redis + minio (S3).
|
||||
age.secrets.buzz-env.file = ../secrets/buzz-env.age;
|
||||
skyg.nixos.common.container-services.buzz = {
|
||||
enable = true;
|
||||
@@ -257,11 +275,17 @@ in
|
||||
services = {
|
||||
relay = {
|
||||
image = buzz.images.relay;
|
||||
dependsOn = [ "postgres" "redis" "minio" ];
|
||||
extraConfig.depends_on = {
|
||||
postgres.condition = "service_healthy";
|
||||
redis.condition = "service_healthy";
|
||||
minio.condition = "service_healthy";
|
||||
minio-init.condition = "service_completed_successfully";
|
||||
};
|
||||
networks = {
|
||||
internal = { };
|
||||
lan = { ipv4_address = buzz.ip; };
|
||||
};
|
||||
dns.names = [ buzz.domain ];
|
||||
environmentFiles = [ config.age.secrets.buzz-env.path ];
|
||||
environment = {
|
||||
BUZZ_BIND_ADDR = "0.0.0.0:${toString buzz.port}";
|
||||
@@ -300,6 +324,7 @@ in
|
||||
environment = {
|
||||
POSTGRES_DB = "buzz";
|
||||
POSTGRES_USER = "buzz";
|
||||
PGDATA = "/var/lib/postgresql/data/pgdata";
|
||||
};
|
||||
volumes = [ "buzz-postgres:/var/lib/postgresql/data" ];
|
||||
healthcheck = {
|
||||
@@ -322,6 +347,14 @@ in
|
||||
exec redis-server --appendonly yes --requirepass "$REDIS_PASSWORD"
|
||||
'';
|
||||
command = [ "sh" "/usr/local/bin/redis-entrypoint.sh" ];
|
||||
healthcheck = {
|
||||
# $$ survives compose interpolation so the container shell expands it.
|
||||
test = [ "CMD-SHELL" ''redis-cli -a "$''${REDIS_PASSWORD}" ping | grep -q PONG'' ];
|
||||
interval = "5s";
|
||||
timeout = "3s";
|
||||
retries = 12;
|
||||
start_period = "5s";
|
||||
};
|
||||
};
|
||||
|
||||
minio = {
|
||||
@@ -332,10 +365,10 @@ in
|
||||
command = [ "server" "/data" "--console-address" ":9001" ];
|
||||
healthcheck = {
|
||||
test = [ "CMD" "curl" "-f" "http://127.0.0.1:9000/minio/health/live" ];
|
||||
interval = "30s";
|
||||
timeout = "10s";
|
||||
retries = 5;
|
||||
start_period = "20s";
|
||||
interval = "5s";
|
||||
timeout = "5s";
|
||||
retries = 12;
|
||||
start_period = "10s";
|
||||
};
|
||||
};
|
||||
|
||||
@@ -343,9 +376,26 @@ in
|
||||
image = buzz.images.mc;
|
||||
networks = [ "internal" ];
|
||||
environmentFiles = [ config.age.secrets.buzz-env.path ];
|
||||
command = [ "mb" "--ignore-existing" "local/${buzz.bucket}" ];
|
||||
dependsOn = [ "minio" ];
|
||||
restart = "on-failure";
|
||||
environment = {
|
||||
BUZZ_S3_BUCKET = buzz.bucket;
|
||||
};
|
||||
# The image ENTRYPOINT is ["mc"], so the upstream bootstrap sequence is
|
||||
# shipped as a script and the entrypoint is overridden to run it.
|
||||
files."/usr/local/bin/minio-init.sh" = ''
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
echo "setting alias"
|
||||
mc alias set local http://minio:9000 "$BUZZ_S3_ACCESS_KEY" "$BUZZ_S3_SECRET_KEY"
|
||||
echo "creating bucket"
|
||||
mc mb -p local/$BUZZ_S3_BUCKET
|
||||
echo "setting bucket permissions"
|
||||
mc anonymous set none local/$BUZZ_S3_BUCKET
|
||||
'';
|
||||
extraConfig = {
|
||||
entrypoint = [ "/bin/sh" "/usr/local/bin/minio-init.sh" ];
|
||||
depends_on.minio.condition = "service_healthy";
|
||||
};
|
||||
restart = "no";
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
@@ -21,8 +21,7 @@
|
||||
niri-touchscreen-gestures = final.callPackage ../../pkgs/niri-touchscreen-gestures { };
|
||||
# Buzz Desktop AppImage wrapper, see pkgs/buzz-desktop.
|
||||
buzz-desktop = final.callPackage ../../pkgs/buzz-desktop { };
|
||||
# Per-connection SSH notification forwarder, see pkgs/ssh-notify.
|
||||
ssh-notify = final.callPackage ../../pkgs/ssh-notify { };
|
||||
|
||||
# Claude Desktop (Linux), see pkgs/claude-desktop.
|
||||
claude-desktop = claude-desktop.packages.${final.stdenv.hostPlatform.system}.default;
|
||||
# herdr (herdrdev/herdr) — see flake.nix input.
|
||||
|
||||
@@ -15,7 +15,7 @@ common/
|
||||
├── user.nix # skyg.user.createSystemUser — creates the system user/groups + zsh shell
|
||||
├── fonts.nix # System font packages + fontconfig defaults (Fira Code, Noto, …); skyg.nixos.common.fonts.minimal
|
||||
├── ssh-server.nix # skyg.nixos.common.ssh-server — hardened sshd + master public keys (list)
|
||||
├── ssh-notify.nix # skyg.nixos.common.ssh-notify — forward notify-send from SSH sessions to a desktop client (RemoteForward scoped to *.lab.internal)
|
||||
|
||||
├── qemu.nix # skyg.core.qemu — QEMU/quickemu + SPICE guest tooling
|
||||
├── binary-cache.nix # skyg.nixos.common.cachePush — push finished builds to the bigbox2 cache
|
||||
├── containers/ # Docker vs Podman runtime selection + host-created container networks
|
||||
@@ -46,7 +46,7 @@ skyg.core.hostName → networking.nix
|
||||
skyg.user.createSystemUser → user.nix
|
||||
skyg.core.qemu.* → qemu.nix
|
||||
skyg.nixos.common.ssh-server.* → ssh-server.nix
|
||||
skyg.nixos.common.ssh-notify.* → ssh-notify.nix
|
||||
|
||||
skyg.nixos.common.cachePush.* → binary-cache.nix
|
||||
skyg.nixos.common.minimal → core.nix (skip heavy always-on system packages)
|
||||
skyg.nixos.common.nh.flake → core.nix (flake path for 'nh os' commands, set per host)
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
./user.nix
|
||||
./fonts.nix
|
||||
./ssh-server.nix
|
||||
./ssh-notify.nix
|
||||
./qemu.nix
|
||||
./binary-cache.nix
|
||||
./pritunl
|
||||
|
||||
@@ -1,95 +0,0 @@
|
||||
{ config, lib, pkgs, ... }:
|
||||
|
||||
let
|
||||
cfg = config.skyg.nixos.common.ssh-notify;
|
||||
|
||||
# Client-side listen socket. Fixed/shared is fine here: socat's `fork`
|
||||
# mode accepts unbounded connections over this path's lifetime, one per
|
||||
# `notify-send` call from any concurrently forwarded SSH session.
|
||||
#
|
||||
# NOTE: assumes a single interactive uid (1000) on the desktop host, same
|
||||
# as the rest of this single-user setup.
|
||||
localSocketPath = "/run/user/1000/ssh-notify/listener.sock";
|
||||
|
||||
# Remote-side (server) forwarded socket. Uses OpenSSH's %C token (hash of
|
||||
# local host/port/user + remote host/port/user, requires OpenSSH >= 8.9)
|
||||
# so each concurrent SSH connection gets its own bind path on the server —
|
||||
# this is what the old shared /tmp/ssh-notify.sock path got wrong: only
|
||||
# one concurrent session could ever bind it, and every other session's
|
||||
# `RemoteForward` silently failed ("remote port forwarding failed for
|
||||
# listen path ..."), falling back to a broken direct D-Bus notify-send.
|
||||
remoteSocketPath = "/tmp/ssh-notify-%C.sock";
|
||||
|
||||
# Detect if this host is acting as the notification client (the machine you sit in front of)
|
||||
isClient =
|
||||
cfg.role == "client"
|
||||
|| (cfg.role == "auto" && (config.skyg.nixos.desktop.enable or false));
|
||||
|
||||
isServer =
|
||||
cfg.role == "server"
|
||||
|| (cfg.role == "auto" && !isClient);
|
||||
in
|
||||
{
|
||||
options.skyg.nixos.common.ssh-notify = {
|
||||
enable = lib.mkEnableOption
|
||||
"forward libnotify messages from SSH sessions back to the client desktop (prefixed with hostname)";
|
||||
|
||||
role = lib.mkOption {
|
||||
type = lib.types.enum [ "auto" "client" "server" ];
|
||||
default = "auto";
|
||||
description = ''
|
||||
auto = client on hosts with skyg.nixos.desktop.enable, server otherwise
|
||||
client = force desktop listener + RemoteForward
|
||||
server = force wrapper only
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.mkIf cfg.enable {
|
||||
# hiPrio: desktop hosts (e.g. hl-fwdesk) also pull in the real libnotify
|
||||
# via the tiler module's "always-on plumbing" packages, and both provide
|
||||
# bin/notify-send. Force ours to win that collision unconditionally.
|
||||
environment.systemPackages = [ (lib.hiPrio pkgs.ssh-notify) ];
|
||||
|
||||
# Client: ask SSH to forward this connection's notification socket back
|
||||
# to the shared local listener, and tell the server-side wrapper (via
|
||||
# SetEnv, expanded here with the same %C the RemoteForward bind uses)
|
||||
# which socket to connect to.
|
||||
# Scoped to lab hosts: without the Match, every outbound ssh (GitHub,
|
||||
# work bastions, …) tries the forward, logs failures, and may leave a
|
||||
# socket behind on hosts that accept it.
|
||||
programs.ssh.extraConfig = lib.mkIf isClient ''
|
||||
Match host *.lab.internal
|
||||
RemoteForward ${remoteSocketPath} ${localSocketPath}
|
||||
SetEnv SSH_NOTIFY_SOCK=${remoteSocketPath}
|
||||
'';
|
||||
|
||||
# Server: accept the SSH_NOTIFY_SOCK env var forwarded by the client
|
||||
# above (SSH only passes through an allow-listed set by default).
|
||||
services.openssh.settings.AcceptEnv = lib.mkIf isServer [ "SSH_NOTIFY_SOCK" ];
|
||||
|
||||
# %C is a deterministic hash of (local host, remote user, remote host,
|
||||
# remote port) -- the same value every time you connect to this host
|
||||
# from this client, not a per-connection nonce. Without this, a socket
|
||||
# left behind by an abnormally-ended session (network drop, kill) blocks
|
||||
# every subsequent connection to the same host with "remote port
|
||||
# forwarding failed for listen path ...". Tell sshd to unlink and rebind
|
||||
# instead of refusing.
|
||||
services.openssh.settings.StreamLocalBindUnlink = lib.mkIf isServer true;
|
||||
|
||||
# Client listener: one persistent socket, forked per connection, that
|
||||
# turns each incoming JSON payload into a real local notification.
|
||||
systemd.user.services.ssh-notify-listener = lib.mkIf isClient {
|
||||
description = "Receive notify-send from remote hosts over SSH and display locally";
|
||||
after = [ "default.target" ];
|
||||
wantedBy = [ "default.target" ];
|
||||
serviceConfig = {
|
||||
ExecStart = "${pkgs.ssh-notify}/bin/ssh-notify-listener";
|
||||
Restart = "always";
|
||||
RestartSec = 2;
|
||||
};
|
||||
};
|
||||
|
||||
# On servers we rely purely on the wrapper; no extra services needed.
|
||||
};
|
||||
}
|
||||
@@ -16,10 +16,6 @@ in
|
||||
};
|
||||
};
|
||||
config = lib.mkIf cfg.enable {
|
||||
skyg.nixos.common.ssh-notify = {
|
||||
enable = true;
|
||||
role = "server";
|
||||
};
|
||||
services.openssh = {
|
||||
enable = true;
|
||||
openFirewall = true;
|
||||
|
||||
@@ -11,7 +11,6 @@ Packages here are exposed via an overlay defined in `modules/core/default.nix`.
|
||||
| `colibri/` | colibrì (`JustVugg/colibri`) — GLM-5.2/OLMoE local inference engine, built from source, pinned to a tagged release. Backend-parameterized (`backend = "cpu" \| "rocm"`). Exposed as `pkgs.colibri` (cpu, default), `pkgs.colibri-rocm` (Strix Halo / gfx1151). Installs the `coli` CLI (wrapped with the Python env its converter/bench subcommands need) plus the bundled `colibri`/`olmoe` engine binaries. Model weights are a runtime concern and not packaged. |
|
||||
| `niri-touchscreen-gestures/` | Python daemon that reads multi-touch events from a touchscreen via `evdev`, detects 2/3/4-finger swipes (up/down/left/right), and dispatches configurable `niri msg action` commands. Configured via TOML; exposed as `pkgs.niri-touchscreen-gestures`. |
|
||||
| `buzz-desktop/` | Block Buzz desktop (Type-2 AppImage from `block/buzz`). Wrapped with `appimageTools.wrapType2` plus extra FHS libs (`elfutils`, `zstd`, WebKit/tray, GStreamer good/bad) so it runs on NixOS. Exposed as `pkgs.buzz-desktop` (`buzz-desktop` binary + desktop entry / icons). |
|
||||
| `ssh-notify/` | Nushell scripts (socket I/O delegated to `socat`) that forward `notify-send` calls from SSH sessions back to the client desktop, one socket per concurrent connection. Exposed as `pkgs.ssh-notify` (`notify-send` server-side wrapper, `ssh-notify-listener` / `ssh-notify-handle-connection` client-side). Wired up by `modules/nixos/common/ssh-notify.nix`. |
|
||||
|
||||
## Adding a New Package
|
||||
|
||||
|
||||
@@ -1,77 +0,0 @@
|
||||
{ lib
|
||||
, stdenvNoCC
|
||||
, replaceVars
|
||||
, makeWrapper
|
||||
, nushell
|
||||
, socat
|
||||
, libnotify
|
||||
}:
|
||||
|
||||
# Forwards `notify-send` calls made in an SSH session back to a notification
|
||||
# daemon on the client desktop, instead of failing with
|
||||
# `GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown` (no daemon exists on
|
||||
# a headless host). Ties into `modules/nixos/common/ssh-notify.nix`, which
|
||||
# wires up the `RemoteForward`/`SetEnv` plumbing that gives each concurrent
|
||||
# SSH session its own per-connection socket on the server side.
|
||||
#
|
||||
# Three entry points, installed as separate binaries:
|
||||
# - `notify-send` -- server-side wrapper, shadows the real binary
|
||||
# - `ssh-notify-listener` -- client-side, one persistent listen socket
|
||||
# - `ssh-notify-handle-connection` -- client-side, one JSON payload per call
|
||||
#
|
||||
# The actual socket I/O is delegated to `socat`; the nushell scripts own the
|
||||
# typed payload encoding/decoding and control flow.
|
||||
|
||||
let
|
||||
realNotifySend = "${libnotify}/bin/notify-send";
|
||||
in
|
||||
stdenvNoCC.mkDerivation {
|
||||
pname = "ssh-notify";
|
||||
version = "0.1.0";
|
||||
|
||||
src = ./.;
|
||||
|
||||
nativeBuildInputs = [ makeWrapper ];
|
||||
|
||||
dontUnpack = true;
|
||||
dontBuild = true;
|
||||
|
||||
installPhase = ''
|
||||
runHook preInstall
|
||||
|
||||
mkdir -p $out/bin
|
||||
|
||||
install -m755 ${replaceVars ./notify-send.nu {
|
||||
real_notify_send = realNotifySend;
|
||||
}} $out/bin/.notify-send-wrapped.nu
|
||||
|
||||
install -m755 ${replaceVars ./ssh-notify-handle-connection.nu {
|
||||
real_notify_send = realNotifySend;
|
||||
}} $out/bin/ssh-notify-handle-connection.nu
|
||||
|
||||
install -m755 ${replaceVars ./ssh-notify-listener.nu {
|
||||
handle_connection = "$out/bin/ssh-notify-handle-connection.nu";
|
||||
}} $out/bin/.ssh-notify-listener-wrapped.nu
|
||||
|
||||
makeWrapper ${nushell}/bin/nu $out/bin/notify-send \
|
||||
--add-flags "$out/bin/.notify-send-wrapped.nu" \
|
||||
--prefix PATH : ${lib.makeBinPath [ socat ]}
|
||||
|
||||
makeWrapper ${nushell}/bin/nu $out/bin/ssh-notify-listener \
|
||||
--add-flags "$out/bin/.ssh-notify-listener-wrapped.nu" \
|
||||
--prefix PATH : ${lib.makeBinPath [ socat nushell ]}
|
||||
|
||||
chmod +x $out/bin/ssh-notify-handle-connection.nu
|
||||
|
||||
runHook postInstall
|
||||
'';
|
||||
|
||||
meta = {
|
||||
description = "Forwards notify-send from SSH sessions back to the client desktop, one socket per concurrent connection";
|
||||
homepage = "https://github.com/skykanin/nixos-setup";
|
||||
license = lib.licenses.mit;
|
||||
sourceProvenance = [ lib.sourceTypes.fromSource ];
|
||||
platforms = lib.platforms.linux;
|
||||
mainProgram = "notify-send";
|
||||
};
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
#!/usr/bin/env nu
|
||||
# Drop-in `notify-send` replacement.
|
||||
#
|
||||
# - Local session (no $SSH_CONNECTION): passes through to the real libnotify
|
||||
# `notify-send` unchanged.
|
||||
# - SSH session with a live per-connection forward ($SSH_NOTIFY_SOCK set by
|
||||
# the client's `SetEnv`, and the socket file present): encodes the message
|
||||
# as JSON and hands it to `socat` to relay over the forwarded Unix socket
|
||||
# to the listener on the client desktop.
|
||||
# - SSH session with no forward available (client didn't request one, or the
|
||||
# remote bind failed): no-op. There is no notification daemon to call on a
|
||||
# headless host, so falling through to the real binary would just reproduce
|
||||
# the `ServiceUnknown` D-Bus error this wrapper exists to avoid.
|
||||
#
|
||||
# @real_notify_send@ is substituted at build time with the libnotify binary's
|
||||
# store path.
|
||||
|
||||
def main [title: string, body: string = "", ...rest: string]: nothing -> nothing {
|
||||
let ssh_connection = ($env.SSH_CONNECTION? | default "")
|
||||
let notify_sock = ($env.SSH_NOTIFY_SOCK? | default "")
|
||||
|
||||
if ($ssh_connection | is-empty) {
|
||||
^@real_notify_send@ $title $body ...$rest
|
||||
return
|
||||
}
|
||||
|
||||
if ($notify_sock | is-empty) or (not ($notify_sock | path exists)) {
|
||||
return
|
||||
}
|
||||
|
||||
let host = (^hostname -s | str trim)
|
||||
let payload = { host: $host, title: $title, body: $body } | to json --raw
|
||||
|
||||
try {
|
||||
$payload | ^socat - $"UNIX-CONNECT:($notify_sock)"
|
||||
} catch {
|
||||
# Best-effort: a race where the forward closed between the exists
|
||||
# check and the connect attempt isn't worth surfacing to the caller.
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
#!/usr/bin/env nu
|
||||
# Invoked by `socat EXEC:` once per accepted connection on the listener
|
||||
# socket, with stdin/stdout wired to that connection. Reads the JSON payload
|
||||
# written by notify-send.nu and shows a real desktop notification.
|
||||
#
|
||||
# @real_notify_send@ is substituted at build time with the libnotify binary's
|
||||
# store path.
|
||||
|
||||
def main [] {
|
||||
let raw = (^cat | str trim)
|
||||
|
||||
if ($raw | is-empty) {
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
let payload = ($raw | from json)
|
||||
^@real_notify_send@ $"[($payload.host)] ($payload.title)" $payload.body
|
||||
} catch {
|
||||
# Malformed/partial payload (e.g. a stray connection) -- ignore.
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
#!/usr/bin/env nu
|
||||
# Client-side (desktop) listener. Runs one persistent `socat` listen socket
|
||||
# at a fixed, per-user path. This can stay fixed (unlike the per-connection
|
||||
# *remote*-side socket) because `fork` mode lets it accept an unbounded
|
||||
# number of connections over its lifetime -- one per `notify-send` call from
|
||||
# any concurrently forwarded SSH session.
|
||||
#
|
||||
# Each accepted connection is handed off to `ssh-notify-handle-connection`,
|
||||
# which reads one JSON payload and turns it into a real desktop notification.
|
||||
#
|
||||
# @handle_connection@ is substituted at build time with that script's store
|
||||
# path.
|
||||
|
||||
def main [] {
|
||||
let uid = (^id -u | str trim)
|
||||
let dir = $"/run/user/($uid)/ssh-notify"
|
||||
mkdir $dir
|
||||
let sock = $"($dir)/listener.sock"
|
||||
|
||||
# /run/user/<uid> is tmpfs and owned solely by this user, so unlike the
|
||||
# old shared /tmp path there's no cross-boot/cross-owner rm race here.
|
||||
rm -f $sock
|
||||
|
||||
^socat $"UNIX-LISTEN:($sock),fork,mode=0666" $"EXEC:@handle_connection@"
|
||||
}
|
||||
Binary file not shown.
Reference in new issue
Block a user