From c61223b4daf6ecabfd92464abb926788da00fb1d Mon Sep 17 00:00:00 2001 From: sajenim Date: Fri, 1 Dec 2023 05:50:10 +0800 Subject: [PATCH] create initial jellyfin-rpc module --- modules/home-manager/default.nix | 1 + modules/home-manager/jellyfin-rpc.nix | 98 +++++++++++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 modules/home-manager/jellyfin-rpc.nix diff --git a/modules/home-manager/default.nix b/modules/home-manager/default.nix index e41f7d9..604d020 100644 --- a/modules/home-manager/default.nix +++ b/modules/home-manager/default.nix @@ -4,4 +4,5 @@ { # List your module files here # my-module = import ./my-module.nix; + jellyfin-rpc = import ./jellyfin-rpc.nix; } diff --git a/modules/home-manager/jellyfin-rpc.nix b/modules/home-manager/jellyfin-rpc.nix new file mode 100644 index 0000000..bcd0f33 --- /dev/null +++ b/modules/home-manager/jellyfin-rpc.nix @@ -0,0 +1,98 @@ +{ lib, pkgs, config, ... }: +with lib; +let + cfg = config.services.jellyfin-rpc; +in { + options.services.jellyfin-rpc = { + enable = mkEnableOption "jellyfin-rpc service"; + jellyfin.url = mkOption { + type = types.str; + default = "https://example.com"; + description = '' + Url to jellyfin server. + ''; + }; + jellyfin.apiKey = mkOption { + type = types.str; + default = "sadasodsapasdskd"; + description = '' + Jellyfin API key, you can get one at http(s)://your_jellyfin_url/web/#!/apikeys.html + ''; + }; + jellyfin.username = mkOption { + type = types.str; + default = "my_user"; + description = '' + Username used to log in to jellyfin. + ''; + }; + discordApplicationID = mkOption { + type = types.str; + default = "1053747938519679018"; + description = '' + Discord application ID, you can make one here https://discord.com/developers/applications + ''; + }; + imgurClientID = mkOption { + type = types.str; + default = "asdjdjdg394209fdjs093"; + description = '' + Imgur Client ID, goto https://api.imgur.com/oauth2/addclient + ''; + }; + package = mkOption { + type = types.package; + default = pkgs.jellyfin-rpc; + defaultText = literalExpression "pkgs.jellyfin-rpc"; + example = literalExpression "pkgs.jellyfin-rpc"; + description = '' + Jellyfin-RPC derivation to use. + ''; + }; + }; + + config = mkIf cfg.enable { + home.packages = [ cfg.package ]; + xdg.configFile."jellyfin-rpc/main.json".text = '' + { + "jellyfin": { + "url": "${cfg.jellyfin.url}", + "api_key": "${cfg.jellyfin.apiKey}", + "username": ["${cfg.jellyfin.username}"], + "music": { + "display": ["year", "album"] + } + }, + "discord": { + "application_id": "${cfg.discordApplicationID}" + }, + "imgur": { + "client_id": "${cfg.imgurClientID}" + }, + "images": { + "enable_images": true, + "imgur_images": true + } + } + ''; + systemd.user.services.jellyfin-rpc = { + Unit = { + Description = "Jellyfin-RPC"; + }; + + Install = { WantedBy = [ "multi-user.target" ]; }; + + Service = { + ExecStart = concatStringsSep " " ([ + "${getExe cfg.package}" + "--config ${config.xdg.configFile."jellyfin-rpc/main.json".source}" + ]); + Restart = "always"; + RestartSec = 3; + }; + }; + }; + + meta.maintainers = with lib.maintainers; [ sajenim ]; +} +