Subject: Add Moonlight

From: phodina <[email-masked]>
Date: Tue, 06 Dec 2022 03:17:28 +0000

Hello,

these patches add support for game streaming solution for Nvidia GameStream protocol. The client is open source. However, the games and the server is a non-libre application.

----
Petr

From 3591443080ca8ae4fa775e6ea697f5e1b999a39b Mon Sep 17 00:00:00 2001
From: Petr Hodina <[email-masked]>
Date: Sat, 3 Dec 2022 10:32:43 +0100
Subject: [PATCH 2/6] gnu: Add enet-moonlight.

* gnu/packages/networking.scm (enet-moonlight): New variable.

diff --git a/gnu/packages/networking.scm b/gnu/packages/networking.scm
index f5276e330e..27f67c01bf 100644
--- a/gnu/packages/networking.scm
+++ b/gnu/packages/networking.scm
@@ -2591,6 +2591,43 @@ (define-public enet
     (home-page "http://enet.bespin.org")
     (license license:expat)))
 
+(define-public enet-moonlight
+  (let ((commit "4cde9cc3dcc5c30775a80da1de87f39f98672a31")
+        (revision "1"))
+(package
+  (inherit enet)
+  (name "enet")
+  (version commit)
+  (source (origin
+            (method git-fetch)
+            (uri (git-reference
+             (url "https://github.com/cgutman/enet")
+             (commit version)))
+            (file-name (git-file-name name version))
+            (sha256
+             (base32
+              "07sr32jy989ja23fwg8bvrq2slgm7bhfw6v3xq7yczbw86c1dndv"))))
+    (build-system cmake-build-system)
+       (arguments
+       '(#:tests? #f
+         #:phases
+         (modify-phases %standard-phases
+          (add-after 'unpack 'build-share-lib
+          (lambda* _
+          (substitute* "CMakeLists.txt"
+          (("STATIC") "SHARED"))))
+          (replace 'install
+           (lambda* (#:key outputs source #:allow-other-keys)
+               (let* ((out (assoc-ref outputs "out"))
+                      (include (string-append out "/include"))
+                      (lib (string-append out "/lib")))
+               (mkdir-p include)
+               (mkdir-p lib)
+               (copy-recursively (string-append source "/include") include)
+               (install-file "libenet.so" lib)))))))
+    (native-inputs
+     (list pkg-config)))))
+
 (define-public sslh
   (package
     (name "sslh")
-- 
2.38.1

From 413514efa6d87236d6f3e26166ac82fc3a85a9dd Mon Sep 17 00:00:00 2001
From: Petr Hodina <[email-masked]>
Date: Sat, 3 Dec 2022 10:35:36 +0100
Subject: [PATCH 4/6] gnu: Add moonlight-common.

* gnu/packages/games.scm (moonlight-common): New variable.

diff --git a/gnu/packages/games.scm b/gnu/packages/games.scm
index 9d79efbe94..131784bc2a 100644
--- a/gnu/packages/games.scm
+++ b/gnu/packages/games.scm
@@ -5857,6 +5857,50 @@ (define-public bambam
 colors, pictures, and sounds.")
     (license license:gpl3+)))
 
+(define-public moonlight-common
+  (let ((commit "8c55c086d596607041e4394fb62a1bc800b7f37c")
+        (revision "1"))
+    (package
+      (name "moonlight-common")
+      (version commit)
+      (source (origin
+                (method git-fetch)
+                (uri (git-reference
+                      (url
+                       "https://github.com/moonlight-stream/moonlight-common-c")
+                      (commit version)))
+                (file-name (git-file-name name version))
+                (sha256
+                 (base32
+                  "0pqm0a2p2sqvazv5gak6gl7d405kaaq6r13l7yhycm0myayqavrp"))))
+      (build-system cmake-build-system)
+      (arguments
+       `(#:tests? #f
+         #:phases (modify-phases %standard-phases
+                    (add-after 'unpack 'use-enet-pkg
+                      (lambda _
+                        (substitute* "CMakeLists.txt"
+                          (("add_subdirectory\\(enet\\)")
+                           ""))))
+                    (replace 'install
+                      (lambda* (#:key outputs source #:allow-other-keys)
+                        (let* ((out (assoc-ref outputs "out"))
+                               (include (string-append out "/include"))
+                               (lib (string-append out "/lib")))
+                          (mkdir-p include)
+                          (mkdir-p lib)
+                          (install-file (string-append source
+                                                       "/src/Limelight.h")
+                                        include)
+                          (install-file "libmoonlight-common-c.so" lib)))))))
+      (native-inputs (list pkg-config))
+      (inputs (list qtbase-5 openssl enet-moonlight))
+      (synopsis "Core implementation of Nvidia's GameStream protocol")
+      (description
+       "This package provides the code GameStream code shared between @code{Moonlight} clients.")
+      (home-page "https://github.com/moonlight-stream/moonlight-common-c")
+      (license license:gpl3))))
+
 (define-public mrrescue
   (package
     (name "mrrescue")
-- 
2.38.1

From 038069c5a4b7034ac2a33b822a84744419ecb3c6 Mon Sep 17 00:00:00 2001
From: Petr Hodina <[email-masked]>
Date: Sat, 3 Dec 2022 10:30:01 +0100
Subject: [PATCH 1/6] gnu: Add qmdnsengine.

* gnu/packages/qt.scm (qmdnsengine): New variable.

diff --git a/gnu/packages/qt.scm b/gnu/packages/qt.scm
index 0f5e1c3530..c095eae871 100644
--- a/gnu/packages/qt.scm
+++ b/gnu/packages/qt.scm
@@ -123,6 +123,31 @@ (define-module (gnu packages qt)
   #:use-module (gnu packages xml)
   #:use-module (srfi srfi-1))
 
+(define-public qmdnsengine
+  (let ((commit "b7a5a9f225d5e14b39f9fd1f905c4f505cf2ee99")
+        (revision "1"))
+    (package
+      (name "qmdnsengine")
+      (version commit)
+      (source (origin
+                (method git-fetch)
+                (uri (git-reference
+                      (url "https://github.com/cgutman/qmdnsengine")
+                      (commit version)))
+                (file-name (git-file-name name version))
+                (sha256
+                 (base32
+                  "1f5v5n9w4aszcdjxmw81cwmd26ssywvfiyr8x0vbyamp4kqd8mww"))))
+      (build-system cmake-build-system)
+      (arguments
+       '(#:configure-flags (list "-DBUILD_TESTS=ON")))
+      (inputs (list qtbase-5))
+      (synopsis "Multicast DNS library for Qt application")
+      (description "This package provides multicast DNS library for Qt
+  applications.")
+      (home-page "https://github.com/moonlight-stream/moonlight-common-c")
+      (license license:expat))))
+
 (define-public qite
   (let ((commit "75fb3b6bbd5c6a5a8fc35e08a6efbfb588ed546a")
         (revision "74"))
-- 
2.38.1

From 6f6e1a55787059f520428287fba474fe72c4a86b Mon Sep 17 00:00:00 2001
From: Petr Hodina <[email-masked]>
Date: Sat, 3 Dec 2022 10:36:38 +0100
Subject: [PATCH 6/6] gnu: Add moonlight.

* gnu/packages/games.scm (moonlight): New variable.

diff --git a/gnu/packages/games.scm b/gnu/packages/games.scm
index 131784bc2a..d3628266ac 100644
--- a/gnu/packages/games.scm
+++ b/gnu/packages/games.scm
@@ -5857,6 +5857,61 @@ (define-public bambam
 colors, pictures, and sounds.")
     (license license:gpl3+)))
 
+(define-public moonlight
+  (package
+    (name "moonlight")
+    (version "3.1.4")
+    (source (origin
+              (method git-fetch)
+              (uri (git-reference
+                    (url "https://github.com/moonlight-stream/moonlight-qt")
+                    (commit (string-append "v" version))))
+              (file-name (git-file-name name version))
+              (sha256
+               (base32
+                "02y2rbiiawhj1dvgxdaz8k9kpz6zkv20zsk17fbqj8259m3g5xr5"))))
+    (build-system qt-build-system)
+    (arguments
+     (list #:tests? #f
+           #:phases #~(modify-phases %standard-phases
+                        (replace 'configure
+                          (lambda* _
+                            (symlink (string-append #$(this-package-input
+                                                       "sdl-gamecontrollerdb")
+                                                    "/gamecontrollerdb.txt")
+                             "app/SDL_GameControllerDB/gamecontrollerdb.txt")
+                            (substitute* "moonlight-qt.pro"
+                              (("moonlight-common-c \\\\")
+                               "#moonlight-common-c \\")
+                              (("qmdnsengine \\\\") "#qmdnsengine \\")
+                              (("app \\\\") "app")
+                              (("app.depends") "INCLUDEPATH +=")
+                              (("h264bitstream \\\\") "#h264bitstream \\"))
+                            (invoke "qmake"
+                                    (string-append "PREFIX=" #$output)))))))
+    (native-inputs (list pkg-config qttools-5))
+    (inputs (list moonlight-common
+                  libva
+                  libvdpau
+                  openssl
+                  opus
+                  qtbase-5
+                  sdl-gamecontrollerdb
+                  qtquickcontrols2-5
+                  qtdeclarative-5
+                  qtsvg-5
+                  qmdnsengine
+                  sdl2
+                  sdl2-ttf
+                  h264bitstream
+                  ffmpeg))
+    (synopsis "GameStream client for PCs")
+    (description
+     "Moonlight PC is an open source implementation of NVIDIA's GameStream, as
+used by the NVIDIA Shield.")
+    (home-page "https://moonlight-stream.org")
+    (license license:gpl3)))
+
 (define-public moonlight-common
   (let ((commit "8c55c086d596607041e4394fb62a1bc800b7f37c")
         (revision "1"))
-- 
2.38.1

From 2034d229893bd6b96e66c588f235da36efc025b9 Mon Sep 17 00:00:00 2001
From: Petr Hodina <[email-masked]>
Date: Sat, 3 Dec 2022 10:34:03 +0100
Subject: [PATCH 3/6] gnu: Add h264bitstream.

* gnu/packages/video.scm (h264bitstream): New variable.

diff --git a/gnu/packages/video.scm b/gnu/packages/video.scm
index 6e0a1e313c..cce98ca6cd 100644
--- a/gnu/packages/video.scm
+++ b/gnu/packages/video.scm
@@ -3957,6 +3957,39 @@ (define-public handbrake
     ;; Combination under GPLv2.  See LICENSE.
     (license license:gpl2)))
 
+(define-public h264bitstream
+  (let ((commit "34f3c58afa3c47b6cf0a49308a68cbf89c5e0bff")
+        (revision "1"))
+    (package
+      (name "h264bitstream")
+      (version commit)
+      (source (origin
+                (method git-fetch)
+                (uri (git-reference
+                      (url "https://github.com/aizvorski/h264bitstream")
+                      (commit version)))
+                (file-name (git-file-name name version))
+                (sha256
+                 (base32
+                  "0rrhzckz2a89q0chw2bfl4g89yiv9a0dcqcj80lcpdr3a1ix8q85"))))
+      (build-system gnu-build-system)
+      (arguments
+       (list #:tests? #f ;no test suite
+             #:phases #~(modify-phases %standard-phases
+                          (add-after 'install 'fix-include-bs-h
+                            (lambda* _
+                              (display "")
+                              (symlink (string-append #$output
+                                        "/include/h264bitstream/bs.h")
+                                       (string-append #$output "/include/bs.h")))))))
+      (native-inputs (list autoconf automake libtool pkg-config))
+      (inputs (list ffmpeg))
+      (synopsis "Library to read and write H.264 video bitstreams")
+      (description
+       "This package provides the code GameStream code shared between @code{Moonlight} clients.")
+      (home-page "https://github.com/aizvorski/h264bitstream")
+      (license license:lgpl2.1))))
+
 (define-public intel-vaapi-driver
   (package
     (name "intel-vaapi-driver")
-- 
2.38.1

From 21db99543561eb797eab3386ad472186153e7622 Mon Sep 17 00:00:00 2001
From: Petr Hodina <[email-masked]>
Date: Mon, 5 Dec 2022 16:19:08 +0100
Subject: [PATCH 5/6] gnu: Add sdl-gamecontrollerdb.

* gnu/packages/sdl.scm (sdl-gamecontrollerdb): New variable.

diff --git a/gnu/packages/sdl.scm b/gnu/packages/sdl.scm
index 0c419dfaca..90c04c98d9 100644
--- a/gnu/packages/sdl.scm
+++ b/gnu/packages/sdl.scm
@@ -14,6 +14,7 @@
 ;;; Copyright © 2020 Timotej Lazar <[email-masked]>
 ;;; Copyright © 2020 Oleg Pykhalov <[email-masked]>
 ;;; Copyright © 2022 Maxim Cournoyer <[email-masked]>
+;;; Copyright © 2022 Petr Hodina <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -41,6 +42,7 @@ (define-module (gnu packages sdl)
   #:use-module (guix download)
   #:use-module (guix git-download)
   #:use-module (guix utils)
+  #:use-module (guix build-system copy)
   #:use-module (guix build-system gnu)
   #:use-module (guix build-system trivial)
   #:use-module (gnu packages audio)
@@ -199,6 +201,29 @@ (define-public libmikmod
     (license license:lgpl2.1)
     (home-page "http://mikmod.sourceforge.net/")))
 
+(define-public sdl-gamecontrollerdb
+  (let ((commit "9bd061ec6282cd9f8ee0eff36112d98096183a82")
+        (revision "1"))
+    (package
+      (name "sdl-gamecontrollerdb")
+      (version "")
+      (source (origin
+                (method git-fetch)
+                (uri (git-reference
+                      (url "https://github.com/gabomdq/SDL_GameControllerDB")
+                      (commit commit)))
+                (sha256
+                 (base32
+                  "1dzch3c39n1kq8m5h8fpi7aqqv6k5jqwmlyagsh6fmyzwjviqgji"))))
+      (build-system copy-build-system)
+      (arguments
+       '(#:install-plan '(("gamecontrollerdb.txt" "gamecontrollerdb.txt"))))
+      (synopsis "Database of game controller mappings to be used with SDL2
+	Game Controller")
+      (description "")
+      (home-page "https://github.com/gabomdq/SDL_GameControllerDB")
+      (license license:zlib))))
+
 (define-public sdl-gfx
   (package
     (name "sdl-gfx")
-- 
2.38.1