Files
sydnix/modules/home/discord/jellyfin-rpc.nix
Madeleine Sydney Ślaga 550da5a27c
Some checks failed
build / build-sydpc (push) Successful in 42s
build / build-fruitbook (push) Failing after 3s
build / build-deertopia (push) Failing after 41s
feat(discord): jellyfin-rpc
2026-03-06 15:28:57 -07:00

83 lines
2.3 KiB
Nix

{ config, lib, pkgs, ... }:
let
cfg = config.sydnix.discord.jellyfin-rpc;
vesktop-wrapper =
pkgs.vesktop.overrideAttrs (finalAttrs: prevAttrs: {
postFixup = ''
${prevAttrs.postFixup or ""}
if [[ -e $out/bin/.vesktop-wrapped ]]; then
echo ".vesktop-wrapped already exists..."
exit 1
fi
mv $out/bin/vesktop $out/bin/.vesktop-wrapped
tee $out/bin/vesktop <<EOF
#!/usr/bin/env bash
systemctl start --user jellyfin-rpc
$out/bin/.vesktop-wrapped "\$@"
systemctl stop --user jellyfin-rpc
EOF
chmod +x $out/bin/vesktop
'';
});
jellyfin-rpc-config-template =
pkgs.writeText "jellyfin-rpc-config-template"
(lib.toJSON {
jellyfin = {
url = "https://watch.deertopia.net";
username = ["lain" "msyds"];
music = {
display = ["year" "album" "genres"];
separator = "-";
};
};
images = {
enable_images = true;
imgur_images = false;
};
});
in {
options.sydnix.discord.jellyfin-rpc = {
enable = lib.mkEnableOption "Jellyfin rich presence";
};
config = lib.mkIf cfg.enable {
systemd.user.services.jellyfin-rpc-configure = {
Service = {
Type = "oneshot";
ExecStart =
let
jq = lib.getExe pkgs.jq;
api-key-file = config.sops.secrets.jellyfin-rpc-api-key.path;
in pkgs.writeShellScript "jellyfin-rpc-configure" ''
dest=''${XDG_CONFIG_HOME:-$HOME/.config}/jellyfin-rpc/main.json
umask 177
[[ -f "$dest" ]] && chmod 600 "$dest"
jq < ${jellyfin-rpc-config-template} > "$dest" \
--rawfile api_key ${api-key-file} \
'.jellyfin.api_key = $api_key'
'';
};
};
systemd.user.services.jellyfin-rpc = {
Unit = {
After = ["jellyfin-rpc-configure"];
Wants = ["jellyfin-rpc-configure"];
};
Service = {
ExecStart = lib.getExe pkgs.jellyfin-rpc;
};
};
sydnix.sops.secrets.jellyfin-rpc-api-key = {};
programs.nixcord.vesktop.package = vesktop-wrapper;
assertions = [{
assertion = config.programs.nixcord.vesktop.enable;
message = "Jellyfin RPC requires Vesktop.";
}];
};
}