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

let
  rofimoji_sway_config = pkgs.writeTextFile {
    name = "rofimoji.conf";
    text = ''
      # Emoji selector
      bindsym $mod+backslash exec ${pkgs.rofimoji}/bin/rofimoji --selector tofi
    '';
  };
in
{
  imports = [ ];

  config = lib.mkIf (config.me.graphical && config.me.sway.enable) {
    me.swayIncludes = [
      rofimoji_sway_config
    ];

    environment.persistence."/state" = lib.mkIf (config.me.mountPersistence) {
      hideMounts = true;
      users.talexander = {
        directories = [
          {
            directory = ".local/share/rofimoji";
            user = "talexander";
            group = "talexander";
            mode = "0755";
          }
        ];
      };
    };

    nixpkgs.overlays = [
      (final: prev: {
        rofimoji = pkgs.symlinkJoin {
          name = prev.rofimoji.name;
          paths = [ prev.rofimoji ];
          nativeBuildInputs = [ pkgs.makeWrapper ];
          postBuild = ''
            wrapProgram $out/bin/rofimoji --prefix PATH : ${
              lib.makeBinPath [
                final.tofi
              ]
            }
          '';
        };
      })
      (final: prev: {
        tofi = pkgs.symlinkJoin {
          name = "tofi";
          paths = [ prev.tofi ];
          buildInputs = [ pkgs.makeWrapper ];
          postBuild = ''
            wrapProgram $out/bin/tofi-drun --add-flags --font=${pkgs.source-sans-pro}/share/fonts/opentype/SourceSansPro-Regular.otf --add-flags --config=${./files/tofi-config}
            wrapProgram $out/bin/tofi --add-flags --config=${./files/tofi-config}
          '';
        };
      })
    ];
  };
}
