Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

feat(nix): build the compositor addon, which is what carries export

EtienneLescot3f96cb9cf144
diff --git a/.github/workflows/nix-build.yml b/.github/workflows/nix-build.yml
index 7d3a0c539..3334dccdb 100644
--- a/.github/workflows/nix-build.yml
+++ b/.github/workflows/nix-build.yml
@@ -25,7 +25,11 @@ name: Nix build
on:
workflow_dispatch:
push:
- branches: [main]
+ # claude/agitated-dijkstra-d63315 is back on the list for the compositor
+ # work: the derivation gains a Rust build that cannot be exercised from a
+ # Windows workstation, and CI is the only loop available until nix is
+ # installed locally. Take it off again when that work lands.
+ branches: [main, claude/agitated-dijkstra-d63315]
schedule:
# Mondays, 06:00 UTC. Drift here comes from the lockfile and from the app's
# own build requirements, neither of which respects a release cadence.
diff --git a/flake.nix b/flake.nix
index 7b2d328a8..a2af95510 100644
--- a/flake.nix
+++ b/flake.nix
@@ -18,7 +18,10 @@
# -- Per-system outputs (packages, dev shells) --
packages = forAllSystems (pkgs: {
- openscreen = pkgs.callPackage ./nix/package.nix { };
+ compositor-view = pkgs.callPackage ./nix/compositor-view.nix { };
+ openscreen = pkgs.callPackage ./nix/package.nix {
+ compositor-view = pkgs.callPackage ./nix/compositor-view.nix { };
+ };
default = self.packages.${pkgs.stdenv.hostPlatform.system}.openscreen;
});
diff --git a/nix/compositor-view.nix b/nix/compositor-view.nix
new file mode 100644
index 000000000..e59af7c5d
--- /dev/null
+++ b/nix/compositor-view.nix
@@ -0,0 +1,80 @@
+# The napi addon that carries export. Without it compositorViewService logs
+# "native addon not present; running as no-op" and the app records but cannot
+# render anything out, which is most of the point of a screen recorder.
+#
+# Built as its own derivation rather than inside the app's buildPhase: it is a
+# Rust workspace with its own toolchain and its own failure modes, and keeping
+# it separate means a break here is legible as a break here.
+{
+ lib,
+ rustPlatform,
+ ffmpeg,
+ symlinkJoin,
+ pkg-config,
+}:
+
+let
+ # crates/compositor/build.rs wants a single tree holding both include/ and
+ # lib/, the shape of the vendored ffmpeg the Windows and Linux scripts
+ # download. nixpkgs splits ffmpeg across outputs, so join them back.
+ ffmpegTree = symlinkJoin {
+ name = "ffmpeg-tree-for-build-rs";
+ paths = [
+ ffmpeg.dev
+ ffmpeg.lib
+ ];
+ };
+in
+rustPlatform.buildRustPackage {
+ pname = "openscreen-compositor-view";
+ version = (lib.importJSON ../package.json).version;
+
+ src = lib.cleanSource ../crates;
+
+ # No git dependencies in the lockfile, so this needs no hash of its own and
+ # cannot go stale the way npmDepsHash did.
+ cargoLock.lockFile = ../crates/Cargo.lock;
+
+ nativeBuildInputs = [
+ # Supplies libclang for bindgen, which build.rs uses to read ffmpeg headers.
+ # crates/.cargo/config.toml points LIBCLANG_PATH at a Windows install; that
+ # entry has no `force = true`, so the environment wins and this hook's value
+ # is what applies here.
+ rustPlatform.bindgenHook
+ pkg-config
+ ];
+
+ buildInputs = [ ffmpeg ];
+
+ # Same reasoning: config.toml's [env] sets FFMPEG_DIR to the vendored win64
+ # tree, without force, so this overrides it rather than fighting it.
+ env.FFMPEG_DIR = "${ffmpegTree}";
+
+ # poc-d3d is in the workspace and is Direct3D, so it must not be built here.
+ cargoBuildFlags = [
+ "-p"
+ "compositor-view-napi"
+ ];
+
+ # The suite targets Windows; running it on this platform proves nothing.
+ doCheck = false;
+
+ installPhase = ''
+ runHook preInstall
+ mkdir -p "$out/lib"
+ # cargo emits a plain .so; the loader looks for a .node.
+ find target -name 'libcompositor_view.so' -exec cp {} "$out/lib/compositor_view.node" \;
+ test -f "$out/lib/compositor_view.node" || {
+ echo "compositor_view.node was not produced" >&2
+ exit 1
+ }
+ runHook postInstall
+ '';
+
+ meta = {
+ description = "Native compositor addon for OpenScreen";
+ homepage = "https://github.com/getopenscreen/openscreen";
+ license = lib.licenses.mit;
+ platforms = lib.platforms.linux;
+ };
+}
diff --git a/nix/package.nix b/nix/package.nix
index f1f45eaf6..9539aaa77 100644
--- a/nix/package.nix
+++ b/nix/package.nix
@@ -4,6 +4,7 @@
nodejs_22,
electron,
ffmpeg-headless,
+ compositor-view,
makeWrapper,
makeDesktopItem,
copyDesktopItems,
@@ -96,7 +97,8 @@ buildNpmPackage {
makeWrapper "${electron}/bin/electron" "$out/bin/openscreen" \
--add-flags "$out/lib/openscreen" \
--set ELECTRON_IS_DEV 0 \
- --set OPENSCREEN_FFMPEG_PATH "${ffmpeg-headless}/bin/ffmpeg"
+ --set OPENSCREEN_FFMPEG_PATH "${ffmpeg-headless}/bin/ffmpeg" \
+ --set OPENSCREEN_COMPOSITOR_VIEW_NODE "${compositor-view}/lib/compositor_view.node"
# Install icons to hicolor theme
for size in 16 24 32 48 64 128 256 512 1024; do