feat(discord): jellyfin-rpc
This commit is contained in:
82
modules/home/discord/jellyfin-rpc.nix
Normal file
82
modules/home/discord/jellyfin-rpc.nix
Normal file
@@ -0,0 +1,82 @@
|
||||
{ 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.";
|
||||
}];
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user