# VLC Blu-ray playback with NixOS
#   Requires libaacs and libbdplus
#   Solution: https://github.com/NixOS/nixpkgs/issues/63641#issuecomment-505039827

# We do also need some databases ...
# Here is a script describing the necessary steps.
# Source: https://github.com/puppylinux-woof-CE/woof-CE/blob/849a9faa7ea8cac74e04d04e4f99f4425652c26b/woof-code/rootfs-skeleton/usr/local/bin/bdplayback_aacs
#
#    # db for libaacs: http://www.videolan.org/developers/libaacs.html
#    mkdir -p ~/.config/aacs
#    (
#    	cd ~/.config/aacs
#    	wget http://www.labdv.com/aacs/KEYDB.cfg
#    )
#    
#    # db for libbdplus: http://www.videolan.org/developers/libbdplus.html
#    mkdir -p ~/.config/bdplus
#    (
#    	cd ~/.config
#    	wget http://www.labdv.com/aacs/libbdplus/bdplus-vm0.bz2
#    	tar -xvjf bdplus-vm0.bz2
#    	rm bdplus-vm0.bz2
#    )

# More details on `libbluray`.
# From the source code
#   https://github.com/NixOS/nixpkgs/blob/2ab31359946cd78a509b61931cbf7de7beebdd6f/pkgs/development/libraries/libbluray/default.nix#L2C4-L6
#   , withJava ? false, jdk, ant
#   , withAACS ? false, libaacs
#   , withBDplus ? false, libbdplus
#   , withMetadata ? true, libxml2
#   , withFonts ? true, freetype
# we can read that Java, AACS and BD+ support can be enabled.

# Back-up a personal DVD:
#   dvdbackup -i /dev/sr0 --mirror --progress -o ~/Downloads/ && eject /dev/sr0

{ config, pkgs, ... }:
let
  libbluray = pkgs.libbluray.override {
    withAACS = true;
    withBDplus = true;
  };
  vlc = pkgs.vlc.override { inherit libbluray; };
in
{
  users.users.yoda = {
    packages = [
      vlc # Video (DVD, Blu-ray) and audio player
      pkgs.dvdbackup # Create ackups of personal DVDs
    ];
  };
}
