diff --git a/modules/programs/anime-downloader.nix b/modules/programs/anime-downloader.nix new file mode 100644 index 000000000..8581ff705 --- /dev/null +++ b/modules/programs/anime-downloader.nix @@ -0,0 +1,71 @@ +{ + lib, + pkgs, + config, + ... +}: +let + inherit (lib) + mkIf + mkEnableOption + mkPackageOption + mkOption + ; + + cfg = config.programs.anime-downloader; + jsonFormat = pkgs.formats.json { }; +in +{ + meta.maintainers = with lib.hm.maintainers; [ aguirre-matteo ]; + options.programs.anime-downloader = { + enable = mkEnableOption "anime-downloader"; + package = mkPackageOption pkgs "anime-downloader" { nullable = true; }; + settings = mkOption { + inherit (jsonFormat) type; + default = { }; + example = { + dl = { + aria2c_for_torrents = false; + chunk_size = "10"; + download_dir = "."; + external_downloader = "{aria2}"; + fallback_qualities = [ + "720p" + "480p" + "360p" + ]; + file_format = "{anime_title}/{anime_title}_{ep_no}"; + force_download = false; + player = null; + provider = "twist.moe"; + quality = "1080p"; + skip_download = false; + url = false; + }; + }; + description = '' + Configuration settings for anime-downloader. All available options can be found here: + . + ''; + }; + }; + + config = + let + configDir = + if pkgs.stdenv.hostPlatform.isDarwin then + "Library/Application Support/anime downloader" + else + "${lib.removePrefix config.home.homeDirectory config.xdg.configHome}/anime-downloader"; + in + mkIf cfg.enable { + assertions = [ + (lib.hm.assertions.assertPlatform "programs.anime-downloader" pkgs lib.platforms.linux) + ]; + + home.packages = mkIf (cfg.package != null) [ cfg.package ]; + home.file."${configDir}/config.json" = mkIf (cfg.settings != { }) { + source = jsonFormat.generate "config.json" cfg.settings; + }; + }; +} diff --git a/tests/modules/programs/anime-downloader/config.json b/tests/modules/programs/anime-downloader/config.json new file mode 100644 index 000000000..76c18485f --- /dev/null +++ b/tests/modules/programs/anime-downloader/config.json @@ -0,0 +1,20 @@ +{ + "dl": { + "aria2c_for_torrents": false, + "chunk_size": "10", + "download_dir": ".", + "external_downloader": "{aria2}", + "fallback_qualities": [ + "720p", + "480p", + "360p" + ], + "file_format": "{anime_title}/{anime_title}_{ep_no}", + "force_download": false, + "player": null, + "provider": "twist.moe", + "quality": "1080p", + "skip_download": false, + "url": false + } +} diff --git a/tests/modules/programs/anime-downloader/default.nix b/tests/modules/programs/anime-downloader/default.nix new file mode 100644 index 000000000..a6bcbf204 --- /dev/null +++ b/tests/modules/programs/anime-downloader/default.nix @@ -0,0 +1,5 @@ +{ lib, pkgs, ... }: + +lib.optionalAttrs pkgs.stdenv.hostPlatform.isLinux { + anime-downloader-settings = ./settings.nix; +} diff --git a/tests/modules/programs/anime-downloader/settings.nix b/tests/modules/programs/anime-downloader/settings.nix new file mode 100644 index 000000000..a524185a2 --- /dev/null +++ b/tests/modules/programs/anime-downloader/settings.nix @@ -0,0 +1,46 @@ +{ + lib, + pkgs, + config, + ... +}: + +{ + programs.anime-downloader = { + enable = true; + settings = { + dl = { + aria2c_for_torrents = false; + chunk_size = "10"; + download_dir = "."; + external_downloader = "{aria2}"; + fallback_qualities = [ + "720p" + "480p" + "360p" + ]; + file_format = "{anime_title}/{anime_title}_{ep_no}"; + force_download = false; + player = null; + provider = "twist.moe"; + quality = "1080p"; + skip_download = false; + url = false; + }; + }; + }; + + nmt.script = + let + configDir = + if pkgs.stdenv.hostPlatform.isDarwin then + "Library/Application Support/anime downloader" + else + "${lib.removePrefix config.home.homeDirectory config.xdg.configHome}/anime-downloader"; + in + '' + assertFileExists "home-files/${configDir}/config.json" + assertFileContent "home-files/${configDir}/config.json" \ + ${./config.json} + ''; +}