From 28492044122aaae385835c51a2a0a2f8ac7e8376 Mon Sep 17 00:00:00 2001 From: xenofem Date: Fri, 3 Mar 2023 23:12:20 -0500 Subject: [PATCH] mpv anime module --- flake.nix | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 flake.nix diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..3bbfa5b --- /dev/null +++ b/flake.nix @@ -0,0 +1,98 @@ +{ + description = "MPV overlay with scripts and configuration for watching anime"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + utils.url = "github:numtide/flake-utils"; + }; + + outputs = { self, nixpkgs, utils }: utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { inherit system; }; + mpvScript = { owner, repo, rev, sha256, scriptName }: pkgs.stdenvNoCC.mkDerivation { + pname = repo; + version = builtins.substring 0 6 rev; + src = pkgs.fetchFromGitHub { + inherit owner repo rev sha256; + }; + dontBuild = true; + installPhase = '' + install -Dm644 ${scriptName} $out/share/mpv/scripts/${scriptName} + ''; + passthru = { inherit scriptName; }; + }; + in rec { + packages.mpvScripts.sub-select = mpvScript { + owner = "CogentRedTester"; + repo = "mpv-sub-select"; + rev = "5d2fb7ab73fc0e36d44109e75c9be26bd42084e2"; + sha256 = "0dyh2kyvivj81lrkyqhc3czmi9hqjkh7xg8dqjnnr3kh3yn62dpi"; + scriptName = "sub-select.lua"; + }; + + packages.mpvScripts.segment-linking = mpvScript { + owner = "CogentRedTester"; + repo = "mpv-segment-linking"; + rev = "bb0fdb7961859df57c64b42d75dbbd60a4024e97"; + sha256 = "1ykl24p96wwka4fillrzni6i0xkk4s2l9zg1scqypcbs5w491qsj"; + scriptName = "segment-linking.lua"; + }; + + nixosModules.default = { ... }: { + nixpkgs.overlays = final: prev: { + mpv = prev.mpv.override { + scripts = with packages.mpvScripts; [ + sub-select + segment-linking + ]; + }; + }; + + # needed for mpv segment-linking plugin + environment.systemPackages = [ + pkgs.mkvtoolnix + ]; + + home-manager.sharedModules = [ ({ config, lib, ... }: { + config = lib.mkIf config.programs.mpv.enable { + xdg.configFile."mpv/script-opts/sub-select.json".text = builtins.toJSON [ + { + alang = "j[ap]n?"; + slang = [ "eng?" "und" ]; + blacklist = [ "sign" ]; + condition = "not sub.forced"; + } + { + alang = "eng?"; + slang = "forced"; + } + { + alang = "eng?"; + slang = "eng?"; + whitelist = [ "sign" "song" ]; + } + { + alang = [ "eng?" "no" ]; + slang = "no"; + } + { + alang = "*"; + slang = "eng?"; + condition = "not sub.forced"; + } + { + alang = "*"; + slang = "und"; + condition = "not sub.forced"; + } + { + alang = "*"; + slang = "forced"; + } + ]; + }; + }) ]; + }; + } + ); +}