{ nix-config, config, lib, pkgs, inputs, ... }:
{

  imports = with nix-config.homeModules; [
    # mako
    yazi
    shell-conf # shell, shell utils, cli tools, libs, tui's
    email
    desktop
    music
    langs
    emacs
  ];

  home = {
    packages = lib.mkMerge [
      [
        inputs.affinity-nix.packages.x86_64-linux.photo
        inputs.affinity-nix.packages.x86_64-linux.publisher
        inputs.affinity-nix.packages.x86_64-linux.designer
      ]

      (with pkgs; [
        samba4Full
        dconf
        xorg.libX11
        xorg.libxcb
        freetype
        alsa-utils
        alsa-oss
        dbus
        cifs-utils
        sops

        ispell
        (aspellWithDicts (dicts: with dicts; [ en en-computers en-science es fr ]))
        texlive.combined.scheme-full

        spice
        spice-gtk
        spice-protocol
        virt-viewer
        virt-manager
      ])
    ];

    username = "emenel";
    homeDirectory = "/home/emenel";

    sessionPath = [ "/home/emenel/.config/emacs/bin"
                    "/home/emenel/.npm-packages/bin"
                    "/home/emenel/Applications"
                    "/home/emenel/.local/bin"
                    "/home/emenel/.local/share"
                    "/home/emenel/.nix-profile/lib"
                    "/etc/profiles/per-user/emenel/bin/"
                    "/home/emenel/.local/state/nix/profiles/home-manager/home-path/bin/" ];

    sessionVariables = {
      WINEFSYNC = 1;
      PKG_CONFIG_PATH = "/home/emenel/.nix-profile/lib/pkgconfig:/home/emenel/.nix-profile/lib64/pkgconfig:/home/emenal/.nix-profile/share/pkgconfig";
      GI_TYPELIB_PATH = "/run/current-system/sw/lib/girepository-1.0";
      BW_CLIENTID = "$(cat ${config.sops.defaultSymlinkPath}/bw_client_id)";
      BW_CLIENTSECRET = "$(cat ${config.sops.defaultSymlinkPath}/bw_api_key)";
      NIXOS_OZONE_WL = "1";
      GSK_RENDERER = "ngl";
      MOZ_ENABLE_WAYLAND = 1;
      LSP_USE_PLISTS = "true";
      NH_FLAKE = "\${HOME}/source/nixos-config";
    };

    stateVersion = "24.05";
  };

  sops = {
    age.keyFile = "/home/emenel/.config/sops/age/keys.txt"; # must have no password!

    defaultSopsFile = ./secrets.yaml;

    secrets = {
      bw_client_id = {
        path = "${config.sops.defaultSymlinkPath}/bw_client_id";
      };
      bw_api_key = {
        path = "${config.sops.defaultSymlinkPath}/bw_api_key";
      };
      ssh_key = {
        path = "${config.sops.defaultSymlinkPath}/ssh_key";
      };
      borg_url = {
        path = "${config.sops.defaultSymlinkPath}/borg_url";
      };
    };
  };

  programs = {
    home-manager.enable = true;

    pandoc.enable = true;
    password-store.enable = true;

    git = {
      enable = true;
      lfs = {
        enable = true;
      };
      userEmail = "matt@emenel.ca";
      userName = "Matt Nish-Lapidus";
      ignores = [
        ".DS_Store"
      ];
      extraConfig = {
        core = {
          editor = "$EDITOR";
        };
        init = {
          defaultBranch = "main";
        };
      };
      aliases = {
        co = "checkout";
        cm = "commit -m";
        aa = "add .";
      };
    };
  };

  services = {
    playerctld = {
      enable = true;
      package = pkgs.playerctl;
    };
    borgmatic = {
      enable = true;
    };
    gpg-agent = {
      enable = true;
    };
  };

  xdg.systemDirs.data = [
    "/home/emenel/.local/share/applications/wine/Programs"
    "/home/emenel/.local/share/applications"
    "/var/lib/flatpak/exports/share"
  ];

  systemd.user = {
    enable = true;
    startServices = "sd-switch"; # auto reload services when home is rebuilt
    sessionVariables = {
      GSK_RENDERER = "ngl";
      MOZ_ENABLE_WAYLAND = 1;
      XCURSOR_SIZE = 32;
      XCURSOR_THEME = "Bibata-Modern-Classic";
      DISPLAY = ":0";
      WAYLAND_DISPLAY="wayland-1";
    };
  };

  # email signature
  home.file.".signature".source = ./dotfiles/dot_signature;

  #custom script executables
  home.file.".local/bin" = {
    source = ./dotfiles/dot_local/bin;
    recursive = true;
  };
}
