Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve obs-v4l2sink #85690

Merged
merged 3 commits into from Apr 26, 2020
Merged

improve obs-v4l2sink #85690

merged 3 commits into from Apr 26, 2020

Conversation

notpeelz
Copy link

@notpeelz notpeelz commented Apr 21, 2020

Motivation for this change

I started working on my own derivation of obs-v42lsink and realized that it had been added to nixpkgs 4 days ago. So I compared the two derivations and noticed a couple things that were done differently.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@grahamc @colemickens

@notpeelz
Copy link
Author

Related PR: #84153

@grahamc @colemickens

@cole-h
Copy link
Member

cole-h commented Apr 21, 2020

@ofborg eval

GitHub seems to be recover(ing/ed).

@notpeelz
Copy link
Author

notpeelz commented Apr 21, 2020

The 32-bit derivation can be tested with this:

{ pkgs ? import ./nixpkgs {}, is32bit ? false }:

with pkgs.lib;
let
  deps = pkgs: {
    inherit (pkgs)
      obs-studio
      obs-v4l2sink;
  };
  depsAttrset = if is32bit
    then deps pkgs.pkgsi686Linux.pkgs
    else deps pkgs;
in pkgs.stdenv.mkDerivation {
  name = "env";
  buildInputs = attrValues depsAttrset;
  shellHook = ''
    echo "obs-studio: ${depsAttrset.obs-studio.outPath}"
    echo "obs-v4l2sink: ${depsAttrset.obs-v4l2sink.outPath}"
    ln -sfT \
      ${depsAttrset.obs-v4l2sink}/share/obs/obs-plugins/v4l2sink \
      ~/.config/obs-studio/plugins/v4l2sink
  '';
  unpackPhase = ":";
  installPhase = "touch $out";
}
$ nix-shell --arg is32bit true

@notpeelz notpeelz force-pushed the obs-v4l2sink branch 2 times, most recently from 868bf88 to 7e96a3c Compare April 22, 2020 04:49
@colemickens
Copy link
Member

(Mentioned in IRC, but just for continuity's sake, including here.)

I applied this patch which made the directory structure back to what home-manager expects (and what other plugins tend to follow):

diff --git a/pkgs/applications/video/obs-studio/v4l2sink.nix b/pkgs/applications/video/obs-studio/v4l2sink.nix
index 29479a33a1b..eddb7928d85 100644
--- a/pkgs/applications/video/obs-studio/v4l2sink.nix
+++ b/pkgs/applications/video/obs-studio/v4l2sink.nix
@@ -35,8 +35,8 @@ stdenv.mkDerivation rec {
   }.${stdenv.targetPlatform.system} or (throw "Unsupported system: ${stdenv.targetPlatform.system}");
 
   postInstall = ''
-    mkdir -p $out/$pluginPath
-    ln -s $out/lib/obs-plugins/v4l2sink.so $out/$pluginPath
+    mkdir -p $out/share/obs/obs-plugins/v4l2sink/$pluginPath
+    ln -s $out/lib/obs-plugins/v4l2sink.so $out/share/obs/obs-plugins/v4l2sink/$pluginPath
   '';
 
   meta = with lib; {

@colemickens
Copy link
Member

Okay, I can confirm - this doesn't crash on Stop anymore. Thanks, looks good.

pkgs/applications/video/obs-studio/v4l2sink.nix Outdated Show resolved Hide resolved
pkgs/applications/video/obs-studio/v4l2sink.nix Outdated Show resolved Hide resolved
pkgs/applications/video/obs-studio/v4l2sink.nix Outdated Show resolved Hide resolved

postInstall = ''
mkdir -p $out/share/obs/obs-plugins/v4l2sink/$pluginPath
ln -s $out/lib/obs-plugins/v4l2sink.so $out/share/obs/obs-plugins/v4l2sink/$pluginPath
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed? Could you add a comment?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

obs-studio seems to expects a specific directory structure for plugins, otherwise it won't find it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that upstream thing or our packaging thing. If the former, why does the project not already do that?

Either way, the comment should be part of the expression.

Copy link
Author

@notpeelz notpeelz Apr 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's an upstream thing. It looks for plugins in $XDG_CONFIG_HOME/obs-studio/plugins and /usr/share/obs/obs-plugins.

Comment added.

@notpeelz notpeelz force-pushed the obs-v4l2sink branch 5 times, most recently from 4b8205f to a33cc5c Compare April 24, 2020 23:27
@notpeelz notpeelz force-pushed the obs-v4l2sink branch 2 times, most recently from fd669a2 to 30fd1ec Compare April 25, 2020 00:36
Copy link
Contributor

@jtojnar jtojnar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The path shenanigans are weird, looks good otherwise.

pkgs/applications/video/obs-studio/v4l2sink.nix Outdated Show resolved Hide resolved
The rev was downgraded to the latest released version (0.1.0) because the
the changes on master are mostly related to localization and README
stuff. The only code-related change is insignificant.
@colemickens
Copy link
Member

Pulled latest commits as of right now - still works in my HM-managed setup. LGTM thanks!

@jtojnar jtojnar merged commit 4bcf123 into NixOS:master Apr 26, 2020
@jtojnar
Copy link
Contributor

jtojnar commented Apr 26, 2020

Thanks.

@grahamc
Copy link
Member

grahamc commented May 27, 2020

coming back to this PR for instructions on how to "install" the plugin. Gosh, I would so love a obs-studioWithPlugins

@notpeelz
Copy link
Author

Yeah that would be a good idea. For now I just have home-manager create a symlink to ${obs-v4l2sink}/share/obs/obs-plugins/v4l2sink in ~/.config/obs-studio/plugins.

@colemickens
Copy link
Member

From my nixcfg: home-manager makes it easy:

    home-manager.users.cole = { pkgs, ... }: {
      programs = {
        obs-studio = {
          enable = true;
          plugins = with pkgs; [ obs-wlrobs obs-v4l2sink ];
        };
      };
    };

@Algram
Copy link
Member

Algram commented Jun 4, 2020

@colemickens Hi, thanks for that example! It helped me a lot. Can I ask how you manage the v4l2loopback module that is required in order for the obs-v4l2sink plugin to work?

@davidak
Copy link
Member

davidak commented Oct 11, 2020

@Algram good question. i got the module loaded and exclusive_caps enabled with

  boot.extraModulePackages = [ pkgs.linuxPackages_latest.v4l2loopback ];
  boot.kernelModules = [ "v4l2loopback" ];
  boot.extraModprobeConfig = ''
    options v4l2loopback exclusive_caps=1 video_nr=9 card_label="obs"
  '';

#84153 (comment)

together with the home-manager from #85690 (comment) it works!

Screenshot from 2020-10-11 06-44-14

It would be nice to have documentation for this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants