2017-10-18 00:12:57 +00:00
|
|
|
{
|
|
|
|
|
2023-08-13 19:34:14 +00:00
|
|
|
config,
|
2023-11-17 09:55:53 +00:00
|
|
|
zsh,
|
2023-08-13 19:34:14 +00:00
|
|
|
|
2023-11-17 09:55:53 +00:00
|
|
|
pkgs ? (import ../pkgs.nix).edge {},
|
2017-10-18 00:12:57 +00:00
|
|
|
|
|
|
|
}: rec {
|
|
|
|
|
2023-08-13 19:34:14 +00:00
|
|
|
defaultXDGOpenRules = [
|
|
|
|
{
|
|
|
|
name = "open-url";
|
|
|
|
pattern = "(ipfs:|ipns:|magnet:|mailto:|gemini:|gopher:|https:|http:|news:|file:|git:|ssh:|ftp:)[^<>\"\\s{-}\\^⟨⟩`]+";
|
|
|
|
xdgOpen = "$1";
|
|
|
|
}
|
|
|
|
];
|
2017-10-18 00:12:57 +00:00
|
|
|
|
2023-08-13 19:34:14 +00:00
|
|
|
xdgOpenRules = defaultXDGOpenRules ++ config.alacritty.xdgOpenRules;
|
2017-10-18 00:12:57 +00:00
|
|
|
|
2024-01-06 12:29:11 +00:00
|
|
|
alacrittyUnwrap = pkgs.writeShellScript "alacritty-unwrap" ''
|
|
|
|
unset LD_LIBRARY_PATH
|
2024-01-06 13:39:30 +00:00
|
|
|
unset LIBGL_DRIVERS_PATH
|
|
|
|
unset LIBVA_DRIVERS_PATH
|
2024-01-06 12:29:11 +00:00
|
|
|
unset __EGL_VENDOR_LIBRARY_DIRS
|
|
|
|
exec "$@"
|
|
|
|
'';
|
|
|
|
|
2023-08-13 19:34:14 +00:00
|
|
|
hints = {
|
|
|
|
enabled = (builtins.map (r:
|
|
|
|
{
|
|
|
|
regex = r.pattern;
|
|
|
|
hyperlinks = true;
|
|
|
|
command = (pkgs.writeShellScript "alacritty-hints-${r.name}" ''
|
2024-01-06 12:29:11 +00:00
|
|
|
${alacrittyUnwrap} xdg-open "${r.xdgOpen}"
|
2023-08-13 19:34:14 +00:00
|
|
|
'');
|
|
|
|
post_processing = true;
|
|
|
|
mouse.enabled = true;
|
|
|
|
}
|
|
|
|
) xdgOpenRules);
|
|
|
|
};
|
2017-10-18 00:12:57 +00:00
|
|
|
|
2023-08-13 19:34:14 +00:00
|
|
|
configFile = pkgs.writeText "alacritty-config" (
|
|
|
|
builtins.replaceStrings
|
|
|
|
["$HINTS"]
|
|
|
|
[(builtins.toJSON hints)]
|
|
|
|
(builtins.readFile ./alacritty.yml)
|
|
|
|
);
|
2017-10-18 00:12:57 +00:00
|
|
|
|
2023-12-17 17:04:43 +00:00
|
|
|
shellEntrypoint = pkgs.writeShellScript "alacritty-shell-entrypoint" ''
|
2024-01-06 12:29:11 +00:00
|
|
|
exec ${alacrittyUnwrap} "${zsh}/bin/zsh" "$@"
|
2023-12-17 17:04:43 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
alacritty = pkgs.writeShellScriptBin "alacritty" ''
|
2024-01-06 13:39:30 +00:00
|
|
|
set -e -x
|
|
|
|
|
|
|
|
host_ld_lib_path="$(
|
|
|
|
ldconfig -v 2>/dev/null \
|
|
|
|
| grep -v ^$'\t' \
|
|
|
|
| tr -s ':\n' ':' \
|
|
|
|
| head -c-1 \
|
|
|
|
)"
|
|
|
|
|
|
|
|
bin_ld_lib_path="$(
|
|
|
|
objdump -x ${pkgs.alacritty}/bin/alacritty \
|
|
|
|
| grep "RUNPATH" \
|
|
|
|
| awk '{print $2}' \
|
|
|
|
)"
|
|
|
|
|
|
|
|
host_dri_path="$(
|
|
|
|
echo "$host_ld_lib_path" \
|
|
|
|
| tr -s ':' '\n' \
|
|
|
|
| while read d; do if [ -d "$d/dri" ]; then echo "$d"/dri; fi; done \
|
|
|
|
| tr '\n' ':' \
|
|
|
|
| head -c-1
|
|
|
|
)"
|
|
|
|
|
|
|
|
# overwrite LD_LIBRARY_PATH such that the binary's ld search path is still
|
|
|
|
# searched first, but afterwards the host's ld search path is looked
|
|
|
|
# through. Similarly, the dri paths are set to be the hosts. This allows us
|
|
|
|
# to use the host's graphics drivers for alacritty.
|
|
|
|
export LD_LIBRARY_PATH="$bin_ld_lib_path":"$host_ld_lib_path"
|
|
|
|
export LIBGL_DRIVERS_PATH="$host_dri_path"
|
|
|
|
export LIBVA_DRIVERS_PATH="$host_dri_path"
|
2023-12-17 17:04:43 +00:00
|
|
|
export __EGL_VENDOR_LIBRARY_DIRS=/usr/share/glvnd/egl_vendor.d
|
2023-08-13 19:34:14 +00:00
|
|
|
|
2023-12-17 17:04:43 +00:00
|
|
|
exec ${pkgs.alacritty}/bin/alacritty \
|
2023-08-13 19:34:14 +00:00
|
|
|
-o font.size=${builtins.toString config.alacritty.fontSize} \
|
|
|
|
--config-file ${configFile} \
|
2023-12-17 17:04:43 +00:00
|
|
|
-e "${shellEntrypoint}"
|
2017-10-18 00:12:57 +00:00
|
|
|
'';
|
|
|
|
}
|