# Archive manager: Compress and decompress

# TODO: Once the issue below is resolved, this file can be simplified!
# https://github.com/NixOS/nixpkgs/issues/311240
# The package definition for `kdePackages.ark` does not specify the extra tools that can be used by Ark. The older definition `libsForQt5.ark` contains extra tools such as unar to handle extra types of archives.
#
# Solution: To extract `.rar` files, we manually override some of the attributes based on how it is done in the old file of `libsForQt5.ark`.

{ config, pkgs, lib, ... }:
let
  extraTools = with pkgs; [
    p7zip
    lrzip
    unar
    unrar
  ];

  # https://ryantm.github.io/nixpkgs/using/overrides/#sec-pkg-overrideAttrs
  ark-with-unrar = pkgs.kdePackages.ark.overrideAttrs {
    buildInputs = with pkgs; [
      libarchive
      libzip
    ] ++ extraTools;

    qtWrapperArgs = [
      "--prefix"
      "PATH"
      ":"
      (lib.makeBinPath extraTools)
    ];
  };
in
{
  allowUnfree = [
   # Required for ark
   "unrar"
  ];

  users.users.yoda = {
    packages = with pkgs; [
      ark-with-unrar # Archive manager: Compress and decompress
    ];
  };
}