grimm-nixos-laptop/modules/lilypond.nix

65 lines
1.6 KiB
Nix
Raw Normal View History

2024-04-26 10:25:17 +02:00
{ lib, config, pkgs, ... }:
let
cfg = config.grimmShared;
lily-pkg = pkgs.lilypond-with-fonts;
defaultPond = pkgs.substituteAll {
src = ./default.ly;
version = lib.getVersion lily-pkg;
};
in
{
programs.neovim = {
enable = true;
configure = {
packages.myVimPackage = with pkgs.vimPlugins; {
# loaded on launch
start = [
nvim-lilypond-suite
];
};
};
};
environment.systemPackages = with pkgs; [
lily-pkg
] ++ lib.optionals (cfg.sway.enable) [
zathura
(with lib; writeShellScriptBin "lilypond-edit" ''
if [ "$1" == "" ] || [ $# -gt 1 ]; then
echo "useage: lilypond-edit [file-path]"
exit 0
fi
if ! test -f "$1"; then
touch "$1"
cat ${defaultPond} > "$1"
fi
if ! test -f "$1"; then
echo "could not create file: $1"
exit 0
fi
pdf_path=$(echo "$1" | sed -E "s/(\.ly)?$//")
generate_cmd="lilypond --pdf -o $pdf_path -s $1"
editor_pid=$(${getExe alacritty} --command ${getExe neovim} -c "autocmd BufWritePost * :silent !$generate_cmd" $1 &> /dev/null & echo $!)
$generate_cmd
swaymsg [pid="$editor_pid"] focus
swaymsg splith
viewer_pid=$(${getExe zathura} "$pdf_path.pdf" &> /dev/null & echo $!)
sleep 1
swaymsg [pid="$editor_pid"] focus
echo "viewer pid is: $viewer_pid"
echo "editor pid is: $editor_pid"
while ps -p $viewer_pid > /dev/null && ps -p $editor_pid > /dev/null; do
sleep .1
done
kill $viewer_pid &> /dev/null
kill $editor_pid &> /dev/null
'')
];
}