2023-08-30 01:50:06 +00:00
# usage:
# - start a DM with a rando via
# - '+' -> 'start conversation'
# - add a user to your roster via
# - '+' -> 'start conversation' -> '+' (opens the "add contact" dialog)
# - this triggers a popup on the remote side asking them for confirmation
# - after the remote's confirmation there will be a local popup for you to allow them to add you to their roster
# - to make a call:
# - ensure the other party is in your roster
# - open a DM with the party
# - click the phone icon at top (only visible if other party is in your roster)
2023-09-21 19:40:12 +00:00
#
# dino can be autostarted on login -- useful to ensure that i always receive calls and notifications --
# but at present it has no "start in tray" type of option: it must render a window.
2023-10-07 00:58:11 +00:00
#
# outstanding bugs:
2024-04-02 04:57:11 +00:00
# - NAT holepunching burns CPU/NET when multiple interfaces are up
# - fix by just `ip link set ovpnd-xyz down`
# - setting `wg-home` down *seems* to be not necessary
# - characterized by UPnP/SOAP error 500/718 in wireshark
# - seems it asks router A to open a port mapping for an IP address which belongs to a different subnet...
2023-10-07 00:58:11 +00:00
# - mic is sometimes disabled at call start despite presenting as enabled
# - fix is to toggle it off -> on in the Dino UI
2023-10-07 08:27:35 +00:00
# - default mic gain is WAY TOO MUCH (heavily distorted)
2024-04-17 09:53:08 +00:00
# - on lappy/desktop, right-clicking the mic button allows to toggle audio devices, but impossible to trigger this on moby/touch screen!
2023-10-11 05:40:19 +00:00
# - TODO: see if Dino calls work better with `echo full > /sys/kernel/debug/sched/preempt`
2023-10-07 08:27:35 +00:00
#
# probably fixed:
2023-10-07 00:58:11 +00:00
# - once per 1-2 minutes dino will temporarily drop mic input:
2024-04-26 05:11:43 +00:00
# - `rtp-WARNING: plugin.vala:148: Warning in pipeline: Can't record audio fast enough
2023-10-07 00:58:11 +00:00
# - this was *partially* fixed by bumping the pipewire mic buffer to 2048 samples (from ~512)
2023-10-07 08:27:35 +00:00
# - this was further fixed by setting PULSE_LATENCY_MSEC=20.
# - possibly Dino should be updated internally: `info.rate / 100` -> `info.rate / 50`.
# - i think that affects the batching for echo cancellation, adaptive gain control, etc.
2024-04-16 20:50:00 +00:00
# - dino *should* be able to use Pipewire directly for calls instead of going through pulse, but had trouble achieving that in actuality
2023-10-07 01:30:45 +00:00
#
2024-04-02 04:57:11 +00:00
{ config , lib , pkgs , . . . }:
2023-09-21 19:40:12 +00:00
let
cfg = config . sane . programs . dino ;
in
2023-08-28 08:48:35 +00:00
{
2023-09-21 19:40:12 +00:00
sane . programs . dino = {
configOption = with lib ; mkOption {
default = { } ;
type = types . submodule {
options . autostart = mkOption {
type = types . bool ;
2023-12-14 01:57:32 +00:00
default = true ;
2023-09-21 19:40:12 +00:00
} ;
} ;
} ;
2024-04-26 05:11:43 +00:00
packageUnwrapped = ( pkgs . dino . override {
# XXX(2024/04/24): build without echo cancelation (i.e. force WITH_VOICE_PROCESSOR to be undefined).
# this means that if the other end of the call is on speaker phone, i'm liable to hear my own voice
# leave their speaker, enter their mic, and then return to me.
# the benefit is a >50% reduction in CPU use. insignificant on any modern PC; make-or-break on a low-power Pinephone.
webrtc-audio-processing = null ;
} ) . overrideAttrs ( upstream : {
2024-04-02 04:57:11 +00:00
# i'm updating experimentally to see if it improves call performance.
# i don't *think* this is actually necessary; i don't notice any difference.
2024-05-08 08:45:41 +00:00
version = " 0 . 4 . 3 - u n s t a b l e - 2 0 2 4 - 0 4 - 2 8 " ;
2024-04-02 04:57:11 +00:00
src = lib . warnIf ( lib . versionOlder " 0 . 4 . 3 " upstream . version ) " d i n o u p d a t e : s a f e t o r e m o v e s a n e p a t c h e s " pkgs . fetchFromGitHub {
owner = " d i n o " ;
repo = " d i n o " ;
2024-05-08 08:45:41 +00:00
rev = " 6 5 7 5 0 2 9 5 5 5 6 7 d d 5 3 8 e 5 6 f 3 0 0 e 0 7 5 c 7 d b 5 2 e 2 5 d 7 4 " ;
hash = " s h a 2 5 6 - S A p J y 9 F g x x L O B 5 A / z G t p d F Z t S q S i S 0 3 v g g R r C t e 1 t F E = " ;
2024-04-02 04:57:11 +00:00
} ;
2024-05-08 08:45:41 +00:00
# avoid double-application of upstreamed patches
# https://github.com/NixOS/nixpkgs/pull/309265
patches = [ ] ;
2024-04-02 04:57:11 +00:00
checkPhase = ''
runHook preCheck
./xmpp-vala-test
# ./signal-protocol-vala-test # doesn't exist anymore
runHook postCheck
'' ;
} ) ;
2024-01-23 14:12:52 +00:00
sandbox . method = " b w r a p " ;
2024-02-08 21:51:32 +00:00
sandbox . net = " c l e a r n e t " ;
2024-02-13 11:14:38 +00:00
sandbox . whitelistAudio = true ;
2024-02-13 11:58:12 +00:00
sandbox . whitelistDbus = [ " u s e r " ] ; # notifications
2024-02-13 11:14:38 +00:00
sandbox . whitelistDri = true ; #< not strictly necessary, but we need all the perf we can get on moby
2024-02-14 01:49:49 +00:00
sandbox . whitelistWayland = true ;
2024-02-15 00:49:24 +00:00
sandbox . extraHomePaths = [
" M u s i c "
2024-02-27 21:36:18 +00:00
" P i c t u r e s / a l b u m s "
" P i c t u r e s / c a t "
" P i c t u r e s / f r o m "
" P i c t u r e s / P h o t o s "
" P i c t u r e s / S c r e e n s h o t s "
2024-02-15 00:49:24 +00:00
" P i c t u r e s / s e r v o - m a c r o s "
2024-02-27 21:36:18 +00:00
" V i d e o s / l o c a l "
2024-02-15 00:49:24 +00:00
" V i d e o s / s e r v o "
" t m p "
] ;
2024-01-22 09:30:13 +00:00
2023-11-08 15:32:50 +00:00
persist . byStore . private = [ " . l o c a l / s h a r e / d i n o " ] ;
2023-09-21 19:40:12 +00:00
services . dino = {
2023-11-14 00:38:38 +00:00
description = " d i n o X M P P c l i e n t " ;
2024-03-21 16:02:06 +00:00
partOf = lib . mkIf cfg . config . autostart [ " g r a p h i c a l - s e s s i o n " ] ;
2024-02-19 12:57:44 +00:00
2024-03-21 05:13:48 +00:00
# audio buffering; see: <https://gitlab.freedesktop.org/pipewire/pipewire/-/wikis/FAQ#pipewire-buffering-explained>
# dino defaults to 10ms mic buffer, which causes underruns, which Dino handles *very* poorly
# as in, the other end of the call will just not receive sound from us for a couple seconds.
2024-04-25 11:28:22 +00:00
# pipewire uses power-of-two buffering for the mic itself (by default), but this env var supports only whole numbers, which isn't quite reconcilable:
# - 1024/48000 = 21.33ms
# - 2048/48000 = 42.67ms
# - 4096/48000 = 85.33ms
# also, Dino's likely still doing things in 10ms batches internally.
#
# note that this number supposedly is just the buffer size which Dino asks Pulse (pipewire) to share with it.
# in theory, it's equivalent to adjusting pipewire's quanta setting, and so isn't additive to the existing pipewire buffers.
# (and would also be overriden by pipewire's quanta.min setting).
# but in practice, setting this seems to have some more effect beyond just the buffer sizes visible in `pw-top`.
2024-03-21 05:13:48 +00:00
#
2024-04-02 09:02:44 +00:00
# further: decrease the "niceness" of dino, so that it can take precedence over anything else.
# ideally this would target just the audio processing, rather than the whole program.
# pipewire is the equivalent of `nice -n -21`, so probably don't want to go any more extreme than that.
2024-04-25 11:28:22 +00:00
# nice -n -15 chosen arbitrarily; not optimized (and seems to have very little impact in practice anyway).
# buffer size:
# - 1024 (PULSE_LATENCY_MSEC=20): `pw-top` shows several underruns per second.
2024-04-26 05:11:43 +00:00
# - 2048 (PULSE_LATENCY_MSEC=50): `pw-top` shows very few underruns: maybe 1-5 per minute. with voice processor disabled, this works well. with it enabled, i still get gaps in which the mic "disappears".
# - 4096 (PULSE_LATENCY_MSEC=100): `pw-top` shows 0 underruns. with voice processor disabled, i seem to be permanently muted. with it enabled, this works well.
2024-04-02 09:02:44 +00:00
#
2024-03-21 05:13:48 +00:00
# note that debug logging during calls produces so much journal spam that it pegs the CPU and causes dropped audio
# env G_MESSAGES_DEBUG = "all";
2024-04-26 05:11:43 +00:00
command = " e n v P U L S E _ L A T E N C Y _ M S E C = 5 0 n i c e - n - 1 5 d i n o " ;
2023-09-21 19:40:12 +00:00
} ;
} ;
2023-08-28 08:48:35 +00:00
}