From 2a1acc6285732b389559d90c9983a977bf581a21 Mon Sep 17 00:00:00 2001 From: LordGrimmauld Date: Fri, 26 Apr 2024 21:36:24 +0200 Subject: [PATCH] rework lilypond and nvim --- common/laptop_hardware.nix | 1 + common/network/bluetooth.nix | 4 +- common/sound/default.nix | 9 +-- common/sound/midi.nix | 23 +++++++ common/sound/spotify.nix | 2 +- common/sound/spotifyd.nix | 7 +- .../{toolchains.nix => tooling/default.nix} | 67 +++++++++++++------ common/tooling/lilypond.nix | 49 ++++++++++++++ common/tooling/lsiommu | 5 ++ configuration.nix | 7 +- load_common.nix | 2 +- modules/lilypond.nix | 64 ------------------ modules/users.nix | 1 + 13 files changed, 145 insertions(+), 96 deletions(-) create mode 100644 common/sound/midi.nix rename common/{toolchains.nix => tooling/default.nix} (69%) create mode 100644 common/tooling/lilypond.nix create mode 100755 common/tooling/lsiommu delete mode 100644 modules/lilypond.nix diff --git a/common/laptop_hardware.nix b/common/laptop_hardware.nix index 3fc7a40..edf4385 100644 --- a/common/laptop_hardware.nix +++ b/common/laptop_hardware.nix @@ -109,3 +109,4 @@ in }; } + diff --git a/common/network/bluetooth.nix b/common/network/bluetooth.nix index 093d350..2bc1edc 100644 --- a/common/network/bluetooth.nix +++ b/common/network/bluetooth.nix @@ -8,9 +8,9 @@ in environment.systemPackages = with pkgs; [ bluetuith - ] ++ lib.optional sound pkgs.bluez; + ] ++ lib.optional sound.enable pkgs.bluez; - systemd.user.services.mpris-proxy = lib.mkIf sound { + systemd.user.services.mpris-proxy = lib.mkIf sound.enable { description = "Mpris proxy"; after = [ "network.target" "sound.target" ]; wantedBy = [ "default.target" ]; diff --git a/common/sound/default.nix b/common/sound/default.nix index a721b86..6125046 100644 --- a/common/sound/default.nix +++ b/common/sound/default.nix @@ -3,7 +3,7 @@ let cfg = config.grimmShared; in { - config = with cfg; lib.mkIf (enable && sound) { + config = with cfg; lib.mkIf (enable && sound.enable) { sound.enable = true; hardware.pulseaudio.enable = false; @@ -26,11 +26,8 @@ in imports = [ ./spotify.nix + ./midi.nix ]; - options.grimmShared.sound = with lib; mkOption { - type = types.bool; - default = false; - description = "whether to enable sound"; - }; + options.grimmShared.sound.enable = lib.mkEnableOption "whether to enable sound"; } diff --git a/common/sound/midi.nix b/common/sound/midi.nix new file mode 100644 index 0000000..7f0a1e8 --- /dev/null +++ b/common/sound/midi.nix @@ -0,0 +1,23 @@ +{ config, lib, pkgs, ... }: +let + cfg = config.grimmShared; + sound_font = pkgs.soundfont-fluid; +in +{ + config = with cfg; lib.mkIf (enable && sound.midi) { + environment.systemPackages = with pkgs; [ + mpv + timidity + ffmpeg-full + sound_font + ]; + + environment.pathsToLink = [ + "/share/soundfonts" + ]; + + environment.etc."timidity/timidity.cfg".text = "soundfont ${sound_font}/share/soundfonts/FluidR3_GM2-2.sf2"; + }; + + options.grimmShared.sound.midi = lib.mkEnableOption "enable midi"; +} diff --git a/common/sound/spotify.nix b/common/sound/spotify.nix index cf0b5f4..2da09b4 100644 --- a/common/sound/spotify.nix +++ b/common/sound/spotify.nix @@ -9,7 +9,7 @@ in ] ++ lib.optional graphical pkgs.spotify; grimmShared = { - sound = true; + sound.enable = true; network = true; }; }; diff --git a/common/sound/spotifyd.nix b/common/sound/spotifyd.nix index f95be45..8966fb4 100644 --- a/common/sound/spotifyd.nix +++ b/common/sound/spotifyd.nix @@ -22,7 +22,7 @@ let ''; in { - config = with cfg; lib.mkIf (enable && spotify.enable && spotify.spotifyd.enable) { + config = with cfg; lib.mkIf (enable && spotify.spotifyd.enable) { environment.systemPackages = with pkgs; [ spotifyd spotifyd-dbus @@ -39,6 +39,11 @@ in ''; }; + grimmShared = { + sound.enable = true; + network = true; + }; + services.pipewire.systemWide = true; # required for spotifyd as spotifyd runs as the spotifyd user # spotifyd config diff --git a/common/toolchains.nix b/common/tooling/default.nix similarity index 69% rename from common/toolchains.nix rename to common/tooling/default.nix index d4501c4..65cb9df 100644 --- a/common/toolchains.nix +++ b/common/tooling/default.nix @@ -3,14 +3,22 @@ let cfg = config.grimmShared; in { + imports = [ + ./lilypond.nix + ]; + config = with cfg; lib.mkIf (enable && tooling.enable) { environment.systemPackages = with pkgs; [ (writeShellScriptBin "silent-add" "git add --intent-to-add $@ ; git update-index --assume-unchanged $@") (writeShellScriptBin "systemd-owner" "systemctl show -pUser,UID $@") (writeShellScriptBin "nix-referrers" "nix-store --query --referrers $@") (writeShellScriptBin "nixpkgs-review-head" "nixpkgs-review rev HEAD") + (writeShellScriptBin "fmt-all" "find ./**.nix -readable -writable -type f | xargs nixpkgs-fmt") + (writeShellScriptBin "lsiommu" ./lsiommu) + nixpkgs-review nixpkgs-fmt + nixd gcc jdk17 python3 @@ -32,7 +40,6 @@ in pypy3 util-linux visualvm - ffmpeg-full imagemagick nmap @@ -44,6 +51,8 @@ in inputs.hammering.packages."${system}".default nix-output-monitor expect + + neovim-remote ] ++ lib.optionals cfg.graphical [ qdirstat libva-utils @@ -77,30 +86,36 @@ in # virtualisation.docker.enable = true; + grimmShared.tooling.nvim.plugins = with pkgs.vimPlugins; [ + vim-nix + vim-scala + fugitive + ]; + programs.neovim = { enable = true; viAlias = true; defaultEditor = true; configure = { - customRC = '' - set number - set hidden - set fileencodings=utf-8 - set nocompatible - set clipboard+=unnamedplus - if filereadable($HOME . "/.vimrc") - source ~/.vimrc - endif - ''; - packages.myVimPackage = with pkgs.vimPlugins; { - # loaded on launch - start = [ - vim-nix - vim-scala - fugitive - ]; + customRC = + let + luarc = pkgs.writeText "init.lua" (lib.concatLines tooling.nvim.extraLuaRC); + in + '' + set number + set hidden + set fileencodings=utf-8 + set nocompatible + set clipboard+=unnamedplus - # manually loadable by calling `:packadd $plugin-name` + luafile ${luarc} + + if filereadable($HOME . "/.vimrc") + source ~/.vimrc + endif + ''; + packages.myVimPackage = { + start = tooling.nvim.plugins; opt = [ ]; }; }; @@ -124,6 +139,20 @@ in options.grimmShared.tooling = with lib; { enable = mkEnableOption "grimm-tooling"; + nvim = { + plugins = mkOption { + type = types.listOf types.package; + default = [ ]; + description = "Extra vim plugins to include"; + }; + + extraLuaRC = mkOption { + type = types.listOf types.nonEmptyStr; + default = [ ]; + description = "Extra init LUA scripts"; + }; + }; + pass = mkOption { type = types.bool; default = true; diff --git a/common/tooling/lilypond.nix b/common/tooling/lilypond.nix new file mode 100644 index 0000000..9b75c11 --- /dev/null +++ b/common/tooling/lilypond.nix @@ -0,0 +1,49 @@ +{ lib, pkgs, config, ... }: +let + cfg = config.grimmShared; + viewer_pkg = pkgs.zathura; + viewer_def = lib.optionalString cfg.graphical ''pdf_viewer = "${lib.getExe pkgs.zathura}",''; +in +{ + config = with cfg; lib.mkIf (enable && tooling.enable && tooling.lilypond) { + environment.systemPackages = with pkgs; [ + lilypond-with-fonts + ] ++ lib.optional graphical viewer_pkg; + environment.sessionVariables = { + LYEDITOR = "${lib.getExe pkgs.neovim-remote} -s +:'dr %(file)s | call cursor(%(line)s,%(char)s+1)'"; + }; + + grimmShared.sound.midi = true; + + grimmShared.tooling.nvim = { + extraLuaRC = lib.singleton '' + require('nvls').setup({ + lilypond = { + options = { + ${viewer_def} + }, + }, + latex = { + options = { + ${viewer_def} + }, + }, + player = { + options = { + fluidsynth_flags = { + "/run/current-system/sw/share/soundfonts/FluidR3_GM2-2.sf2" + } + } + } + }) + ''; + }; + + grimmShared.tooling.nvim.plugins = with pkgs.vimPlugins; [ + nvim-lilypond-suite + ]; + }; + + options.grimmShared.tooling.lilypond = lib.mkEnableOption "enable lilypond tooling"; + +} diff --git a/common/tooling/lsiommu b/common/tooling/lsiommu new file mode 100755 index 0000000..b445ed7 --- /dev/null +++ b/common/tooling/lsiommu @@ -0,0 +1,5 @@ +for d in $(find /sys/kernel/iommu_groups/ -type l | sort -n -k5 -t/); do + n=${d#*/iommu_groups/*}; n=${n%%/*} + printf 'IOMMU Group %s ' "$n" + lspci -nns "${d##*/}" +done; diff --git a/configuration.nix b/configuration.nix index 936f158..d443762 100644 --- a/configuration.nix +++ b/configuration.nix @@ -5,7 +5,6 @@ # Include the results of the hardware scan. ./modules/fonts.nix ./modules/tabletdriver.nix - ./modules/lilypond.nix ./sway ]; @@ -27,8 +26,12 @@ network = true; tooling = { enable = true; + lilypond = true; + }; + sound = { + enable = true; + midi = true; }; - sound = true; graphical = true; firefox = { enable = true; diff --git a/load_common.nix b/load_common.nix index 5240d10..680c376 100644 --- a/load_common.nix +++ b/load_common.nix @@ -10,7 +10,7 @@ with lib; ./common/printing.nix ./common/portals.nix ./common/network - ./common/toolchains.nix + ./common/tooling ./common/sound ./common/graphics ./common/gaming.nix diff --git a/modules/lilypond.nix b/modules/lilypond.nix deleted file mode 100644 index 4e8b507..0000000 --- a/modules/lilypond.nix +++ /dev/null @@ -1,64 +0,0 @@ -{ 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 - '') - ]; - -} diff --git a/modules/users.nix b/modules/users.nix index 5e5ab2e..d6babfd 100644 --- a/modules/users.nix +++ b/modules/users.nix @@ -37,6 +37,7 @@ kcalc rmview krita + weasis kicad prusa-slicer freecad