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

wivrn: init at 0.17 #316975

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

wivrn: init at 0.17 #316975

wants to merge 2 commits into from

Conversation

PassiveLemon
Copy link
Contributor

@PassiveLemon PassiveLemon commented Jun 3, 2024

Description of changes

Adds WiVRn #278126 (comment)

Continuation of #299830 because I goofed.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.11 Release Notes (or backporting 23.11 and 24.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@PassiveLemon
Copy link
Contributor Author

@ckiee
Copy link
Member

ckiee commented Jun 3, 2024

Welcome back.. It's a right of passage sometimes.

@Scrumplex
Copy link
Member

Both nixpkgs-review and ofborg fail to evaluate. While I can evaluate it when built by itself, FDO GitLab is currently under maintenance, so I can't pull the Monado source.

@Pandapip1
Copy link
Contributor

@GrahamcOfBorg eval

@PassiveLemon
Copy link
Contributor Author

From what Ofborg says, it looks like the monado CMake feature is involved but I don't really know why it fails. It builds on my system and it built in the other PR before

@Scrumplex
Copy link
Member

I think it just can't build the monado derivation currently because of the downtime of FDO GitLab

@Scrumplex
Copy link
Member

Scrumplex commented Jun 4, 2024

I have refactored the derivation a little, utilizing finalAttrs and moving the sources into the derivation itself, so overriding is much easier.

From 49cf6b5a420e347c1edcfc18f7e9787091fc1434 Mon Sep 17 00:00:00 2001
From: Sefa Eyeoglu <contact@scrumplex.net>
Date: Tue, 4 Jun 2024 23:23:01 +0200
Subject: [PATCH] wivrn: refactor derivation

Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>
---
 pkgs/by-name/wi/wivrn/package.nix | 59 ++++++++++++++-----------------
 1 file changed, 26 insertions(+), 33 deletions(-)

diff --git a/pkgs/by-name/wi/wivrn/package.nix b/pkgs/by-name/wi/wivrn/package.nix
index 67ec086ab758..81c798ee8b6b 100644
--- a/pkgs/by-name/wi/wivrn/package.nix
+++ b/pkgs/by-name/wi/wivrn/package.nix
@@ -3,7 +3,7 @@
 , stdenv
 , fetchFromGitHub
 , fetchFromGitLab
-, fetchpatch
+, applyPatches
 , avahi
 , boost
 , cmake
@@ -38,55 +38,36 @@
 , vulkan-tools
 , x264
 }:
-let
-  wivrnVersion = "0.15";
+stdenv.mkDerivation (finalAttrs: {
+  pname = "wivrn";
+  version = "0.15";
 
-  wivrnSrc = fetchFromGitHub {
+  src = fetchFromGitHub {
     owner = "meumeu";
     repo = "wivrn";
-    rev = "v${wivrnVersion}";
+    rev = "v${finalAttrs.version}";
     hash = "sha256-RVRbL9hqy9pMKjvzwaP+9HGEfdpAhmlnnvqZsEGxlCw=";
   };
 
-  monadoVersion = builtins.head (builtins.elemAt (builtins.split
-    "monado\n +GIT_TAG +([A-Za-z0-9]+)"
-    (builtins.readFile (wivrnSrc + "/CMakeLists.txt"))
-  ) 1);
-
-  monado = stdenv.mkDerivation {
-    pname = "monado";
-    version = monadoVersion;
-
+  monadoSrc = applyPatches {
     src = fetchFromGitLab {
       domain = "gitlab.freedesktop.org";
       owner = "monado";
       repo = "monado";
-      rev = monadoVersion;
+      rev = "ffb71af26f8349952f5f820c268ee4774613e200";
       hash = "sha256-+RTHS9ShicuzhiAVAXf38V6k4SVr+Bc2xUjpRWZoB0c=";
     };
 
     patches = [
-      (wivrnSrc + "/patches/monado/0001-c-multi-disable-dropping-of-old-frames.patch")
-      (wivrnSrc + "/patches/monado/0002-ipc-server-Always-listen-to-stdin.patch")
-      (wivrnSrc + "/patches/monado/0003-c-multi-Don-t-log-frame-time-diff.patch")
+      ("${finalAttrs.src}/patches/monado/0001-c-multi-disable-dropping-of-old-frames.patch")
+      ("${finalAttrs.src}/patches/monado/0002-ipc-server-Always-listen-to-stdin.patch")
+      ("${finalAttrs.src}/patches/monado/0003-c-multi-Don-t-log-frame-time-diff.patch")
     ];
 
     postPatch = ''
       substituteInPlace CMakeLists.txt --replace "add_subdirectory(doc)" ""
     '';
-
-    dontBuild = true;
-
-    installPhase = ''
-      cp -r . $out
-    '';
   };
-in
-stdenv.mkDerivation {
-  pname = "wivrn";
-  version = wivrnVersion;
-
-  src = wivrnSrc;
 
   nativeBuildInputs = [
     cmake
@@ -128,6 +109,18 @@ stdenv.mkDerivation {
     cudaPackages.cudatoolkit
   ];
 
+  postUnpack = ''
+    # Let's make sure our monado source revision matches what is used by WiVRn upstream
+    ourMonadoRev="${finalAttrs.monadoSrc.src.rev}"
+    theirMonadoRev=$(grep -A1 "https://gitlab.freedesktop.org/monado/monado" ${finalAttrs.src.name}/CMakeLists.txt | tail -n1 | sed 's/.*GIT_TAG\s*//')
+    if [ ! "$theirMonadoRev" == "$ourMonadoRev" ]; then
+      echo "Our Monado source revision doesn't match CMakeLists.txt." >&2
+      echo "  theirs: $theirMonadoRev" >&2
+      echo "    ours: $ourMonadoRev" >&2
+      return 1
+    fi
+  '';
+
   cmakeFlags = [
     (lib.cmakeBool "WIVRN_USE_VAAPI" true)
     (lib.cmakeBool "WIVRN_USE_X264" true)
@@ -138,7 +131,7 @@ stdenv.mkDerivation {
     (lib.cmakeBool "WIVRN_BUILD_CLIENT" false)
     (lib.cmakeBool "WIVRN_OPENXR_INSTALL_ABSOLUTE_RUNTIME_PATH" true)
     (lib.cmakeBool "FETCHCONTENT_FULLY_DISCONNECTED" true)
-    (lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_MONADO" "${monado}")
+    (lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_MONADO" "${finalAttrs.monadoSrc}")
   ];
 
   passthru.updateScript = nix-update-script { };
@@ -146,10 +139,10 @@ stdenv.mkDerivation {
   meta = with lib; {
     description = "An OpenXR streaming application to a standalone headset";
     homepage = "https://github.com/Meumeu/WiVRn/";
-    changelog = "https://github.com/Meumeu/WiVRn/releases/tag/v${wivrnVersion}";
+    changelog = "https://github.com/Meumeu/WiVRn/releases/tag/v${finalAttrs.version}";
     license = licenses.gpl3Only;
     maintainers = with maintainers; [ passivelemon ];
     platforms = platforms.linux;
     mainProgram = "wivrn-server";
   };
-}
+})
-- 
2.44.1

@Pandapip1
Copy link
Contributor

Actually, might it make sense to patch wivrn to use the latest version of monado instead?

@xytovl
Copy link

xytovl commented Jun 5, 2024

Actually, might it make sense to patch wivrn to use the latest version of monado instead?

I do not recommend it, updating monado often requires changes in WiVRn itself, see latest updates on dev branch:
Meumeu/WiVRn@27235d3
Meumeu/WiVRn@eaf6efd
Meumeu/WiVRn@41044fe (which didn't require any change).

You may backport those changes if you wish, but you may not always have a compatible version.

@PassiveLemon
Copy link
Contributor Author

I believe it currently is best to target the official releases rather than backporting changes. I like the idea case of checking if the versions match so if WiVRn is automatically updated but the Monado source isn't, a broken package isn't released.

@PassiveLemon
Copy link
Contributor Author

Also I think it would be of interest to add WiVRn configuration to the module as well. It's in json so there's probably some parts of other modules I can use to get that working. I'll probably look into it tomorrow.

@Pandapip1
Copy link
Contributor

Fair enough. Is it possible to have an update script update something other than the derivation's src?

@PassiveLemon
Copy link
Contributor Author

Config file doesn't appear to be that hard to implement, however it's loaded from the users config dir by default and I don't think there's a flag to specify a config file to load. Not sure how this could be done otherwise. Maybe a suggestion for upstream.


Note that applications can bypass this option by setting an active
runtime in a writable XDG_CONFIG_DIRS location like `~/.config`
'' // { default = true; };
Copy link
Contributor

@Pandapip1 Pandapip1 Jul 1, 2024

Choose a reason for hiding this comment

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

pkgs/by-name/wi/wivrn/package.nix Outdated Show resolved Hide resolved
nixos/modules/services/video/wivrn.nix Outdated Show resolved Hide resolved
nixos/modules/services/video/wivrn.nix Outdated Show resolved Hide resolved
nixos/modules/services/video/wivrn.nix Outdated Show resolved Hide resolved
nixos/modules/services/video/wivrn.nix Show resolved Hide resolved
nixos/modules/services/video/wivrn.nix Outdated Show resolved Hide resolved
Comment on lines 11 to 37
applicationListNotEmpty = (
if builtins.isList cfg.config.json.application
then if builtins.length cfg.config.json.application == 0
then false
else true
else true
);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
applicationListNotEmpty = (
if builtins.isList cfg.config.json.application
then if builtins.length cfg.config.json.application == 0
then false
else true
else true
);
applicationListNotEmpty = builtins.isList cfg.config.json.application
|| builtins.length cfg.config.json.application != 0;

@PassiveLemon PassiveLemon force-pushed the wivrn-init branch 4 times, most recently from 5d824e3 to 514056b Compare July 4, 2024 14:06
@PassiveLemon
Copy link
Contributor Author

PassiveLemon commented Jul 9, 2024

Should I add an option for starting by default through "wantedBy = [ "multi-user.target" ];"? I would think it makes sense for it to be started by automatically.

@Pandapip1
Copy link
Contributor

Should I add an option for starting by default through "wantedBy = [ "multi-user.target" ];"? I would think it makes sense for it to be started by automatically.

Since it's a user service, shouldn't it be wantedBy = [ "default.target" ];?

@PassiveLemon
Copy link
Contributor Author

Since it's a user service, shouldn't it be wantedBy = [ "default.target" ];?

It think it should be, though I'm not 100% sure. We could also make it depend on graphical.target instead but I also don't know if WiVRn requires that. I'll have to check and see

@Pandapip1
Copy link
Contributor

WiVRn shouldn't need graphical.target

@PassiveLemon
Copy link
Contributor Author

PassiveLemon commented Jul 10, 2024

Pushed an option for enabling autostarting. Still waiting for the previous reviews to be resolved

@Pandapip1
Copy link
Contributor

Still waiting for the previous reviews to be resolved

Only the pull request author and committers can resolve reviews (not even the review author)! You should manually resolve any resolved discussions yourself.

@PassiveLemon
Copy link
Contributor Author

Only the pull request author and committers can resolve reviews (not even the review author)! You should manually resolve any resolved discussions yourself.

I did not know that. We still didn't come to a conclusion so i'm unsure if those discussions are resolved or not

@Pandapip1
Copy link
Contributor

#316975 (comment) and #316975 (comment) are unresolved nits.

#316975 (comment) is also an unresolved nit. The code it's pointing to is outdated. It refers to these updated lines:

applicationListNotEmpty = (
if builtins.isList cfg.config.json.application
then (builtins.length cfg.config.json.application) != 0
else true
);

@PassiveLemon PassiveLemon changed the title wivrn: init at 0.16 wivrn: init at 0.17 Jul 15, 2024
@PassiveLemon
Copy link
Contributor Author

Updated to release 0.17

pkgs/by-name/wi/wivrn/package.nix Outdated Show resolved Hide resolved
pkgs/by-name/wi/wivrn/package.nix Outdated Show resolved Hide resolved
nixos/modules/services/video/wivrn.nix Outdated Show resolved Hide resolved
nixos/modules/services/video/wivrn.nix Outdated Show resolved Hide resolved
pkgs/by-name/wi/wivrn/package.nix Outdated Show resolved Hide resolved
@PassiveLemon PassiveLemon force-pushed the wivrn-init branch 2 times, most recently from f12ffb0 to c2b18de Compare July 18, 2024 01:41
Copy link
Contributor

@Pandapip1 Pandapip1 left a comment

Choose a reason for hiding this comment

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

LGTM, despite the nits

nixos/modules/services/video/wivrn.nix Outdated Show resolved Hide resolved
nixos/modules/services/video/wivrn.nix Outdated Show resolved Hide resolved
nixos/modules/services/video/wivrn.nix Outdated Show resolved Hide resolved
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

10 participants