All checks were successful
build / build (push) Successful in 2m46s
96 lines
2.8 KiB
Nix
96 lines
2.8 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 = "•";
|
|
};
|
|
blacklist.libraries = [
|
|
"episode"
|
|
"movie"
|
|
"book"
|
|
"audiobook"
|
|
"livetv"
|
|
];
|
|
};
|
|
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 =
|
|
let api-key-file = config.sops.secrets.jellyfin-rpc-api-key.path;
|
|
in {
|
|
Unit = {
|
|
After = [ "sops-nix.service" ];
|
|
Requires = [ "sops-nix.service" ];
|
|
X-Restart-Triggers = [ api-key-file ];
|
|
};
|
|
Install.WantedBy = [ "default.target" ];
|
|
Service = {
|
|
Type = "oneshot";
|
|
ExecStart =
|
|
pkgs.writeShellScript "jellyfin-rpc-configure" ''
|
|
dest=''${XDG_CONFIG_HOME:-$HOME/.config}/jellyfin-rpc/main.json
|
|
mkdir -p "$(dirname "$dest")"
|
|
umask 177
|
|
[[ -f "$dest" ]] && chmod 600 "$dest"
|
|
${lib.getExe pkgs.jq} \
|
|
< ${jellyfin-rpc-config-template} \
|
|
> "$dest" \
|
|
--rawfile api_key ${api-key-file} \
|
|
'.jellyfin.api_key = $api_key'
|
|
'';
|
|
};
|
|
};
|
|
|
|
systemd.user.services.jellyfin-rpc = {
|
|
Unit.Requires = [ "jellyfin-rpc-configure.service" ];
|
|
Unit.After = [ "jellyfin-rpc-configure.service" ];
|
|
Install.WantedBy = [ "default.target" ];
|
|
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.";
|
|
}];
|
|
};
|
|
}
|