{ lib
, config
, pkgs
, ...
}:

with lib;
let
  cfg = config.my.profiles.desktop;
in
{
  options.my.profiles.desktop.enable = mkEnableOption "desktop profile";

  config = mkIf cfg.enable {
    my = {
      yubikey = {
        enable = mkDefault true;
        luksSupport = {
          enable = mkDefault false;
          devices = mkDefault [ "enc" ];
        };
      };
      wallpapers.enable = mkDefault true;
      theming = {
        enable = mkDefault true;
        scheme = mkDefault "catppuccin-macchiato";
      };
      virtualisation.podman.enable = mkDefault true;

      programs = {
        chromium.enable = mkDefault true;
        firefox.enable = mkDefault true;
        gpg.enable = mkDefault true;
        hyprland.enable = mkDefault true;
        nix-edit.enable = mkDefault true;
        nvim.enable = mkDefault true;
        python.versions."311".enable = mkDefault true;
        spotify-player = {
          enable = mkDefault true;
          package = pkgs.spotify-player.overrideAttrs (old: {
            buildFeatures = lib.lists.remove "notify" (old.buildFeatures or [ ]);
          });
          config = {
            client_id = "3172dbeaf64949728920c58b823bc24b";
            copy_command = {
              command = "wl-copy";
              args = [ ];
            };
            enable_cover_image_cache = true;
            default_device = "spotify-player-daemon";
            enable_streaming = false;
            playback_window_position = "Bottom";
            cover_img_length = 20;
            cover_img_width = 10;
          };
        };
        ssh.enable = mkDefault true;
        thunar.enable = mkDefault true;
        wallpaper.enable = mkDefault true;
        zathura.enable = mkDefault true;
      };
      services = {
        dunst.enable = mkDefault true;
        gammastep.enable = true;
        kdeconnect.enable = mkDefault true;
        printing.enable = true;
        spotify-player = {
          enable = mkDefault true;
          config = {
            client_id = "3172dbeaf64949728920c58b823bc24b";
            device = {
              name = "spotify-player-daemon";
              device_type = "computer";
              volume = 70;
              bitrate = 320;
              audio_cache = true;
            };
          };
        };
        timers.enable = true;
        wireguard.enable = true;
      };
    };

    environment.systemPackages = with pkgs; [
      keepassxc
      pavucontrol
      stable.libreoffice # NOTE breaks often
      stable.signal-desktop # NOTE breaks often
      stable.texlive.combined.scheme-full # NOTE breaks often
      thunderbird
      vlc
    ];

    programs.nix-ld.enable = true;

    home-manager.users.moritz = {
      services.nextcloud-client = {
        enable = true;
        startInBackground = true;
      };
      systemd.user.services.nextcloud-client.Service = {
        RestartSec = "500ms";
        Restart = "on-failure";
      };
    };

    services = {
      illum.enable = true;
      gnome.gnome-keyring.enable = true;
      pipewire = {
        enable = true;
        alsa.enable = true;
        pulse.enable = true;
      };
    };

    # faster startup https://majiehong.com/post/2021-07-30_slow_nixos_startup/
    networking = {
      # no need to wait interfaces to have an IP to continue booting
      dhcpcd.wait = "background";
      # avoid checking if IP is already taken to boot a few seconds faster
      dhcpcd.extraConfig = "noarp";
    };
    # disable network-online.target
    systemd.services.NetworkManager-wait-online.enable = false;
    boot = {
      consoleLogLevel = 0;
      kernelParams = [ "quiet" "udev.log_level=3" ];
    };
  };
}
