hex/nix/hm-module.nix
Dax Raad dfa2d852b8 feat(linux): one Hex process with the window in-process
The Linux host, the single-instance socket, the HUD, and the window run in
one process. A relaunch forwards Activate with the launcher's activation
token; hex dictation, voice-action, paste-last, status, and quit forward
over the same socket, and shortcut commands go straight to the listener.
Without an instance a launch starts the managed unit (Type=notify) or
becomes Hex. The Rune window is the default on rune-ui builds and talks to
the host directly; GPUI stays behind --ui gpui. Quit Hex lives in the
sidebar.
2026-10-22 14:46:49 -04:00

69 lines
2 KiB
Nix

{
config,
lib,
pkgs,
...
}:
let
cfg = config.programs.hex;
waitForSession = pkgs.writeShellApplication {
name = "hex-wait-for-session";
runtimeInputs = [
pkgs.coreutils
pkgs.gnugrep
pkgs.xprop
];
text = builtins.readFile ./wait-for-session.sh;
};
in
{
options.programs.hex = {
enable = lib.mkEnableOption "HEX local voice dictation";
package = lib.mkOption {
type = lib.types.package;
description = "HEX package to install.";
};
autostart = lib.mkEnableOption "HEX startup with the graphical session";
systemdTarget = lib.mkOption {
type = lib.types.str;
default = "graphical-session.target";
example = "sway-session.target";
description = ''
User target that owns the graphical session. The compositor or session
manager must import its display environment before starting this target,
and stop the target at logout. This module does not start a session.
'';
};
};
config = lib.mkIf cfg.enable {
assertions = [
{
assertion = pkgs.stdenv.hostPlatform.system == "x86_64-linux";
message = "The HEX Nix package supports x86_64-linux only.";
}
];
home.packages = [ cfg.package ];
systemd.user.services.hex = {
Unit = {
Description = "HEX local voice dictation";
After = [ cfg.systemdTarget ];
PartOf = [ cfg.systemdTarget ];
};
Service = {
Type = "notify";
NotifyAccess = "main";
ExecStartPre = lib.getExe waitForSession;
ExecStart = "${lib.getExe cfg.package} service";
Environment = [ "HEX_APPLICATION_SUPPORT_DIR=${config.xdg.dataHome}/voice-control" ];
EnvironmentFile = "-${config.xdg.dataHome}/voice-control/session.env";
TimeoutStartSec = 35;
Restart = "on-failure";
RestartSec = 5;
TimeoutStopSec = 30;
UMask = "0077";
};
Install.WantedBy = lib.optionals cfg.autostart [ cfg.systemdTarget ];
};
};
}