{ lib, config, pkgs, ... }:
{
  imports = [
    ../home-manager/waybar.nix
  ];

  options.nirihome = {
    enable = lib.mkEnableOption "Enable niri home config";
    homePackages = lib.mkOption {
      default = [ ];
      description = "Add any additional packages desired. Merged with niri defaults.";
    };
  };

  config = lib.mkIf config.nirihome.enable {
    # Note: We don't use wayland.windowManager.niri in home-manager
    # because we manage the niri config through dotfiles.
    # The system-level module enables niri via programs.niri.enable

    # Niri sets WAYLAND_DISPLAY and XDG_CURRENT_DESKTOP automatically.
    # Manually overriding session vars conflicts with xdg-desktop-portal-gnome
    # screencasting (breaks Zoom screen sharing).

    # Cursor is managed by Stylix (stylix.cursor in host config)

    # Waybar with Stylix theming
    waybarConfig.enable = true;

    home.packages = with pkgs; lib.lists.flatten [
      [
        ### niri packages
        swaybg
        swaylock-effects
        # Etc
        gopsuinfo # For system stats in panel
        wl-clipboard # System clipboard
        brightnessctl
        wev
        wdisplays
        # Notifs
        libnotify
        swaynotificationcenter
        # Tray Applets
        pavucontrol
        syncthingtray
        tailscale-systray
        # Portals are managed at system level by programs.niri.enable
      ]
      config.nirihome.homePackages
    ];

    programs.cava = {
      enable = true;
      settings = {
        smoothing.noise_reduction = 55;
      };
    };
  };
}
