summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2023-01-11 17:14:19 +0100
committertv <tv@krebsco.de>2023-01-11 17:23:48 +0100
commit48f91cbeb1b6bfd751cc7ed26ddee2fcf97a4f99 (patch)
tree9460123d115c0ece0ca6c1d35d9652fb73595c58
parentab8139704a331b88d72d533ac4206464ae069f7c (diff)
tv alacritty: add support for multiple profiles
-rw-r--r--tv/5pkgs/simple/alacritty-tv.nix46
1 files changed, 38 insertions, 8 deletions
diff --git a/tv/5pkgs/simple/alacritty-tv.nix b/tv/5pkgs/simple/alacritty-tv.nix
index fd4dec9ec..f66bcdc0b 100644
--- a/tv/5pkgs/simple/alacritty-tv.nix
+++ b/tv/5pkgs/simple/alacritty-tv.nix
@@ -6,7 +6,7 @@ let
program = "${pkgs.font-size-alacritty}/bin/font-size-alacritty";
args = [arg];
};
- config = {
+ configs.default = {
bell.animation = "EaseOut";
bell.duration = 50;
bell.color = "#ff00ff";
@@ -50,16 +50,31 @@ let
];
scrolling.multiplier = 8;
};
- config-file = pkgs.writeJSON "alacritty-tv.json" config;
- profile = pkgs.writeText "alacritty-tv.profile" /* sh */ ''
+ writeProfile = name: config: let
+ config-file =
+ assert lib.types.filename.check name;
+ pkgs.writeJSON "alacritty-tv-${name}.json" config;
+ in pkgs.writeText "alacritty-tv-${name}.profile" /* sh */ ''
# Use home so Alacritty can find the configuration without arguments.
# HOME will be reset once in Alacritty.
- HOME=$TMPDIR/Alacritty
+ HOME=$TMPDIR/Alacritty-${name}
export HOME
+ # Tell Alacritty via XDG_RUNTIME_DIR where to create sockets.
+ # XDG_RUNTIME_DIR needs to be reset manually.
+ export ALACRITTY_XDG_RUNTIME_DIR="$XDG_RUNTIME_DIR"
+ export BASH_EXTRA_INIT=${pkgs.writeDash "alacritty-tv.cleanup.sh" ''
+ XDG_RUNTIME_DIR=$ALACRITTY_XDG_RUNTIME_DIR
+ unset ALACRITTY_XDG_RUNTIME_DIR
+ unset BASH_EXTRA_INIT
+ ''}
+ export XDG_RUNTIME_DIR="$HOME"
+
# Install stored configuration if it has changed.
# This allows for both declarative updates and runtime modifications.
- ${pkgs.coreutils}/bin/mkdir -p "$HOME"
+ # rust-xdg requires XDG_RUNTIME_DIR to be secure:
+ # https://docs.rs/xdg/2.4.1/src/xdg/lib.rs.html#311
+ ${pkgs.coreutils}/bin/mkdir -m 0700 -p "$HOME"
if test "$(${pkgs.coreutils}/bin/cat "$HOME"/ref)" != ${config-file}; then
echo ${config-file} > "$HOME"/ref
${pkgs.coreutils}/bin/cp ${config-file} "$HOME"/.alacritty.yml
@@ -72,20 +87,35 @@ pkgs.symlinkJoin {
paths = [
(pkgs.writeDashBin "alacritty" ''
# usage:
- # alacritty [--singleton] [ARGS...]
+ # alacritty [--profile=PROFILE] [--singleton] [ARGS...]
+ # where
+ # PROFILE one of ${lib.toJSON (lib.attrNames configs)}
set -efu
case ''${1-} in
+ ${lib.concatMapStringsSep "\n" (name: /* sh */ ''
+ --${lib.shell.escape name}|--profile=${lib.shell.escape name})
+ shift
+ profile=${writeProfile name configs.${name}}
+ ;;
+ '') (lib.attrNames configs)}
+ *)
+ profile=${writeProfile "default" configs.default}
+ ;;
+ esac
+
+
+ case ''${1-} in
--singleton)
shift
if ! ${pkgs.alacritty}/bin/alacritty msg create-window "$@"; then
- . ${profile}
+ . "$profile"
${pkgs.alacritty}/bin/alacritty "$@" &
fi
;;
*)
- . ${profile}
+ . "$profile"
exec ${pkgs.alacritty}/bin/alacritty "$@"
;;
esac