diff --git a/flake.nix b/flake.nix index 8fe5b99..fcf96a1 100644 --- a/flake.nix +++ b/flake.nix @@ -113,6 +113,9 @@ }; workstationOverlay = final: prev: { plasticity = nixpkgs.legacyPackages."x86_64-linux".callPackage ./packages/plasticity.nix { }; + toggleaudiosink = + nixpkgs.legacyPackages."x86_64-linux".callPackage ./packages/toggleaudiosink.nix + { }; }; serverOverlay = final: prev: { }; diff --git a/hosts/modules/programs.nix b/hosts/modules/programs.nix index 8d5c1b1..b8751c9 100644 --- a/hosts/modules/programs.nix +++ b/hosts/modules/programs.nix @@ -43,113 +43,96 @@ }) # Workstation specific configuration - (lib.mkIf hostType.isWorkstation ( - let - kwrite = pkgs.symlinkJoin { - name = "kwrite"; - paths = [ pkgs.kdePackages.kate ]; - postBuild = '' - rm -rf $out/bin/kate \ - $out/bin/.kate-wrapped \ - $out/share/applications/org.kde.kate.desktop \ - $out/share/man \ - $out/share/icons/hicolor/*/apps/kate.png \ - $out/share/icons/hicolor/scalable/apps/kate.svg \ - $out/share/appdata/org.kde.kate.appdata.xml - ''; + (lib.mkIf hostType.isWorkstation ({ + environment.systemPackages = with pkgs; [ + ### Dev Tools ### + bat + deploy-rs + fd + fzf + nixfmt-rfc-style + nix-init + nix-output-monitor + ripgrep + ### Internet Browsers & Communication ### + beeper + brave + nextcloud-client + tor-browser + vesktop + ### Office & Productivity ### + aspell + aspellDicts.de + aspellDicts.en + aspellDicts.en-computers + aspellDicts.pt_BR + libreoffice-qt + obsidian + (octaveFull.withPackages (octavePackages: with octavePackages; [ signal ])) + onlyoffice-desktopeditors + rnote + ### Graphics & Design ### + gimp + inkscape + orca-slicer + plasticity + ### Gaming & Entertainment ### + clonehero + heroic + mangohud + prismlauncher + protonup + ### System Utilities ### + adwaita-icon-theme + junction + kara + kde-rounded-corners + libfido2 + morewaita-icon-theme + nautilus + mission-center + p7zip + qbittorrent + quickemu + quickgui + rustdesk + steam-run + toggleaudiosink + unrar + ### Media ### + mpv + obs-studio + qview + ]; + + programs = { + adb.enable = true; + steam.enable = true; + dconf.enable = true; + nix-ld.enable = true; + kdeconnect.enable = true; + partition-manager.enable = true; + gamemode.enable = true; + appimage = { + enable = true; + binfmt = true; }; - in - { - environment.systemPackages = with pkgs; [ - ### Dev Tools ### - bat - deploy-rs - fd - fzf - nixfmt-rfc-style - nix-init - nix-output-monitor - ripgrep - ### Internet Browsers & Communication ### - beeper - brave - nextcloud-client - tor-browser - vesktop - ### Office & Productivity ### - aspell - aspellDicts.de - aspellDicts.en - aspellDicts.en-computers - aspellDicts.pt_BR - kwrite - libreoffice-qt - obsidian - (octaveFull.withPackages (octavePackages: with octavePackages; [ signal ])) - onlyoffice-desktopeditors - rnote - ### Graphics & Design ### - gimp - inkscape - orca-slicer - plasticity - ### Gaming & Entertainment ### - clonehero - heroic - mangohud - prismlauncher - protonup - ### System Utilities ### - adwaita-icon-theme - junction - kara - kde-rounded-corners - libfido2 - morewaita-icon-theme - nautilus - mission-center - p7zip - qbittorrent - quickemu - quickgui - rustdesk - steam-run - unrar - ### Media ### - mpv - obs-studio - qview + nh = { + enable = true; + flake = "/home/user/Projects/personal/nix-config"; + }; + }; + + fonts = { + fontDir.enable = true; + packages = with pkgs; [ + corefonts + inter + nerd-fonts.hack + noto-fonts-cjk-sans + roboto ]; - - programs = { - adb.enable = true; - steam.enable = true; - dconf.enable = true; - nix-ld.enable = true; - kdeconnect.enable = true; - partition-manager.enable = true; - gamemode.enable = true; - appimage = { - enable = true; - binfmt = true; - }; - nh = { - enable = true; - flake = "/home/user/Projects/personal/nix-config"; - }; - }; - - fonts = { - fontDir.enable = true; - packages = with pkgs; [ - corefonts - inter - nerd-fonts.hack - noto-fonts-cjk-sans - roboto - ]; - }; - } - )) + }; + })) ]; } diff --git a/packages/toggleaudiosink.nix b/packages/toggleaudiosink.nix new file mode 100644 index 0000000..623346f --- /dev/null +++ b/packages/toggleaudiosink.nix @@ -0,0 +1,48 @@ +{ + pkgs ? import { }, +}: + +pkgs.writeShellScriptBin "toggleaudiosink" '' + #!/usr/bin/env bash + + sound_server="pipewire" + + # Grab a count of how many audio sinks we have + sink_count=$(${pkgs.pulseaudio}/bin/pactl list sinks | grep -c "Sink #[[:digit:]]") + # Create an array of the actual sink IDs + sinks=() + mapfile -t sinks < <(${pkgs.pulseaudio}/bin/pactl list sinks | grep 'Sink #[[:digit:]]' | sed -n -e 's/.*Sink #\([[:digit:]]\)/\1/p') + # Get the ID of the active sink + active_sink_name=$(${pkgs.pulseaudio}/bin/pactl info | grep 'Default Sink:' | sed -n -e 's/.*Default Sink:[[:space:]]\+\(.*\)/\1/p') + active_sink=$(${pkgs.pulseaudio}/bin/pactl list sinks | grep -B 2 "$active_sink_name" | sed -n -e 's/Sink #\([[:digit:]]\)/\1/p' | head -n 1) + + # Get the ID of the last sink in the array + final_sink=''${sinks[$((sink_count - 1))]} + + # Find the index of the active sink + for index in "''${!sinks[@]}"; do + if [[ "''${sinks[$index]}" == "$active_sink" ]]; then + active_sink_index=$index + fi + done + + # Default to the first sink in the list + next_sink=''${sinks[0]} + next_sink_index=0 + + # If we're not at the end of the list, move up the list + if [[ $active_sink -ne $final_sink ]]; then + next_sink_index=$((active_sink_index + 1)) + next_sink=''${sinks[$next_sink_index]} + fi + + # Change the default sink + # Get the name of the next sink + next_sink_name=$(${pkgs.pulseaudio}/bin/pactl list sinks | grep -C 2 "Sink #$next_sink" | sed -n -e 's/.*Name:[[:space:]]\+\(.*\)/\1/p' | head -n 1) + ${pkgs.pulseaudio}/bin/pactl set-default-sink "$next_sink_name" + + # Move all inputs to the new sink + for app in $(${pkgs.pulseaudio}/bin/pactl list sink-inputs | sed -n -e 's/.*Sink Input #\([[:digit:]]\)/\1/p'); do + ${pkgs.pulseaudio}/bin/pactl "move-sink-input $app $next_sink" + done +''