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

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

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

      (with pkgs; [
        dconf
        cifs-utils
        sops
        (btop.override { cudaSupport = true; rocmSupport = true; })
        ispell
        (aspellWithDicts (dicts: with dicts; [ en en-computers en-science es fr ]))
        texlive.combined.scheme-full
      ])
    ];

    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";
      GDK_BACKEND= "wayland";
      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";
      };
      icloud = {};
    };
  };

  programs = {
    home-manager.enable = true;

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

    rclone = {
      enable = true;
    };
    
    borgmatic = {
      enable = true;
      backups = {
        eddie = {
          location = {
            patterns = [
              "R /home/emenel"
              "- home/emenel/.cache"
              "- home/emenel/.nix*"
              "- home/emenel/.steam*"
              "- home/emenel/Dropbox"
              "- home/emenel/Sync"
              "- home/emenel/.dropbox*"
              "- home/emenel/.BitwigStudio"
              "- home/emenel/.local/share/bitwig"
            ];
            repositories = [
              {
                "path" = "ssh://oyi3ydnz@oyi3ydnz.repo.borgbase.com/./repo";
                "label" = "eddie on borgbase";
              }
            ];
          };
          retention = {
            keepDaily = 3;
            keepHourly = 3;
            keepMonthly = 2;
          };
        };
      };
    };
  };

  services = {
    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";
      QT_QPA_PLATFORM = "xcb";
      MOZ_ENABLE_WAYLAND = 1;
      XCURSOR_SIZE = 32;
      XCURSOR_THEME = "Bibata-Modern-Classic";
      DISPLAY = ":0";
      WAYLAND_DISPLAY="wayland-1";
      ELECTRON_OZONE_PLATFORM_HINT = "auto";
    };
  };

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

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

  home.file.".ssh/config".source = ./dotfiles/dot_ssh/config;
}
