{
  pkgs,
  config,
  lib,
  inputs,
  ...
}: let
  inherit (config.lib.cosmic) mkRON;
  mkAction = variant: action:
    mkRON "enum" {
      inherit variant;
      value = [
        (mkRON "enum" action)
      ];
    };
in {
  imports = [inputs.cosmic-manager.homeManagerModules.cosmic-manager];
  wayland.desktopManager.cosmic = {
    enable = true;

    systemActions = mkRON "map" [
      {
        key = mkRON "enum" "Terminal";
        value = lib.getExe config.programs.terminal;
      }
    ];

    shortcuts = [
      {
        action = mkAction "System" "Terminal";
        key = "Super+Return";
      }
    ];

    compositor = {
      autotile = true;
      focus_follows_cursor = true;
      focus_follows_cursor_delay = 25;
      input_default.acceleration = mkRON "optional" {
        profile = mkRON "optional" (mkRON "enum" "Flat");
        speed = 0.0;
      };
      keyboard_config.numlock_state = (mkRON "enum" "BootOn");
    };

    wallpapers = [
      {
        filter_by_theme = true;
        filter_method = mkRON "enum" "Lanczos";
        output = "all";
        rotation_frequency = 600;
        sampling_method = mkRON "enum" "Alphanumeric";
        scaling_mode = mkRON "enum" "Zoom";
        source = mkRON "enum" {
          value = [(toString config.stylix.image)];
          variant = "Path";
        };
      }
    ];

    panels = [
      {
        anchor = mkRON "enum" "Top";
        anchor_gap = false;
        autohide = mkRON "optional" null;
        background = mkRON "enum" "Dark";
        expand_to_edges = true;
        name = "Panel";
        opacity = 1.0;
        output = mkRON "enum" "All";
        plugins_center = mkRON "optional" [
          "com.system76.CosmicAppletTime"
        ];
        plugins_wings = mkRON "optional" (mkRON "tuple" [
          [
            "com.system76.CosmicPanelWorkspacesButton"
            "com.system76.CosmicPanelAppButton"
            "com.system76.CosmicAppletWorkspaces"
          ]
          [
            "com.system76.CosmicAppletInputSources"
            "com.system76.CosmicAppletStatusArea"
            "com.system76.CosmicAppletTiling"
            "com.system76.CosmicAppletAudio"
            "com.system76.CosmicAppletNetwork"
            "com.system76.CosmicAppletBattery"
            "com.system76.CosmicAppletNotifications"
            "com.system76.CosmicAppletBluetooth"
            "com.system76.CosmicAppletPower"
          ]
        ]);
        size = mkRON "enum" "XS";
      }
    ];
  };
}
