Subject: Re: [bug#51737] [PATCH v2 1/7] gnu: Add linux-libre-waydroid.

From: phodina <[email-masked]>
Date: Mon, 27 Jun 2022 07:07:46 +0000

Hi Maxime,
>
> > +                                (string-append "DESTDIR="
> > +                                               #$output))
>
>
> DESTDIR is for staged installation, which Guix doesn't do, so set
> DESTDIR=/ or don't set it at all (maybe PREFIX or prefix is what you
> need to set instead?). Likewise for other packages.
>
> Greetings,
> Maxime.

I packaged it this way as at that time was the simples solution. Now I switched to substitution in Makefile itself.

Also there's fix for waydroid package as I mistakenly send old patch.

Should I also create a service for waydroid + test to check it's running?

----
Petr
From ef52a2ac20b691d3eac6614c94787c8bf2daa523 Mon Sep 17 00:00:00 2001
From: Petr Hodina <[email-masked]>
Date: Tue, 9 Nov 2021 22:41:30 +0100
Subject: [PATCH v3 4/6] gnu: Add libgbinder.

* gnu/packages/glib.scm (libgbinder): New variable.

diff --git a/gnu/packages/glib.scm b/gnu/packages/glib.scm
index 19f69b3a5c..8b91aac41a 100644
--- a/gnu/packages/glib.scm
+++ b/gnu/packages/glib.scm
@@ -850,6 +850,61 @@ (define-public glibmm-2.64
       (modify-inputs (package-propagated-inputs glibmm)
         (replace "libsigc++" libsigc++-2)))))
 
+(define-public libgbinder
+  (package
+    (name "libgbinder")
+    (version "1.1.23")
+    (source (origin
+              (method git-fetch)
+              (uri (git-reference
+                    (url "https://github.com/mer-hybris/libgbinder")
+                    (commit version)))
+              (file-name (git-file-name name version))
+              (sha256
+               (base32
+                "12nw2ihd2xhpvdh0jlyacskqmbdxhnrm5pnz30v4mkyg9kz4xhdc"))))
+    (build-system gnu-build-system)
+    (arguments
+     (list #:make-flags #~(list (string-append "CC="
+                                               #$(cc-for-target)))
+           #:phases #~(modify-phases %standard-phases
+                        (delete 'configure)
+                        (add-after 'unpack 'fix-pkg-config-in
+                          (lambda* _
+                            (substitute* "Makefile"
+                              (("\\$\\(DESTDIR\\)") #$output)
+                              (("usr/") ""))
+                            (substitute* "libgbinder.pc.in"
+                              (("@libdir@") (string-append #$output "/lib"))
+                              (("/usr/include") (string-append #$output
+                                                               "/include")))))
+                        (add-after 'install 'install-dev
+                          (lambda* _
+                            (invoke "make" "install-dev"
+                                    (string-append "DESTDIR="
+                                                   #$output))))
+                        (replace 'check
+                          (lambda* (#:key tests? #:allow-other-keys)
+                            (when tests?
+                              (chdir "test")
+                              (invoke "make"
+                                      (string-append "CC="
+                                                     #$(cc-for-target)))
+                              (chdir "..")))))))
+    (native-inputs (list bison flex pkg-config))
+    (inputs (list glib libglibutil))
+    (home-page "https://github.com/mer-hybris/libgbinder")
+    (synopsis "GLib-style interface to binder")
+    (description
+     "This package provides GLib-style interface to binder:
+@enumerate
+@item Integration with GLib event loop
+@item Detection of 32 vs 64 bit kernel at runtime
+@item Asynchronous transactions that don't block the event thread
+@item Stable service manager and low-level transation APIs
+@end enumerate")
+    (license license:bsd-3)))
+
 (define-public libglibutil
   (package
     (name "libglibutil")
-- 
2.36.1

From faedb7a4beb492fd024982655a844fb049ba538d Mon Sep 17 00:00:00 2001
From: Petr Hodina <[email-masked]>
Date: Wed, 22 Dec 2021 02:35:46 +0100
Subject: [PATCH v3 2/6] gnu: Add linux-libre-arm64-waydroid.

* gnu/packages/linux.scm (linux-libre-arm64-waydroid): New variable.

diff --git a/gnu/packages/linux.scm b/gnu/packages/linux.scm
index 3d58f8a2c6..7c57ec0d68 100644
--- a/gnu/packages/linux.scm
+++ b/gnu/packages/linux.scm
@@ -1080,6 +1080,33 @@ (define-public linux-libre-arm-omap2plus-4.14
                      #:defconfig "omap2plus_defconfig"
                      #:extra-version "arm-omap2plus"))
 
+(define-public linux-libre-arm64-waydroid
+  (make-linux-libre* linux-libre-version
+                     linux-libre-gnu-revision
+                     linux-libre-source
+                     '("aarch64-linux")
+                     #:defconfig "defconfig"
+                     #:extra-version "arm64-generic"
+                     #:extra-options
+                     (append
+                      `(;; needed to fix the RTC on rockchip platforms
+                        ("CONFIG_RTC_DRV_RK808" . #t)
+                        ;; Pinebook display, battery, charger and usb
+                        ("CONFIG_DRM_ANALOGIX_ANX6345" . m)
+                        ("CONFIG_CHARGER_AXP20X" . m)
+                        ("CONFIG_INPUT_AXP20X_PEK" . m)
+                        ("CONFIG_CHARGER_AXP20X" . m)
+                        ("CONFIG_BATTERY_AXP20X" . m)
+                        ("CONFIG_PINCTRL_AXP209" . m)
+                        ("CONFIG_AXP20X_POWER" . m)
+                        ("CONFIG_AXP20X_ADC" . m)
+                        ;; Pinebook PRO battery and sound support
+                        ("CONFIG_BATTERY_CW2015" . m)
+                        ("CONFIG_CHARGER_GPIO" . m)
+                        ("CONFIG_SND_SOC_ES8316" . m))
+                        %waydroid-extra-linux-options
+                      %default-extra-linux-options)))
+
 (define-public linux-libre-arm64-generic
   (make-linux-libre* linux-libre-version
                      linux-libre-gnu-revision
-- 
2.36.1

From a416098d46b7ca5963d835d2603d9d525f0ca236 Mon Sep 17 00:00:00 2001
From: Petr Hodina <[email-masked]>
Date: Thu, 11 Nov 2021 19:26:41 +0100
Subject: [PATCH v3 1/6] gnu: Add linux-libre-waydroid.

* gnu/packages/linux.scm (linux-libre-waydroid,
  waydroid-extra-linux-options): New variables.

diff --git a/gnu/packages/linux.scm b/gnu/packages/linux.scm
index 9c59d4ef9b..3d58f8a2c6 100644
--- a/gnu/packages/linux.scm
+++ b/gnu/packages/linux.scm
@@ -729,6 +729,14 @@ (define %bpf-extra-linux-options
     ;; kheaders module
     ("CONFIG_IKHEADERS" . #t)))
 
+(define %waydroid-extra-linux-options
+  `(;; Modules required for waydroid:
+   ("CONFIG_ASHMEM" . #t)
+   ("CONFIG_ANDROID" . #t)
+   ("CONFIG_ANDROID_BINDER_IPC" . #t)
+   ("CONFIG_ANDROID_BINDERFS" . #t)
+   ("CONFIG_ANDROID_BINDER_DEVICES" . "binder,hwbinder,vndbinder")))
+
 (define (config->string options)
   (string-join (map (match-lambda
                       ((option . 'm)
@@ -1156,6 +1164,24 @@ (define-public linux-libre-mips64el-fuloong2e
                       `(("CONFIG_OVERLAY_FS" . m))
                       %default-extra-linux-options)))
 
+(define-public linux-libre-waydroid
+  (let ((base-linux-libre
+         (make-linux-libre*
+          linux-libre-version
+          linux-libre-gnu-revision
+          linux-libre-source
+          '("x86_64-linux" "i686-linux" "armhf-linux"
+            "aarch64-linux" "riscv64-linux")
+          #:extra-version "linux"
+          #:configuration-file kernel-config
+          #:extra-options
+          (append %waydroid-extra-linux-options
+                  %default-extra-linux-options))))
+    (package
+      (inherit base-linux-libre)
+         (name "linux-libre-waydroid")
+      (inputs `(("cpio" ,cpio) ,@(package-inputs base-linux-libre))))))
+
 (define-public linux-libre-with-bpf
   (let ((base-linux-libre
          (make-linux-libre*
-- 
2.36.1

From fceafa6fefd82d0968781ed03cf5565af76dc7eb Mon Sep 17 00:00:00 2001
From: Petr Hodina <[email-masked]>
Date: Wed, 10 Nov 2021 01:25:52 +0100
Subject: [PATCH v3 5/6] gnu: Add python-gbinder.

* gnu/packages/glib.scm (python-gbinder): New variable.

diff --git a/gnu/packages/glib.scm b/gnu/packages/glib.scm
index 8b91aac41a..205c24a909 100644
--- a/gnu/packages/glib.scm
+++ b/gnu/packages/glib.scm
@@ -952,6 +952,33 @@ (define-public libglibutil
     (description "This package provides library of glib utilities.")
     (license license:bsd-3)))
 
+(define-public python-gbinder
+  (package
+    (name "python-gbinder")
+    (version "1.0.0")
+    (source (origin
+              (method git-fetch)
+              (uri (git-reference
+                    (url "https://github.com/erfanoabdi/gbinder-python")
+                    (commit version)))
+              (file-name (git-file-name name version))
+              (sha256
+               (base32
+                "0jgblzakjgsy0cj93bmh5gr7qnl2xgsrm0wzc6xjvzry9lrbs360"))))
+    (build-system python-build-system)
+    (arguments
+     (list #:phases #~(modify-phases %standard-phases
+                        (replace 'build
+                          (lambda* _
+                            (invoke "python" "setup.py" "build_ext"
+                                    "--inplace" "--cython"))))))
+    (native-inputs (list python-cython pkg-config))
+    (inputs (list glib libgbinder libglibutil))
+    (home-page "https://github.com/erfanoabdi/gbinder-python")
+    (synopsis "Python bindings for libgbinder")
+    (description "This package provides Python bindings for libgbinder.")
+    (license license:gpl3+)))
+
 (define-public python-pygobject
   (package
     (name "python-pygobject")
-- 
2.36.1

From 1d8491917107f232dac0fe707aebf6a5571fb730 Mon Sep 17 00:00:00 2001
From: Petr Hodina <[email-masked]>
Date: Wed, 10 Nov 2021 02:21:08 +0100
Subject: [PATCH v3 6/6] gnu: Add waydroid.

* gnu/packages/virtualization.scm (waydroid): New variable.

diff --git a/gnu/packages/virtualization.scm b/gnu/packages/virtualization.scm
index 4cb83b4d85..2ec37201c9 100644
--- a/gnu/packages/virtualization.scm
+++ b/gnu/packages/virtualization.scm
@@ -2092,6 +2092,94 @@ (define-public bochs
 DOS or Microsoft Windows.")
     (license license:lgpl2.0+)))
 
+(define-public waydroid
+  (package
+    (name "waydroid")
+    (version "1.2.1")
+    (source (origin
+              (method git-fetch)
+              (uri (git-reference
+                    (url "https://github.com/waydroid/waydroid")
+                    (commit version)))
+              (file-name (git-file-name name version))
+              (sha256
+               (base32
+                "1ssqlsnhmpzaq2n9rbkfn3d2ml4vmima0az6gakknjc2q6bnpza9"))))
+    (build-system python-build-system)
+    (arguments
+     (list #:phases #~(modify-phases %standard-phases
+                        (delete 'build)
+                        (delete 'check)
+                        (replace 'install
+                          (lambda* (#:key outputs inputs #:allow-other-keys)
+                            (let* ((lib (string-append #$output
+                                                       "/lib/waydroid")) (tools
+                                                                          (string-append
+                                                                           lib
+                                                                           "/tools"))
+                                   (data (string-append lib "/data"))
+                                   (apps (string-append out
+                                                        "/share/applications"))
+                                   (bin (string-append out "/bin"))
+                                   (paths-bin #~(map (lambda (input)
+                                                     (string-append
+													 #$input "/bin"))
+                                                   '(iptables nftables
+                                                     glibc dnsmasq)))
+                                   (paths-sbin #$(map (lambda (input)
+                                                      (string-append #$input "/sbin"))
+                                                    '(dnsmasq)))
+                                   (site (string-append out "/lib/python"
+                                                        #$(version-major+minor
+                                                           (package-version
+                                                            python))
+                                                        "/site-packages")))
+                              (mkdir-p tools)
+                              (mkdir-p data)
+                              (mkdir-p apps)
+                              (mkdir-p bin)
+                              (copy-recursively "tools" tools)
+                              (copy-recursively "data" data)
+                              (install-file (string-append data
+                                             "/Waydroid.desktop")
+                                            (string-append apps))
+                              (substitute* (string-append apps
+                                                          "/Waydroid.desktop")
+                                (("/usr") lib))
+                              (install-file "waydroid.py" lib)
+                              (symlink (string-append lib "/waydroid.py")
+                                       (string-append bin "/waydroid"))
+                              (wrap-program (string-append bin "/waydroid")
+                                            #~("PYTHONPATH" ":" prefix
+                                               #$paths-bin))
+                              (substitute* (string-append out
+                                            "/lib/waydroid/data/scripts/waydroid-net.sh")
+                                (("/misc") ""))
+                              (wrap-program (string-append out
+                                             "/lib/waydroid/data/scripts/waydroid-net.sh")
+                                            #~("PATH" ":" prefix
+                                               #$(append paths-bin paths-sbin)))))))))
+    (inputs (list bash-minimal
+                  dnsmasq
+                  libgbinder
+                  glibc
+                  lxc
+                  nftables
+                  iptables
+                  python
+                  python-gbinder
+                  python-pygobject))
+    (home-page "https://waydro.id")
+    (synopsis "Container-based approach to boot a full Android system")
+    (description
+     "Waydroid uses Linux namespaces @code{(user, pid, uts, net,
+mount, ipc)} to run a full Android system in a container and provide Android
+applications.  The Android inside the container has direct access to needed
+underlying hardware.  The Android runtime environment ships with a minimal
+customized Android system image based on LineageOS.  The used image is
+currently based on Android 11.")
+    (license license:gpl3)))
+
 (define-public xen
   (package
     (name "xen")
-- 
2.36.1

From 9f9dbbfed1d8b7f999c92d940740b478d8d082a8 Mon Sep 17 00:00:00 2001
From: Petr Hodina <[email-masked]>
Date: Tue, 9 Nov 2021 22:34:39 +0100
Subject: [PATCH v3 3/6] gnu: Add libglibutil.

* gnu/packages/glib.scm (libglibutil): New variable.

diff --git a/gnu/packages/glib.scm b/gnu/packages/glib.scm
index 98267fcee5..19f69b3a5c 100644
--- a/gnu/packages/glib.scm
+++ b/gnu/packages/glib.scm
@@ -17,6 +17,7 @@
 ;;; Copyright © 2020 Jan (janneke) Nieuwenhuizen <[email-masked]>
 ;;; Copyright © 2020 Arthur Margerit <[email-masked]>
 ;;; Copyright © 2021 Maxime Devos <[email-masked]>
+;;; Copyright © 2021 Petr Hodina <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -75,6 +76,7 @@ (define-module (gnu packages glib)
   #:use-module (guix build-system perl)
   #:use-module (guix build-system python)
   #:use-module (guix download)
+  #:use-module (guix git-download)
   #:use-module ((guix licenses) #:prefix license:)
   #:use-module (guix packages)
   #:use-module (guix utils)
@@ -848,6 +850,53 @@ (define-public glibmm-2.64
       (modify-inputs (package-propagated-inputs glibmm)
         (replace "libsigc++" libsigc++-2)))))
 
+(define-public libglibutil
+  (package
+    (name "libglibutil")
+    (version "1.0.65")
+    (source (origin
+              (method git-fetch)
+              (uri (git-reference
+                    (url "https://git.sailfishos.org/mer-core/libglibutil")
+                    (commit version)))
+              (file-name (git-file-name name version))
+              (sha256
+               (base32
+                "0sc8xw5cbxcicipjp6ycbgqppn31lzsll4r9j6b0zxd747dziv54"))))
+    (build-system gnu-build-system)
+    (arguments
+     (list #:make-flags #~(list (string-append "CC="
+                                               #$(cc-for-target)))
+           #:phases #~(modify-phases %standard-phases
+                        (delete 'configure)
+                        (add-after 'unpack 'remove-usr-prefix
+                          (lambda* _
+                            (substitute* "libglibutil.pc.in"
+                              (("/usr/include") (string-append #$output
+                                                               "/include")))
+                            (substitute* "Makefile"
+                              (("\\$\\(DESTDIR\\)") #$output)
+                              (("usr/") ""))))
+                        (add-after 'install 'install-dev
+                          (lambda* _
+                            (invoke "make" "install-dev"
+                                    (string-append "DESTDIR="
+                                                   #$output))))
+                        (replace 'check
+                          (lambda* (#:key tests? #:allow-other-keys)
+                            (when tests?
+                              (chdir "test")
+                              (invoke "make"
+                                      (string-append "CC="
+                                                     #$(cc-for-target)))
+                              (chdir "..")))))))
+    (native-inputs (list pkg-config))
+    (inputs (list glib))
+    (home-page "https://git.sailfishos.org/mer-core/libglibutil")
+    (synopsis "GLib utilites")
+    (description "This package provides library of glib utilities.")
+    (license license:bsd-3)))
+
 (define-public python-pygobject
   (package
     (name "python-pygobject")
-- 
2.36.1