{ inputs, config, pkgs, ... }:
  let
    userName = "scrappy";
    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; };
    #niri = import inputs.niri { 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 = [
#    niri.overlays.niri
#  ];

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

  programs.home-manager.enable = true;

  home.stateVersion = "24.05"; # 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;

  wayland.windowManager.hyprland.enable = true; # enable Hyprland
  wayland.windowManager.hyprland.settings = {
    "$mod" = "Super";
    "$terminal" = "foot";
    "$fileManager" = "thunar";
    "$menu" = "nwg-drawer";
    # Autostart
    exec-once =
      [
        "swaylock -C ~/.config/swaylock/boot-config"
        "swaybg -i ~/.config/hypr/nix.png"
        "nwg-panel"
        "nm-applet --indicator"
        # May need to kill mako if nwg-panel starts it
        "swaync"
        # Disable keyboard's power button
        "hyprctl keyword 'device[power-button]:enabled' 'false'"
      ];
    input = {
      repeat_rate = 50;
      repeat_delay = 400;
      touchpad = {
        natural_scroll = true;
      };
    };
    gestures = {
      workspace_swipe = true;
    };
    general = {
      gaps_in = 3;
      gaps_out = 5;
      border_size = 2;
      "col.active_border" = "rgba(33ccffee) rgba(00ff99ee) 45deg";
    };
    decoration = {
      rounding = 8;
      inactive_opacity = 0.8;
      # Perf improvement
     blur = {
        enabled = false;
      };
      drop_shadow = false;
    };
    bind =
      [
        "$mod, Q, killactive"
        "$mod Shift, Q, exit"
        "$mod, W, exec, firefox"
        "$mod, D, exec, $menu"
        "$mod, T, exec, $fileManager"
        "$mod, code:36, exec, $terminal" # Enter code
        "$mod, Space, togglefloating"
        "$mod, F, fullscreen, 0"
        "$mod, Tab, cyclenext"
        "$mod Shift, Tab, swapnext"
        "$mod, left, movefocus, l"
        "$mod, right, movefocus, r"
        "$mod, up, movefocus, u"
        "$mod, down, movefocus, d"
        "$mod Shift, left, movewindow, l"
        "$mod Shift, right, movewindow, r"
        "$mod Shift, up, movewindow, u"
        "$mod Shift, down, movewindow, d"
        # Colemak-DH binds
        "$mod, N, movefocus, l"
        "$mod, O, movefocus, r"
        "$mod, E, movefocus, u"
        "$mod, I, movefocus, d"
        "$mod Shift, N, movewindow, l"
        "$mod Shift, O, movewindow, r"
        "$mod Shift, E, movewindow, u"
        "$mod Shift, I, movewindow, d"
        # Disabled laptop keyboard
        "$mod SHIFT, K, exec, hyprctl keyword 'device[at-translated-set-2-keyboard]:enabled' 'false' && notify-send 'Laptop keyboard disabled' -i nix-snowflake"
        # Reload config
        "$mod SHIFT, R, exec, hyprctl reload && notify-send 'Hypr Config Reloaded' -i nix-snowflake"
        # Print, exec, grimblast copy area"
      ]
      ++ (
        # workspaces
        # binds $mod + [shift +] {1..9} to [move to] workspace {1..9}
        builtins.concatLists (builtins.genList (i:
            let ws = i + 1;
            in [
              "$mod, code:1${toString i}, workspace, ${toString ws}"
              "$mod SHIFT, code:1${toString i}, movetoworkspace, ${toString ws}"
            ]
          )
          9)
      );
      bindm = [
        "$mod, mouse:272, movewindow" # LMB to move window
        "$mod, mouse:273, resizewindow" # RMB to move window
      ];
      bindel = [
        # Brightness / Volume Controls
        # Chromebook has the printed symbols for these actions, but are really just fn keys
        "$mod, F6, exec, brightnessctl s 10%-"
        "$mod, F7, exec, brightnessctl s 10%+"
        "$mod, F8, exec, wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle"
        "$mod, F9, exec, wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%-"
        "$mod, F10, exec, wpctl set-volume -l 1 @DEFAULT_AUDIO_SINK@ 5%+"
        # "$mod, XF86AudioMicMute, exec, wpctl set-mute @DEFAULT_AUDIO_SOURCE@ toggle"
      ];
      # Lid switch binds
      bindl = [
        ", switch:Lid Switch, exec, swaylock"
      ];
      misc = {
        "vfr" = true;
        force_default_wallpaper = 0;
        disable_hyprland_logo = true;
      };
  };
  # Optional, hint Electron apps to use Wayland:
  # home.sessionVariables.
  home.packages = with pkgs; [
    ### ---
    ### hyprland packages
    swaybg
    swaylock-effects
    wofi
    nwg-bar
    nwg-menu
    nwg-look
    nwg-dock-hyprland
    nwg-panel
    nwg-drawer
    nwg-launchers
    gopsuinfo # For system stats in panel
    wl-clipboard # System clipboard
    networkmanagerapplet
    libnotify
    swaynotificationcenter
    lynx
    qutebrowser
    brightnessctl
    ### ---

    # nur.repos.crazazy.js.eslint
    # inputs.nixpkgs-stable.legacyPackages.x86_64-linux.corectrl
    chromium
    #
    # Dev Tools
    #
    #dbeaver-bin
    helix
    foot
    docker
    docker-compose
    fossil
    fnc
    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
    # zls
    ### Misc
    # android-udev-rules
    # android-tools
    # sdkmanager
    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
    #
    imv
    mpv
    gimp
    ffmpeg
    tenacity
    yt-dlp

    #
    # Communication
    #
    mumble
    slack
    unstable.signal-desktop

    #
    # Other
    #
    keepassxc
    yubioath-flutter

    #
    # Style
    #
    catppuccin-kvantum
    libsForQt5.qtstyleplugin-kvantum
    libsForQt5.qt5ct
    # Install fonts
    lato
    (nerdfonts.override { fonts = [ "Hermit" "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.sessionVariables = {
    BAT_THEME="Catppuccin Macchiato";
    EDITOR = "hx";
    # For electron apps
    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 = [ "fossil" "git" ];
          theme = "half-life";
      };
      initExtra = ''
          eval "$(direnv hook zsh)"
          export SSH_AUTH_SOCK=$XDG_RUNTIME_DIR/ssh-agent

          yt-audio() {
            nix-shell -p yt-dlp --run "yt-dlp -x $1 --audio-format mp3"
          }

          # Better Unix Aliases
          # alias ask="nix-shell -p python310Packages.openai --run 'python ~/source/python/chat.py'"
          alias ls="lsd"
          alias l="lsd --almost-all --long"
          alias llm="lsd --timesort --long"
          alias lS="lsd --oneline --classic"
          alias lt="lsd --tree --depth=2"
          alias grep="rg"
          alias cat="bat --paging=never"
          alias rm="rm -i"
          alias adaptiveoff="swaymsg 'output * adaptive_sync off'"
          alias 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
  '';
  services.wlsunset = {
    enable = true;
    sunrise = "07:00";
    sunset = "17:00";
    temperature.night = 3500;
  };
}