{ pkgs, lib, profile ? "cli", ... }:
let
  # Handle both file and directory imports for profiles
  # desktop is a directory, others are files
  profilePath =
    if builtins.pathExists ./programs/${profile}/default.nix
    then ./programs/${profile}
    else ./programs/${profile}.nix;
in
{
  imports = [ profilePath ];

  home = {
    packages = (import ./packages.nix { inherit pkgs profile; }).packages;
    stateVersion = "24.05"; # TODO: unify this with the references in flake.nix:inputs

    sessionVariables = {
      EDITOR = "nvim";
      VISUAL = "nvim";
      MOSH_SERVER_NETWORK_TMOUT = 604800;
      NOMAD_ADDR = "http://nomad.service.consul:4646";
      LESS = "-F -i -M -+S -R -w -X -z-4";
      SYSTEMD_LESS = "FiM+SRwX";
      NIX_LD = "${pkgs.glibc}/lib/ld-linux-x86-64.so.2";
      NIX_LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [
        pkgs.stdenv.cc.cc
      ];
      GEMINI_API_KEY = "AIzaSyBZkifYOFNKCjROLa_GZyzQbB2EbEYIby4";
      LLM_GEMINI_KEY = "AIzaSyBZkifYOFNKCjROLa_GZyzQbB2EbEYIby4";
      PLAYWRIGHT_BROWSERS_PATH = "${pkgs.unstable.playwright-driver.browsers}";
      NIXOS_OZONE_WL = "1";
    };

    shellAliases = {
      reload-home-manager-config = "home-manager switch --flake ${builtins.toString ./.}";
    };

    file.".ssh/rc".text = ''
      #!/bin/sh
      if test "$SSH_AUTH_SOCK"; then
        ln -sf "$SSH_AUTH_SOCK" "$HOME/.ssh/ssh_auth_sock"
      fi
    '';
    file.".ssh/rc".executable = true;
  };
}
