{
  config,
  pkgs,
  lib,
  ...
}:
let
  cfg = config.alqueva.shells.xonsh;
  aliasesToPyDict =
    aliases: lib.concatStringsSep "\n" (lib.mapAttrsToList (k: v: "aliases['${k}'] = '${v}'") aliases);
in
{
  options.alqueva.shells.xonsh = {
    enable = lib.mkEnableOption "xonsh";
    package = lib.mkPackageOption pkgs "xonsh" { };
  };

  config = lib.mkIf cfg.enable {
    programs = {
      xonsh = {
        config = ''
          from xonsh.xontribs import get_xontribs

          ${aliasesToPyDict config.environment.shellAliases}

          for xontrib in get_xontribs():
              xontrib load @(xontrib)
        '';
        inherit (cfg) package;
        enable = true;
      };
    };
  };
}
