{ machine, ... }@inputs:
let
  browsers = [
    "firefox.desktop"
  ];

  defaultApps = {
    text = [
      "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaanvim.desktop"
    ];
    image = [ "org.gnome.Loupe.desktop" ];
    audio = [ "mpv.desktop" ];
    video = [ "mpv.desktop" ];
    directory = [
      "nautilus.desktop"
      "org.gnome.Nautilus.desktop"
    ];
    mail = [ ] ++ browsers;
    calendar = [ ] ++ browsers;
    browser = [ ] ++ browsers;
    office = [ "libreoffice.desktop" ];
    pdf = [ ] ++ browsers;
    ebook = [ ];
    magnet = [ ];
    signal = [ "signal.desktop" ];
  };

  mimeMap = {
    text = [
      "text/plain"
      "text/english"
      "application/x-zerosize"
      "text/x-makefile"
      "text/x-c++hdr"
      "text/x-c++src"
      "text/x-chdr"
      "text/x-csrc"
      "text/x-java"
      "text/x-moc"
      "text/x-pascal"
      "text/x-tcl"
      "text/x-tex"
      "application/x-shellscript"
      "text/x-c"
      "text/x-c++"
    ];
    image = [
      "image/bmp"
      "image/gif"
      "image/jpeg"
      "image/jpg"
      "image/png"
      "image/svg+xml"
      "image/tiff"
      "image/vnd.microsoft.icon"
      "image/webp"
    ];
    audio = [
      "audio/aac"
      "audio/mpeg"
      "audio/ogg"
      "audio/opus"
      "audio/wav"
      "audio/webm"
      "audio/x-matroska"
    ];
    video = [
      "video/mp2t"
      "video/mp4"
      "video/mpeg"
      "video/ogg"
      "video/webm"
      "video/x-flv"
      "video/x-matroska"
      "video/x-msvideo"
    ];
    directory = [ "inode/directory" ];
    mail = [ "x-scheme-handler/mailto" ];
    calendar = [
      "text/calendar"
      "x-scheme-handler/webcal"
    ];
    browser = [
      "text/html"
      "x-scheme-handler/about"
      "x-scheme-handler/http"
      "x-scheme-handler/https"
      "x-scheme-handler/unknown"
    ];
    office = [
      "application/vnd.oasis.opendocument.text"
      "application/vnd.oasis.opendocument.spreadsheet"
      "application/vnd.oasis.opendocument.presentation"
      "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
      "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
      "application/vnd.openxmlformats-officedocument.presentationml.presentation"
      "application/msword"
      "application/vnd.ms-excel"
      "application/vnd.ms-powerpoint"
      "application/rtf"
    ];
    pdf = [ "application/pdf" ];
    ebook = [ "application/epub+zip" ];
    magnet = [ "x-scheme-handler/magnet" ];
    signal = [ "signal.desktop" ];
  };

  associations =
    with inputs.lib;
    with builtins;
    listToAttrs (
      flatten (mapAttrsToList (key: map (type: attrsets.nameValuePair type defaultApps."${key}")) mimeMap)
    );
  removedAssociations = {
    "text/plain" = "dev.zed.Zed.desktop";
    "application/x-zerosize" = "dev.zed.Zed.desktop";
  };
in
{
  imports = machine.program {
    name = "xdg";
    inherit inputs;
    requirements = [ ];
    home-config =
      { config, ... }:
      {
        xdg = {
          enable = true;
          mime.enable = true;
          configHome = "${config.home.homeDirectory}/.config";
          userDirs = {
            enable = true;
            documents = "${config.home.homeDirectory}/Documents";
            desktop = "${config.home.homeDirectory}/Documents";
            download = "${config.home.homeDirectory}/Downloads";
            music = "${config.home.homeDirectory}/Documents/personal/music";
            pictures = "${config.home.homeDirectory}/Documents/personal/pictures";
          };
          configFile."mimeapps.list".force = true;
          mimeApps = {
            enable = true;
            associations.added = associations;
            associations.removed = removedAssociations;
            defaultApplications = associations;
          };
        };
      };
    system-config = _: {
      xdg = {
        mime = {
          enable = true;
          defaultApplications = associations;
          addedAssociations = associations;
          inherit removedAssociations;
        };
      };
    };
  };
}
