{ config, lib, pkgs, ... }@args:

let cfg = config.sydnix.users.msyds.emacs;
in {
  options.sydnix.users.msyds.emacs = {
    enable = lib.mkEnableOption ''Emacs, à la msyds'';
    userDir = lib.mkOption {
      description = ''
        The path to the Emacs user directory.
      '';
      default = "/persist/dots/modules/home/users/msyds/emacs";
      type = lib.types.path;
    };
    package = lib.mkPackageOption pkgs "emacs" {
      default = [ "emacs-pgtk" ];
    };
  };

  imports = [
    ./emacs/nix/jinx.nix
    ./emacs/nix/tufte-latex.nix
    ./emacs/nix/plex-latex.nix
    ./emacs/nix/treesit.nix
  ];

  config = lib.mkIf cfg.enable {
    sydnix.users.msyds.emacs = {
      jinx.enable = true;
      tufte-latex.enable = true;
      plex-latex.enable = true;
      treesit.enable = true;
    };

    sydnix.emacs = {
      enable = true;
      defaultEditor = true;
      inherit (cfg) userDir;
      fontPackages = [
        pkgs.julia-mono
        pkgs.nerd-fonts.victor-mono
        pkgs.ibm-plex
      ];
    };
  };
}
