{ inputs, config, pkgs, lib, ... }:
  let
    userName = "nate";
    fullName = "Nathan Anderson";
    email = "n8r@tuta.io";
    unstable = import inputs.nixpkgs-unstable { system = "x86_64-linux"; config.allowUnfree = true; };
    # oldstable = import inputs.nixpkgs-23 { system = "x86_64-linux"; config.allowUnfree = true; };
    # davinciDesktop = pkgs.makeDesktopItem {
    #   name = "davinci-resolve-studio";
    #   desktopName = "Davinci Resolve Studio";
    #   exec = "${oldstable.davinci-resolve-studio}";
    # };
    # overlay-unstable = final: prev: {
    #   unstable = inputs.nixpkgs-unstable.legacyPackages.x86_64-linux;
    # };
    # overlay-oldstable = final: prev: {
    #   pkgs23 = inputs.nixpkgs-23.legacyPackages.x86_64-linux;
    # };
    # overlay-unstable = final: prev: {
    #   # unstable = inputs.nixpkgs-unstable.legacyPackages.x86_64-linux;
    #   unstable = import inputs.nixpkgs-unstable {
    #     system = "x86_64-linux";
    #     config = { 
    #       allowUnfreePredicate = (pkg: true); 
    #       allowUnfree = true; 
    #     }; 
    #   };
    # };
  in
{
  # nixpkgs.overlays = [
  #   overlay-unstable
  # ];

  imports = [
      ../../../shared/modules/apps/firefox/firefox.nix
  ];
  
  home.username = userName;
  home.homeDirectory = "/home/${userName}";

  programs.home-manager.enable = true;

  home.stateVersion = "23.11"; # Please read the comment before changing.

  # The home.packages option allows you to install Nix packages into your
  # environment.
  firefoxApp.enable = true;
  
  fonts.fontconfig.enable = true;


  home.packages = with pkgs; [
    # nur.repos.crazazy.js.eslint
    chromium
    #
    # Dev Tools
    #
    dbeaver-bin
    helix
    docker
    docker-compose
    unstable.godot
    jq
    python310
    ### LSP's
    nil # Nix LSP
    nodePackages_latest.bash-language-server
    openscad-lsp
    vscode-langservers-extracted # provides eslint, markdown, json, css, and html lsp
    python311Packages.python-lsp-server
    ## Clojure
    leiningen
    jre17_minimal
    clojure
    clojure-lsp
    cljfmt
    emacs

    # zls
    ### Misc
    # android-udev-rules
    # android-tools
    # sdkmanager
    unstable.claude-code
    usbutils
    cli-visualizer
    openscad

    #
    # Gaming
    #
    amdgpu_top
    mangohud
    r2modman
    wine-wayland
    webcord

    #
    # Better Unix
    #
    bat
    duf
    du-dust
    fd
    fzf
    lsd
    ripgrep
    tre-command
    gtop
    htop
    neofetch
    # Normies
    unzip
    llpp
    nmap

    #
    # Photo / Video
    #
    unstable.davinci-resolve-studio
    # davinciDesktop
    imv
    mpv
    gimp
    ffmpeg
    tenacity
    yt-dlp
    libimobiledevice
    ifuse

    #
    # Communication
    #
    mumble
    slack
    #
    # Other
    #
    keepassxc
    obs-studio
    prusa-slicer
    yubioath-flutter
    gnome-disk-utility
    handbrake
    kdePackages.filelight
    hugo
    prismlauncher
    simple-scan
    code-cursor

    #
    # Style
    #
    catppuccin-kvantum
    libsForQt5.qtstyleplugin-kvantum
    libsForQt5.qt5ct
    # Install fonts
    lato
    unstable.nerd-fonts.hurmit
    unstable.nerd-fonts.overpass
    recursive
  ];

  # Home Manager is pretty good at managing dotfiles. The primary way to manage
  # plain files is through 'home.file'.
  # home.file."${config.xdg.configHome}" = {
  #   source = ../../dotfiles;
  #   recursive = true;
  # };

  home.file = lib.mkMerge [
    # Shared dotfiles
    (let
      sharedDotfilesPath = ../../../shared/dotfiles;
    in
      if builtins.pathExists sharedDotfilesPath then
        builtins.listToAttrs (map (name: {
          name = "${config.xdg.configHome}/${name}";
          value = { source = lib.mkDefault (sharedDotfilesPath + "/${name}"); };
        }) (builtins.attrNames (builtins.readDir sharedDotfilesPath)))
      else {})
    # Add local dotfiles, overriding from local over shared
    (let
      localDotfilesPath = ../../dotfiles;
    in
      if builtins.pathExists localDotfilesPath && builtins.readDir localDotfilesPath != {} then
        builtins.listToAttrs (map (name: {
          name = "${config.xdg.configHome}/${name}";
          value = { source = localDotfilesPath + "/${name}"; };
        }) (builtins.attrNames (builtins.readDir localDotfilesPath)))
      else {})
  ];

  xdg.configFile = {
    # Active linked dotfiles
    "hypr".source = config.lib.file.mkOutOfStoreSymlink "/home/nate/nixos/nate-work/linked-dotfiles/hypr";
    "waybar".source = config.lib.file.mkOutOfStoreSymlink "/home/nate/nixos/nate-work/linked-dotfiles/waybar";
    # Shared
    "helix".source = config.lib.file.mkOutOfStoreSymlink "/home/nate/nixos/shared/linked-dotfiles/helix";

    # Theme files
    "gtk-4.0/assets".source = "${config.gtk.theme.package}/share/themes/${config.gtk.theme.name}/gtk-4.0/assets";
    "gtk-4.0/gtk.css".source = "${config.gtk.theme.package}/share/themes/${config.gtk.theme.name}/gtk-4.0/gtk.css";
    "gtk-4.0/gtk-dark.css".source = "${config.gtk.theme.package}/share/themes/${config.gtk.theme.name}/gtk-4.0/gtk-dark.css";
    "Kvantum/kvantum.kvconfig".source = (pkgs.formats.ini {}).generate "kvantum.kvconfig" {
      General.theme = "catppuccin-macchiato-lavender";
     };
  };
  # For applying custom styles
  # home.file.".mozilla/firefox/default" = {
  #   source = ../../misc/firefox_styles;
  #   recursive = true;
  # };
  # location where stylus data is kept
  # /home/nate/.mozilla/firefox/default/storage/default/moz-extension+++77a1d59f-183c-4439-b249-fdae98b7bd7b/idb
  services.kdeconnect = {
    enable = true;
    indicator = true;
  };

  home.sessionVariables = {
    # MANPAGER="sh -c 'col -bx | bat -l man -p'";
    BAT_THEME="Catppuccin Macchiato";
    EDITOR = "hx";
    XDG_CURRENT_DESKTOP="sway";
    NIXOS_OZONE_WL = "1";
  };

  # Git setup
  programs.git = {
      enable = true;
      userEmail = email;
      userName = fullName;
      extraConfig = {
        include = { path = "${config.xdg.configHome}/macchiato.gitconfig"; };
        init = { defaultBranch = "main"; };
        pull = { ff = "only"; };
        merge = { conflictStyle="zdiff3"; };
        push = { autoSetupRemote="true"; };
        delta = { features = "Catppuccin Macchiato"; };
      };
      delta.enable = true;
  };

  programs = {
    direnv = {
      enable = true;
      enableZshIntegration = true; # see note on other shells below
      nix-direnv.enable = true;
    };

    bash.enable = true; # see note on other shells below
  };

  # Zsh setup
  programs.zsh = {
      enable = true;
      oh-my-zsh = {
          enable = true;
          plugins = [ "git" "ssh-agent" ];
          theme = "half-life";
          extraConfig =
          ''
            zstyle :omz:plugins:ssh-agent lazy yes
          '';
      };
      initContent = ''
          eval "$(direnv hook zsh)"

          yt-audio() {
            nix-shell -p yt-dlp --run "yt-dlp -x $1 --audio-format mp3"
          }
       '';
      shellAliases = {
          ls="lsd";
          l="lsd --almost-all --long";
          llm="lsd --timesort --long";
          lS="lsd --oneline --classic";
          lt="lsd --tree --depth=2";
          cat="bat --paging=never";
          rm="rm -i";
          adaptiveoff="swaymsg 'output * adaptive_sync off'";
          adaptiveon="swaymsg 'output * adaptive_sync on'";
      };
  };

  qt = {
    enable = true;
    platformTheme.name = "qtct";
    style.name = "kvantum";
  };

  gtk = {
    enable = true;
    cursorTheme = {
      package = pkgs.catppuccin-cursors.macchiatoLavender;
      name = "catppuccin-macchiato-lavender-cursors";
    };
    iconTheme = {
      package = pkgs.catppuccin-papirus-folders;
      name = "Papirus-Dark";
    };
    theme = {
      name = "catppuccin-macchiato-lavender-compact+rimless";
      package = pkgs.catppuccin-gtk.override {
        accents = [ "lavender" ];
        size = "compact";
        tweaks = [ "rimless" ];
        variant = "macchiato";
      };
    };
  };
  # Symlink in gtk and kvantum theme to ~/.config
  # xdg.configFile = {
  #   "gtk-4.0/assets".source = "${config.gtk.theme.package}/share/themes/${config.gtk.theme.name}/gtk-4.0/assets";
  #   "gtk-4.0/gtk.css".source = "${config.gtk.theme.package}/share/themes/${config.gtk.theme.name}/gtk-4.0/gtk.css";
  #   "gtk-4.0/gtk-dark.css".source = "${config.gtk.theme.package}/share/themes/${config.gtk.theme.name}/gtk-4.0/gtk-dark.css";
  #   "Kvantum/kvantum.kvconfig".text = ''
  #     [General]
  #     theme=Catppuccin-Frappe-Blue
  #   '';
  #   "Kvantum/Catppuccin-Frappe-Blue".source = "${pkgs.catppuccin-kvantum}/share/Kvantum/Catppuccin-Frappe-Blue";
  # };

  # home.file.".icons/default/index.theme".text = ''
  #   [icon theme]
  #   Inherits=Catppuccin-Macchiato-Lavender-Cursors
  # '';
}
