{
  lib,
  config,
  username,
  host,
  pkgs,
  ...
}:
let
  cfg = config.desktop;
in
{
  imports = [
    ./base.nix
  ];

  options = {
    desktop = {
      enable = lib.mkEnableOption "Enable desktop in NixOS";
      hostSettings = lib.mkOption {
        type = lib.types.str;
        default = "hostMonitorSettings";
      };
      browser = lib.mkOption {
        type = lib.types.str;
        default = "firefox";
      };
      terminal = lib.mkOption {
        type = lib.types.str;
        default = "kitty";
      };
    };
  };
  config = lib.mkIf cfg.enable {
    # Custom modules
    base.enable = true;
    catppuccinTheming.enable = true;
    # floorp.enable = true;
    # kde.enable = true;
    # mumble.enable = true;
    # office.enable = true;
    vscode.enable = true;
    # wezterm.enable = true;
    # wireshark.enable = true;
    # zed.enable = false;

    hardware = {
      bluetooth = {
        enable = true;
        powerOnBoot = true;
        settings = {
          General = {
            AutoEnable = true;
          }; # https://reddit.com/r/NixOS/comments/1aoteqb/keychron_k1_pro_bluetooth_nixos_wkde_install/kq49q9r/?context=3
        };
      };
      enableAllFirmware = true;
      i2c.enable = true;
      graphics = {
        enable = true;
        enable32Bit = true;
      };
    };
    nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";
    services = {
      #   btrfs = {
      #     autoScrub = {
      #       enable = true;
      #       interval = "weekly";
      #     };
      #   };
      blueman.enable = true;
      devmon.enable = true;
      fwupd.enable = true;
      geoclue2 = {
        enable = true;
        geoProviderUrl = "https://beacondb.net/v1/geolocate";
      };
      power-profiles-daemon.enable = true;
      udev.packages = with pkgs; [ android-udev-rules ];
      udisks2 = {
        enable = true;
      };
    };
    # NixOS system programs
    programs = {
      thunar = {
        enable = true;
        plugins = with pkgs.xfce; [
          thunar-archive-plugin
          thunar-volman
        ];
      };
      foot.enable = true;
    };
    home-manager.users.${username} =
      {
        pkgs,
        config,
        vars,
        ...
      }:
      {
        # Home-manager programs
        programs = {
          kitty.enable = true;
        };
        home.packages = with pkgs; [
          # GUI Apps
          firefox
          ungoogled-chromium
          logseq
          filezilla
          spotify
          anki-bin

          # Utilities
          networkmanagerapplet
          swaynotificationcenter
          brightnessctl
        ];
        xdg = {
          mimeApps =
            let
              audioPlayer = "org.fooyin.fooyin.desktop";
              browser = "app.zen_browser.zen.desktop";
              editor = "org.kde.kate.desktop";
              imageViewer = "org.kde.gwenview.desktop";
              pdfViewer = "org.kde.okular.desktop";
              videoPlayer = "org.kde.haruna.desktop";
            in
            {
              enable = true;
              defaultApplications =
                {
                  "audio/*" = audioPlayer;
                  "image/*" = imageViewer;
                  "video/*" = videoPlayer;
                  "text/*" = editor;
                  "text/html" = browser;
                  "text/plain" = editor;
                  "application/json" = editor;
                  "application/pdf" = pdfViewer;
                  "application/toml" = editor;
                  "application/x-bat" = editor;
                  "application/xhtml+xml" = browser;
                  "application/xml" = editor;
                  "application/x-shellscript" = editor;
                  "application/x-yaml" = editor;
                  "inode/directory" = "org.kde.dolphin.desktop";
                  "x-scheme-handler/bottles" = "com.usebottles.bottles.desktop";
                  "x-scheme-handler/http" = browser;
                  "x-scheme-handler/https" = browser;
                  "x-scheme-handler/terminal" = "org.wezfurlong.wezterm.desktop";
                }
                // lib.optionalAttrs vars.gaming {
                  "application/x-cue" = "cdemu-client.desktop";
                  "application/x-msdownload" = "wine.desktop";
                  "x-scheme-handler/ror2mm" = "r2modman.desktop";
                };
            };
          portal = {
            enable = true;
            config.common.default = "*";
            extraPortals = with pkgs; [
              xdg-desktop-portal
              xdg-desktop-portal-hyprland
              xdg-desktop-portal-gtk
            ];
            configPackages = with pkgs; [
              xdg-desktop-portal-gtk
              xdg-desktop-portal-hyprland
              xdg-desktop-portal
            ];
          };
        };
      };
    # Services to start
    services = {
      displayManager.sddm.enable = true;
      displayManager.sddm.wayland.enable = true;
      xserver = {
        enable = false;
        xkb = {
          layout = "us";
          variant = "";
          options = "grp:win_space_toggle";
        };
      };
      # greetd = {
      #   enable = true;
      #   vt = 1;
      #   settings = rec {
      #     initial_session = {
      #       user = username;
      #       command = "${pkgs.greetd.tuigreet}/bin/tuigreet --time --cmd Hyprland"; # st>
      #     };
      #     default_session = initial_session;
      #   };
      # };
      smartd = {
        enable = false;
        autodetect = true;
      };
      libinput.enable = true;
      fstrim.enable = true;
      gvfs.enable = true;
      openssh.enable = true;
      flatpak.enable = false;
      printing = {
        enable = true;
        drivers = [
          # pkgs.hplipWithPlugin
        ];
      };
      gnome.gnome-keyring.enable = true;
      avahi = {
        enable = true;
        nssmdns4 = true;
        openFirewall = true;
      };
      ipp-usb.enable = true;
      pipewire = {
        enable = true;
        alsa.enable = true;
        alsa.support32Bit = true;
        pulse.enable = true;
      };
      rpcbind.enable = false;
      nfs.server.enable = false;
    };
  };
}
