{ lib, config, pkgs, ... }:
{
    options.labwc = {
        enable = lib.mkEnableOption "Enable labwc window manager.";
        useNonFree = lib.mkOption {
            default = false;
            example = true;
            description = "Whether to enable non-free software in the labwc config";
        };
        installGaming = lib.mkOption {
            default = false;
            example = true;
            description = "Whether to install gaming software on the system.";
        };
        systemPackages = lib.mkOption {
            default = [];
            description = "Add any additional packages desired. Merged with labwc defaults.";
        };

    };

    ###
    ##  Configuration
    ###
    config = lib.mkIf config.labwc.enable {

        programs.dconf.enable = true;

        nixpkgs.config.allowUnfree = config.labwc.useNonFree;
        # For R2ModMan
        # nixpkgs.config.permittedInsecurePackages = [
        #     "electron-25.9.0"
        # ];
        
        ###
        ##  XDG portal setup
        ###
        xdg.portal = {
            config = {
                common = {
                  default = [
                    "wlr"
                  ];
                };
            };
            extraPortals = with pkgs; [
                xdg-desktop-portal-gtk
            ];
            wlr.enable = true;
            enable = true;
        };
        xdg.sounds.enable = true;

        ###
        ##  System Packages
        ###
        environment.systemPackages = with pkgs; lib.lists.flatten [
             [
                bash
                foot
                git
                glib
                grim
                sway-contrib.grimshot
                ghostscript
                labwc
                libnotify
                kanshi
                mako
                spot
                networkmanagerapplet
                nwg-dock
                nwg-drawer
                nwg-look
                pavucontrol
                slurp
                swaylock
                swayidle
                swww
                wl-clipboard
                cliphist
                waybar
                wdisplays
                xdg-utils
                zsh
             ]
            config.labwc.systemPackages
            # (lib.mkIf config.labwc.installGaming [
            #     pkgs.lutris
            # ])
        ];

        # Thunar config
        programs.thunar = {
            enable = true;
            plugins = with pkgs.xfce; [
                thunar-archive-plugin
                thunar-volman
            ];
        };
        programs.file-roller.enable = true;
        programs.xfconf.enable = true;

        programs.zsh.enable = true;
        programs.steam.enable = config.labwc.installGaming;
        programs.gamemode.enable = true;

        ###
        ##  Services
        ###

        # Printing
        services.flatpak.enable = true;
        services.printing.enable = true;
        services.printing.drivers = [ pkgs.brlaser ];

        services.gvfs.enable = true;  # thunar functionalities

        services.openssh.enable = true;

        services.dbus.enable = true;
        services.pipewire = {
          enable = true;
          alsa.enable = true;
          pulse.enable = true;
        };

        ###
        ##  Misc
        ###
        # sound.enable = true;
        # Necessary for home-manager labwc setup
        security.polkit.enable = true;

        services.greetd = {
          enable = true;
          settings = rec {
            initial_session = {
              command = "${pkgs.labwc}/bin/labwc";
              user = "jaci";
            };
            default_session = initial_session;
          };
        };

        services.xserver.videoDrivers = [ "amdgpu" ];
        # Enable HIP
        systemd.tmpfiles.rules = [
            "L+    /opt/rocm/hip   -    -    -     -    ${pkgs.rocmPackages.clr}"
        ];
        hardware.graphics = {
            # Mesa
            enable = true;
            enable32Bit = true;
            # Rocm support
            extraPackages = with pkgs; [
                rocmPackages.clr.icd
            ];
        };
    };
}
