2026-08-11 14:00:29 +03:00

62 lines
1.4 KiB
Nix

{ config, pkgs, inputs, lib, hostname, username, ... }:
let
mpv-service-script = pkgs.writeShellScriptBin "mpv-service" ''
#!/bin/sh -eu
SOCKET_PATH="/tmp/mpv-${USER}.sock"
rm -f "''${SOCKET_PATH}"
cleanup() {
echo "Stopping MPV service..."
rm -f "''${SOCKET_PATH}"
pkill -P $$ mpv || true
}
trap cleanup EXIT TERM INT
exec ${pkgs.mpv}/bin/mpv \
--really-quiet \
--idle \
--no-video --force-window=no \
--input-ipc-server="''${SOCKET_PATH}" \
--demuxer-max-bytes=50MiB \
--demuxer-max-back-bytes=10MiB \
--audio-buffer=0.5
'';
in {
systemd.user.services.mpv-service = {
enable = true;
description = "MPV Audio Player Service with IPC";
documentation = [ "man:mpv(1)" ];
wantedBy = [ "default.target" ];
after = [ "sound.target" ];
wants = [ "sound.target" ];
serviceConfig = {
Type = "simple";
ExecStart = "${mpv-service-script}/bin/mpv-service";
Restart = "on-failure";
RestartSec = "5";
Environment = [
"DBUS_SESSION_BUS_ADDRESS=unix:path=%t/bus"
"XDG_RUNTIME_DIR=%t"
];
StandardOutput = "journal";
StandardError = "journal";
PrivateTmp = false;
ProtectSystem = "strict";
ProtectHome = "read-only";
NoNewPrivileges = true;
};
environment = {
MPV_SOCKET = "/tmp/mpv-${username}.sock";
};
};
}