# HM side of the flake; option tree is `chiasson.home.*` (docs/conventions.md).
{ self, inputs, ... }: {
  # Root module: chiasson.home.enable + git identity. Other `wisdom*` slices (including
  # the bash shell) auto-wire via `lib.wisdomCatalogExtraModules`; hosts flip
  # `chiasson.home.*.enable` rather than re-importing.
  flake.homeManagerModules.wisdom =
    { config, lib, pkgs, ... }:
    let
      cfg = config.chiasson.home;
    in
    {
      options.chiasson.home = {
        enable =
          lib.mkEnableOption ''
            HM profile root for this flake (bash on by default). Desktop hosts use
            `lib.wisdomCatalogExtraModules` once per user and flip `chiasson.home.*.enable` on the host.
          ''
          // {
            default = true;
          };

        extraPackages = lib.mkOption {
          type = lib.types.listOf lib.types.package;
          default = [ ];
          description = ''
            Extra `home.packages` (e.g. `pkgs.parsec-bin`) when you do not want a separate wisdom module.
          '';
        };
      };

      config = lib.mkIf cfg.enable (
        lib.mkMerge [
          { home.packages = cfg.extraPackages; }

          # Base git identity + encryption/player tools shared by every HM user.
          {
            programs.git = {
              enable = true;
              settings.user = {
                name = "OlivierChiasson";
                email = "olivierchiasson@hotmail.fr";
              };
            };
            home.packages = [
              pkgs.git-crypt
              pkgs.feishin
            ];
          }
        ]
      );
    };
}
