From f77b8a5fda481b55a4b2bab64d0c85113c5f5a2d Mon Sep 17 00:00:00 2001 From: Patrick Date: Mon, 19 Aug 2024 15:45:08 +0200 Subject: [PATCH] feat: add streamdeck succesor --- hosts/desktopnix/default.nix | 10 +- pkgs/default.nix | 35 +++--- pkgs/streamcontroller.nix | 218 +++++++++++++++++++++++++++++++++++ pkgs/usb-monitor.nix | 29 +++++ users/patrick/streamdeck.nix | 2 +- 5 files changed, 276 insertions(+), 18 deletions(-) create mode 100644 pkgs/streamcontroller.nix create mode 100644 pkgs/usb-monitor.nix diff --git a/hosts/desktopnix/default.nix b/hosts/desktopnix/default.nix index 169583f..4079e7b 100644 --- a/hosts/desktopnix/default.nix +++ b/hosts/desktopnix/default.nix @@ -1,4 +1,9 @@ -{ inputs, lib, ... }: +{ + inputs, + lib, + pkgs, + ... +}: { imports = [ inputs.nixos-hardware.nixosModules.common-gpu-nvidia-nonprime @@ -73,4 +78,7 @@ nixpkgs.hostPlatform = "x86_64-linux"; nixpkgs.config.cudaSupport = true; + + environment.systemPackages = [ pkgs.streamlink ]; + services.udev.packages = [ pkgs.streamlink ]; } diff --git a/pkgs/default.nix b/pkgs/default.nix index 507b53b..b989b15 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -1,18 +1,18 @@ [ (import ./scripts) - (_prev: final: { - zsh-histdb-skim = final.callPackage ./zsh-histdb-skim.nix { }; - zsh-histdb = final.callPackage ./zsh-histdb.nix { }; - actual = final.callPackage ./actual.nix { }; - pr-tracker = final.callPackage ./pr-tracker.nix { }; - homebox = final.callPackage ./homebox.nix { }; - deploy = final.callPackage ./deploy.nix { }; - minion = final.callPackage ./minion.nix { }; - mongodb-bin = final.callPackage ./mongodb-bin.nix { }; - awakened-poe-trade = final.callPackage ./awakened-poe-trade.nix { }; - neovim-clean = final.neovim-unwrapped.overrideAttrs ( + (_final: prev: { + zsh-histdb-skim = prev.callPackage ./zsh-histdb-skim.nix { }; + zsh-histdb = prev.callPackage ./zsh-histdb.nix { }; + actual = prev.callPackage ./actual.nix { }; + pr-tracker = prev.callPackage ./pr-tracker.nix { }; + homebox = prev.callPackage ./homebox.nix { }; + deploy = prev.callPackage ./deploy.nix { }; + minion = prev.callPackage ./minion.nix { }; + mongodb-bin = prev.callPackage ./mongodb-bin.nix { }; + awakened-poe-trade = prev.callPackage ./awakened-poe-trade.nix { }; + neovim-clean = prev.neovim-unwrapped.overrideAttrs ( _neovimFinal: neovimPrev: { - nativeBuildInputs = (neovimPrev.nativeBuildInputs or [ ]) ++ [ final.makeWrapper ]; + nativeBuildInputs = (neovimPrev.nativeBuildInputs or [ ]) ++ [ prev.makeWrapper ]; postInstall = (neovimPrev.postInstall or "") + '' @@ -20,7 +20,7 @@ ''; } ); - path-of-building = final.path-of-building.overrideAttrs (old: { + path-of-building = prev.path-of-building.overrideAttrs (old: { postFixup = (old.postFixup or "") + '' @@ -28,10 +28,10 @@ --set QT_QPA_PLATFORM xcb ''; }); - kanidm = final.kanidm.overrideAttrs ( + kanidm = prev.kanidm.overrideAttrs ( old: let - provisionSrc = final.fetchFromGitHub { + provisionSrc = prev.fetchFromGitHub { owner = "oddlama"; repo = "kanidm-provision"; rev = "v1.1.0"; @@ -47,6 +47,9 @@ doCheck = false; } ); - kanidm-provision = final.callPackage ./kanidm-provision.nix { }; + kanidm-provision = prev.callPackage ./kanidm-provision.nix { }; + pythonPackagesExtension = prev.pythonPackagesExtension ++ [ + (_pythonFinal: pythonPrev: { usb-monitor = pythonPrev.callPackage ./usb-monitor.nix { }; }) + ]; }) ] diff --git a/pkgs/streamcontroller.nix b/pkgs/streamcontroller.nix new file mode 100644 index 0000000..fbb5083 --- /dev/null +++ b/pkgs/streamcontroller.nix @@ -0,0 +1,218 @@ +{ + stdenv, + lib, + python3Packages, + fetchFromGitHub, + copyDesktopItems, + makeDesktopItem, + wrapGAppsHook4, + gobject-introspection, + libadwaita, + libportal, + libportal-gtk4, + xdg-desktop-portal, + xdg-desktop-portal-gtk, +}: +let + streamcontroller-plugin-tools = python3Packages.buildPythonPackage rec { + pname = "streamcontroller-plugin-tools"; + version = "2.0.0"; + + src = fetchFromGitHub { + owner = "StreamController"; + repo = "streamcontroller-plugin-tools"; + rev = version; + hash = "sha256-dQZPRSzHhI3X+Pf7miwJlECGFgUfp68PtvwXAmpq5/s="; + }; + + dependencies = with python3Packages; [ + loguru + rpyc + ]; + + pythonImportsCheck = [ "streamcontroller_plugin_tools" ]; + + meta = with lib; { + description = "StreamController plugin tools"; + homepage = "https://github.com/StreamController/streamcontroller-plugin-tools"; + license = licenses.gpl3; + maintainers = with maintainers; [ sifmelcara ]; + platforms = lib.platforms.linux; + }; + }; +in +stdenv.mkDerivation rec { + name = "streamcontroller"; + + # Note that the latest tagged version (1.5.0-beta.6) includes a python dependency + # that doesn't exist anymore, so we package an unstable version instead. + version = "0-unstable-2024-08-13"; + + src = fetchFromGitHub { + repo = "StreamController"; + owner = "StreamController"; + rev = "dbb6460a69137af192db09d504224ae9f1127cbd"; + hash = "sha256-+YYzHLRU5MNjF3iaKIDj9k4PVg+vnEZhbc3ZmNI7xyw="; + }; + + # The installation method documented upstream + # (https://streamcontroller.github.io/docs/latest/installation/) is to clone the repo, + # run `pip install`, then run `python3 main.py` to launch the program. + # Due to how the code is structured upstream, it's infeasible to use `buildPythonApplication`. + + dontBuild = true; + installPhase = '' + runHook preInstall + + mkdir -p $out/bin/ + + cat << EOF > $out/bin/streamcontroller + #!/usr/bin/env bash + + # Note that the implementation of main.py assumes + # working directory to be at the root of the project's source code + cd ${src} + ${python3Packages.python}/bin/python main.py + + EOF + chmod +x $out/bin/streamcontroller + + wrapProgram $out/bin/streamcontroller --prefix PYTHONPATH : "$PYTHONPATH" + + # Install udev rules + mkdir -p "$out/etc/udev/rules.d" + cp ${src}/udev.rules $out/etc/udev/rules.d/70-streamcontroller.rules + + runHook postInstall + ''; + + desktopItems = [ + (makeDesktopItem { + name = "StreamController"; + desktopName = "StreamController"; + exec = "streamcontroller"; + icon = "${src}/flatpak/icon_256.png"; + categories = [ "Application" ]; + }) + ]; + + nativeBuildInputs = [ + copyDesktopItems + wrapGAppsHook4 + ]; + + buildInputs = + [ + gobject-introspection + libadwaita + libportal + libportal-gtk4 + xdg-desktop-portal + xdg-desktop-portal-gtk + ] + ++ (with python3Packages; [ + annotated-types + async-lru + cairocffi + cairosvg + certifi + cffi + charset-normalizer + click + colorama + contourpy + cssselect2 + cycler + dbus-python + decorator + defusedxml + distlib + dnspython + evdev + filelock + fonttools + fuzzywuzzy + gcodepy + get-video-properties + gitdb + idna + imageio + imageio-ffmpeg + indexed-bzip2 + jinja2 + joblib + kiwisolver + levenshtein + linkify-it-py + loguru + markdown-it-py + markupsafe + matplotlib + mdit-py-plugins + mdurl + meson + meson-python + natsort + nltk + numpy + opencv4 + packaging + pillow + platformdirs + plumbum + proglog + psutil + pulsectl + pycairo + pyclip + pycparser + pydantic + pydantic-core + pyenchant + pygments + pygobject3 + pymongo + pyparsing + pyperclip + pyproject-metadata + pyro5 + pyspellchecker + python-dateutil + pyudev + pyusb + pyyaml + rapidfuzz + regex + requests + requirements-parser + rich + rpyc + serpent + setproctitle + setproctitle + six + smmap + speedtest-cli + streamcontroller-plugin-tools + streamdeck + textual + tinycss2 + tqdm + types-setuptools + typing-extensions + uc-micro-py + urllib3 + usb-monitor + webencodings + websocket-client + ]); + + meta = with lib; { + description = "An elegant Linux app for the Elgato Stream Deck with support for plugins"; + homepage = "https://core447.com/"; + license = licenses.gpl3; + mainProgram = "streamcontroller"; + maintainers = with maintainers; [ sifmelcara ]; + platforms = lib.platforms.linux; + }; +} diff --git a/pkgs/usb-monitor.nix b/pkgs/usb-monitor.nix new file mode 100644 index 0000000..d47166b --- /dev/null +++ b/pkgs/usb-monitor.nix @@ -0,0 +1,29 @@ +{ + buildPythonPackage, + fetchPypi, + lib, + python3Packages, +}: + +buildPythonPackage rec { + pname = "usb-monitor"; + version = "1.21"; + + src = fetchPypi { + inherit version; + pname = "usb_monitor"; + hash = "sha256-M+BUmbNxQWcULFECexTnp55EZiJ6y3bYCEtSwqKldAk="; + }; + + dependencies = [ python3Packages.pyudev ]; + + pythonImportsCheck = [ "usbmonitor" ]; + + meta = { + description = "Cross-platform library for USB device monitoring"; + homepage = "https://github.com/Eric-Canas/USBMonitor"; + license = lib.licenses.mit; + maintainers = with lib.maintainers; [ sifmelcara ]; + platforms = lib.platforms.linux; + }; +} diff --git a/users/patrick/streamdeck.nix b/users/patrick/streamdeck.nix index 4da9a45..1322e4a 100644 --- a/users/patrick/streamdeck.nix +++ b/users/patrick/streamdeck.nix @@ -1,7 +1,7 @@ { config, ... }: { programs.streamdeck-ui = { - enable = true; + #enable = true; settings = { # Device ID "AL31H1B01852" = {