1
0
Fork 0
mirror of https://github.com/LnL7/nix-darwin.git synced 2025-03-14 20:56:37 +00:00
nix-darwin/modules/services/math-symbols-input/default.nix
Ryan Orendorff 55b3754e21 [math-symbols-input] Symbols change after switch
Previously if you modified the `services.math-symbols.input.symbols`
dictionary, then the changes were not seen because the updates were done
without using the `UserDefaults` toolchain in macOS. Now we use
`defaults` to write the preference file to disk, which causes the cache
used by Math Symbols Input to be refreshed.
2022-12-24 12:08:55 -07:00

59 lines
1.7 KiB
Nix

{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.math-symbols-input;
package = pkgs.callPackage ./package { };
plist-base-path = "com.mathsymbolsinput.inputmethod.MathSymbolsInput.plist ";
plist-full-path = "~/Library/Preferences/${plist-base-path}";
commands-to-plist = pkgs.callPackage ./commands-to-plist.nix { };
custom-commands-plist = "${commands-to-plist cfg.symbols}/${plist-base-path}";
command-to-run = pkgs.writeScriptBin "write_defaults" ''
defaults write ${plist-full-path} "$(defaults read ${custom-commands-plist} | sed 's|\\\\|\\|g')"
'';
in {
options.services.math-symbols-input = {
enable = mkEnableOption ''
LaTeX-style mathematical symbols input method for macOS
'';
symbols = mkOption {
type = types.attrs;
default = { };
example = literalExample ''
{
"xd" = "😆";
}
'';
description = "Custom symbols to add to Math Symbols Input";
};
};
# Note that this only makes sense for homebrew
config = mkIf cfg.enable {
system.activationScripts.preActivation.text = ''
echo "Setting up Math Symbols Input"
if [ -d /Library/Input\ Methods/Math\ Symbols\ Input.app ]; then
rm /Library/Input\ Methods/Math\ Symbols\ Input.app
fi
ln -s ${package}/Math\ Symbols\ Input.app /Library/Input\ Methods/
if [ ! -f ${plist-full-path} ]; then
defaults write ${plist-full-path} CustomCommands ""
chmod 600 ${plist-full-path}
chown $SUDO_USER:staff ${plist-full-path}
fi
# Force a cache reload by writing
su - $SUDO_USER -c "${command-to-run}/bin/write_defaults"
'';
};
}