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

with lib;

let
  cfg = config.settings.desktop-environments.niri;
in {
  options = {
    settings.desktop-environments.niri.enable = lib.mkOption {
      type = lib.types.bool;
      description = ''
        Enable niri desktop environment
      '';
      default = false;
    };
  };

  imports = [
    inputs.niri.nixosModules.niri
  ];

  config = mkIf cfg.enable {
    nix = {
      settings = {
        substituters = [
          "https://niri.cachix.org"
        ];
        trusted-public-keys = [
          "niri.cachix.org-1:Wv0OmO7PsuocRKzfDoJ3mulSl7Z6oezYhGhR+3W2964="
        ];
      };
    };
  
    programs.niri.enable = true;
    programs.niri.package = pkgs.unstable.niri;
    nixpkgs.overlays = [ inputs.niri.overlays.niri ];
    environment.variables.NIXOS_OZONE_WL = "1";

    environment.systemPackages = with pkgs; [
      wl-clipboard
      wayland-utils
      libsecret
      cage
      gamescope
      xwayland-satellite-unstable
      swaybg
    ];
  };
}
