From fd6dd387a04c2507e00fe27848d9b1a9bbe649f7 Mon Sep 17 00:00:00 2001 From: Tim Keller Date: Sat, 6 Dec 2025 17:43:46 -0600 Subject: decklink --- hosts/optiplex/configuration.nix | 8 ++ nixos/decklink.nix | 29 +++++ nixos/default.nix | 1 + pkgs/blackmagic-desktop-video/default.nix | 195 ++++++++++++++++++++++++++++++ 4 files changed, 233 insertions(+) create mode 100644 nixos/decklink.nix create mode 100644 pkgs/blackmagic-desktop-video/default.nix diff --git a/hosts/optiplex/configuration.nix b/hosts/optiplex/configuration.nix index f3b0f2a..7c2298e 100644 --- a/hosts/optiplex/configuration.nix +++ b/hosts/optiplex/configuration.nix @@ -52,6 +52,8 @@ # Allow unfree for nvidia + others nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [ + "blackmagic-desktop-video" + "decklink" "nvidia-x11" "nvidia-settings" "spotify" @@ -75,6 +77,10 @@ forceFullCompositionPipeline = true; # Enables vsync }; + # Enable decklink support for intensity pro + services._decklink.enable = true; + services._decklink.decklinkSupport.enable = true; + # Configure home home-manager.users.timmy = { gtk._mintTheme = { @@ -85,5 +91,7 @@ programs._seasonalwallpaper.wallpapers.download = true; }; + networking.firewall.allowedTCPPorts = [ 8080 8081 ]; + system.stateVersion = "24.11"; } diff --git a/nixos/decklink.nix b/nixos/decklink.nix new file mode 100644 index 0000000..4618975 --- /dev/null +++ b/nixos/decklink.nix @@ -0,0 +1,29 @@ +{ config, lib, pkgs, ... }: let + cfg = config.services._decklink; +in { + options.services._decklink = { + enable = lib.mkEnableOption "enables decklink support"; + decklinkSupport.enable = lib.mkEnableOption "enable decklinkSupport flag for all packages that support it by default"; + }; + + config = lib.mkIf cfg.enable { + #assertions = [ + # { + # assertion = config.nixpkgs.config.allowUnfree or false; + # message = "Must allow unfree pkgs to use the decklink module"; + # } + #]; + + # Kernel modules + hardware.decklink.enable = true; + + # DesktopVideoHelper + environment.systemPackages = [ pkgs.blackmagic-desktop-video ]; + + # Enable decklinkSupport flag globally for all packages that support it (e.g. obs) + nixpkgs.overlays = [ + (final: prev: { decklinkSupport = cfg.decklinkSupport.enable; }) + ]; + }; +} + diff --git a/nixos/default.nix b/nixos/default.nix index e934431..9f297e2 100644 --- a/nixos/default.nix +++ b/nixos/default.nix @@ -9,6 +9,7 @@ ./services/searxng.nix ./bootloader.nix + ./decklink.nix ./doas.nix ./filesystems.nix ./geoclue.nix diff --git a/pkgs/blackmagic-desktop-video/default.nix b/pkgs/blackmagic-desktop-video/default.nix new file mode 100644 index 0000000..5c7a541 --- /dev/null +++ b/pkgs/blackmagic-desktop-video/default.nix @@ -0,0 +1,195 @@ +{ + autoPatchelfHook, + cacert, + common-updater-scripts, + curl, + gcc, + jq, + lib, + libGL, + + desktopVideoFull ? false, + + # whether to include firmware update tool + desktopVideoUpdater ? desktopVideoFull, + libusb1, + + # whether to include gui applications as well + desktopVideoGUI ? desktopVideoFull, + dbus, + fontconfig, + freetype, + glib, + libICE, + libXrender, + qt5, + libcxx, + runCommandLocal, + stdenv, + writeShellApplication, +}: + +stdenv.mkDerivation (finalAttrs: { + pname = "blackmagic-desktop-video"; + version = "15.1"; + + buildInputs = [ + autoPatchelfHook + libcxx + libGL + gcc.cc.lib + ] + ++ lib.optionals desktopVideoUpdater [ + libusb1 + ] + ++ lib.optionals desktopVideoGUI [ + dbus + fontconfig + freetype + glib + libICE + libXrender + qt5.qtbase + ]; + nativeBuildInputs = lib.optionals desktopVideoGUI [ qt5.wrapQtAppsHook ]; + + # yes, the below download function is an absolute mess. + # blame blackmagicdesign. + src = + runCommandLocal "${finalAttrs.pname}-${lib.versions.majorMinor finalAttrs.version}-src.tar.gz" + { + outputHashMode = "recursive"; + outputHashAlgo = "sha256"; + outputHash = "sha256-nZXfUbUyk9PDhBeXUHGt6T95hfMMDEH1oOgcm1wwi3E="; + + impureEnvVars = lib.fetchers.proxyImpureEnvVars; + + nativeBuildInputs = [ + curl + jq + ]; + + # ENV VARS + SSL_CERT_FILE = "${cacert}/etc/ssl/certs/ca-bundle.crt"; + + DOWNLOADSURL = "https://www.blackmagicdesign.com/api/support/us/downloads.json"; + + USERAGENT = builtins.concatStringsSep " " [ + "User-Agent: Mozilla/5.0 (X11; Linux ${stdenv.hostPlatform.linuxArch})" + "AppleWebKit/537.36 (KHTML, like Gecko)" + "Chrome/77.0.3865.75" + "Safari/537.36" + ]; + + REQJSON = builtins.toJSON { + "country" = "nl"; + "downloadOnly" = true; + "platform" = "Linux"; + "policy" = true; + }; + + PRODUCT = "Desktop Video"; + VERSION = finalAttrs.version; + } + '' + DOWNLOADID=$( + curl --silent --compressed "$DOWNLOADSURL" \ + | jq --raw-output '.downloads[] | .urls.Linux?[]? | select(.downloadTitle | test("^'"$PRODUCT $VERSION"'( Update)?$")) | .downloadId' + ) + REFERID=$( + curl --silent --compressed "$DOWNLOADSURL" \ + | jq --raw-output '.downloads[] | .urls.Linux?[]? | select(.downloadTitle | test("^'"$PRODUCT $VERSION"'( Update)?$")) | .releaseId' + ) + echo "Download ID is $DOWNLOADID" + echo "Refer ID is $REFERID" + test -n "$REFERID" + test -n "$DOWNLOADID" + SITEURL="https://www.blackmagicdesign.com/api/register/us/download/$DOWNLOADID"; + RESOLVEURL=$(curl \ + -s \ + -H "$USERAGENT" \ + -H 'Content-Type: application/json;charset=UTF-8' \ + -H "Referer: https://www.blackmagicdesign.com/support/download/$REFERID/Linux" \ + --data-ascii "$REQJSON" \ + --compressed \ + "$SITEURL") + curl \ + --retry 3 --retry-delay 3 \ + --compressed \ + "$RESOLVEURL" \ + > $out + ''; + + passthru.updateScript = lib.getExe (writeShellApplication { + # mostly stolen from pkgs/by-name/da/davinci-resolve/package.nix :) + name = "update-blackmagic-desktop-video"; + runtimeInputs = [ + common-updater-scripts + curl + jq + ]; + text = '' + set -o errexit + downloadsJSON="$(curl --fail --silent https://www.blackmagicdesign.com/api/support/us/downloads.json)" + latestLinuxVersion="$(echo "$downloadsJSON" | jq '[.downloads[] | select(.urls.Linux) | .urls.Linux[] | select(.downloadTitle | test("Desktop Video")) | .downloadTitle]' | grep -oP 'Desktop Video \K\d\d\.\d+(\.\d+)?' | sort | tail -n 1)" + + update-source-version blackmagic-desktop-video "$latestLinuxVersion" + ''; + }); + + postUnpack = + let + arch = stdenv.hostPlatform.uname.processor; + in + '' + tar xf Blackmagic_Desktop_Video_Linux_${finalAttrs.version}/other/${arch}/desktopvideo-${finalAttrs.version}*-${arch}.tar.gz + unpacked=$NIX_BUILD_TOP/desktopvideo-${finalAttrs.version}*-${stdenv.hostPlatform.uname.processor} + ''; + + installPhase = '' + runHook preInstall + mkdir -p $out/{bin,share/doc,share/man/man1,lib/systemd/system} + cp -r $unpacked/usr/share/doc/desktopvideo $out/share/doc + cp $unpacked/usr/share/man/man1/DesktopVideoHelper.1 $out/share/man/man1 + cp $unpacked/usr/lib/*.so $out/lib + cp $unpacked/usr/lib/systemd/system/DesktopVideoHelper.service $out/lib/systemd/system + cp $unpacked/usr/lib/blackmagic/DesktopVideo/DesktopVideoHelper $out/bin/ + substituteInPlace $out/lib/systemd/system/DesktopVideoHelper.service \ + --replace-fail "/usr/lib/blackmagic/DesktopVideo/DesktopVideoHelper" "$out/bin/DesktopVideoHelper" + '' + + lib.optionalString desktopVideoUpdater '' + mkdir -p $out/{opt/blackmagic/DesktopVideo/{,Firmware},share/icons,share/applications} + cp $unpacked/usr/share/man/man1/DesktopVideo{UpdateTool,Updater}.1 $out/share/man/man1 + cp -r $unpacked/usr/share/icons/* $out/share/icons + cp $unpacked/usr/share/applications/DesktopVideoUpdater.desktop $out/share/applications + cp -r $unpacked/usr/lib/blackmagic/DesktopVideo/Firmware $out/opt/blackmagic/DesktopVideo/Firmware # UpdateTool expects Firmware dir next to it + cp $unpacked/usr/lib/blackmagic/DesktopVideo/libDVUpdate.so $out/lib + cp $unpacked/usr/lib/blackmagic/DesktopVideo/DesktopVideo{UpdateTool,Updater} $out/opt/blackmagic/DesktopVideo + ln -s $out/opt/blackmagic/DesktopVideo/DesktopVideo{UpdateTool,Updater} $out/bin + '' + + lib.optionalString desktopVideoGUI '' + mkdir -p $out/{share/{icons,applications},opt/blackmagic/DesktopVideo/{,plugins}} + cp -r $unpacked/usr/share/doc/desktopvideo-gui $out/share/doc + cp $unpacked/usr/share/man/man1/BlackmagicDesktopVideoSetup.1 $out/share/man/man1 + cp -r $unpacked/usr/share/icons/* $out/share/icons + cp $unpacked/usr/share/applications/BlackmagicDesktopVideoSetup.desktop $out/share/applications + cp -r $unpacked/usr/lib/blackmagic/DesktopVideo/plugins $out/opt/blackmagic/DesktopVideo/plugins + cp $unpacked/usr/lib/blackmagic/DesktopVideo/qt.conf $out/opt/blackmagic/DesktopVideo + cp $unpacked/usr/lib/blackmagic/DesktopVideo/BlackmagicDesktopVideoSetup $out/opt/blackmagic/DesktopVideo + ln -s $out/opt/blackmagic/DesktopVideo/BlackmagicDesktopVideoSetup $out/bin + '' + + '' + runHook postInstall + ''; + + # need to tell the DesktopVideoHelper where to find its own library + appendRunpaths = [ "${placeholder "out"}/lib" ]; + + meta = with lib; { + homepage = "https://www.blackmagicdesign.com/support/family/capture-and-playback"; + maintainers = [ maintainers.naxdy ]; + license = licenses.unfree; + description = "Supporting applications for Blackmagic Decklink. Doesn't include the desktop applications or firmware updater by default, only the helper required to make the driver work"; + platforms = platforms.linux; + }; +}) -- cgit v1.2.3