{ config, lib, inputs, pkgs, timeZone, ... }:
let
  deskCfg = config.deskCfg;
in
{
  imports = [
    inputs.nixos-hardware.nixosModules.framework-12-13th-gen-intel
    ./nixos/hardware-configuration.nix
    ../../shared/modules/desktop/base.nix
    ../../shared/modules/desktop/stylix.nix
    ../../shared/modules/desktop/silent-boot.nix
    ../../shared/modules/desktop/greetd.nix
    ../../shared/modules/wm/niri.nix
  ];

  deskCfg = {
    userName = "jaci";
    hostName = "jaci";
    fullName = "Jaci Anderson";
    de = "niri";
    installGaming = true;
    flakePath = "/home/jaci/nixos";
  };

  # Limit the number of generations to keep
  boot.loader.systemd-boot.configurationLimit = 5;
  boot.kernelPackages = pkgs.linuxPackages_latest;

  # Enable systemd in initrd for better LUKS unlocking with Plymouth
  boot.initrd.systemd.enable = true;

  # Silent boot
  silentBoot.enable = true;

  # Plymouth — custom kiki pixel theme
  boot.plymouth = {
    enable = true;
    theme = "kiki-pixel";
    themePackages = [
      (pkgs.runCommand "plymouth-kiki-theme" { } ''
        mkdir -p $out/share/plymouth/themes/kiki
        cp -r ${./kiki-plymouth-theme/kiki}/* $out/share/plymouth/themes/kiki/
        substituteInPlace $out/share/plymouth/themes/kiki/kiki.plymouth \
          --replace-fail "@IMAGEDIR@" "$out/share/plymouth/themes/kiki"
      '')
      (pkgs.runCommand "plymouth-kiki-pixel-theme" { } ''
        mkdir -p $out/share/plymouth/themes/kiki-pixel
        cp -r ${./kiki-plymouth-theme/kiki-pixel}/* $out/share/plymouth/themes/kiki-pixel/
        substituteInPlace $out/share/plymouth/themes/kiki-pixel/kiki-pixel.plymouth \
          --replace-fail "@IMAGEDIR@" "$out/share/plymouth/themes/kiki-pixel"
      '')
    ];
  };

  # Perform garbage collection weekly to maintain low disk usage
  nix.gc = {
    automatic = true;
    dates = "weekly";
    options = "--delete-older-than 21d";
  };
  nix.settings.auto-optimise-store = true;

  # IWD wireless backend
  networking.wireless.iwd.enable = true;

  # Extra groups for jaci user
  main_user.extraGroups = [ "corectrl" ];

  # Stylix overrides — light rose-pine-dawn theme with Reversal icons
  stylix = {
    base16Scheme = "${pkgs.base16-schemes}/share/themes/rose-pine-dawn.yaml";
    polarity = "light";
    fonts.sizes = {
      applications = 14;
      desktop = 14;
      popups = 14;
      terminal = 14;
    };
    iconTheme = {
      package = pkgs.reversal-icon-theme;
      light = "Reversal-dark";
      dark = "Reversal";
    };
  };

  # Intel graphics acceleration (Framework 12)
  hardware.graphics.enable = true;
  hardware.enableRedistributableFirmware = true;

  # Intel iHD GPU
  environment.sessionVariables.LIBVA_DRIVER_NAME = "iHD";

  # Niri WM config
  niriwm = {
    enable = true;
    useNonFree = true;
    user = deskCfg.userName;
    installGaming = deskCfg.installGaming;
    systemPackages = with pkgs; [
      libreoffice
    ];
  };

  # Jaci-specific: gnome-software for Flatpak management
  environment.systemPackages = with pkgs; [
    cryptsetup
    gnome-software
  ];

  # Disable pcscd (not needed on jaci)
  services.pcscd.enable = false;

  # Disable regreet — use direct niri-session via greetd
  programs.regreet.enable = false;
  services.greetd.settings.default_session = {
    command = "${pkgs.niri}/bin/niri-session";
    user = deskCfg.userName;
  };

  # Bluetooth name
  hardware.bluetooth.settings.General.Name = "Jaci-Frame";

  system.stateVersion = "23.11";
}
