Subject: Re: bug#49577: [PATCH] Add python-pmbootstrap

From: phodina <[email-masked]>
Date: Mon, 06 Jun 2022 21:07:10 +0000

Hi,

here's an updated version of the patch + 2 more tools around PMOS.

However, there is some issue with the sanity-check phase in pmbootstrap which I disabled as I didn't know how to fix it.

----
Petr

From 45fea1b10467dae4310064112b993037b7f827c3 Mon Sep 17 00:00:00 2001
From: Petr Hodina <[email-masked]>
Date: Mon, 10 Jan 2022 02:54:17 +0100
Subject: [PATCH 3/3] gnu: Add boot-deploy.

* gnu/packages/android.scm (boot-deploy): New variable.

diff --git a/gnu/packages/android.scm b/gnu/packages/android.scm
index aa9b0e0fe6..0342e30cef 100644
--- a/gnu/packages/android.scm
+++ b/gnu/packages/android.scm
@@ -46,6 +46,7 @@ (define-module (gnu packages android)
   #:use-module ((guix licenses) #:prefix license:)
   #:use-module (gnu packages)
   #:use-module (gnu packages admin)
+  #:use-module (gnu packages algebra)
   #:use-module (gnu packages base)
   #:use-module (gnu packages bash)
   #:use-module (gnu packages check)
@@ -1023,6 +1024,42 @@ (define-public abootimg
 safest way, on a file image.")
     (license license:gpl2+)))
 
+(define-public boot-deploy
+  (package
+    (name "boot-deploy")
+    (version "0.5")
+    (source (origin
+              (method git-fetch)
+              (uri (git-reference
+                    (url "https://gitlab.com/postmarketOS/boot-deploy")
+                    (commit version)))
+              (file-name (git-file-name name version))
+              (sha256
+               (base32
+                "0vh8gjprsyp4zwmpgasf4gyxclm3yyr32pf39bf218690m86fijq"))))
+    (build-system gnu-build-system)
+    (arguments
+     (list #:phases
+           #~(modify-phases %standard-phases
+               (delete 'configure)
+               (delete 'build)
+               (replace 'check
+                 (lambda* (#:key tests? #:allow-other-keys)
+                   (when tests?
+                     (invoke "bash" "test_boot_deploy_functions.sh"))))
+               (replace 'install
+                 (lambda* _
+                   (install-file "boot-deploy"
+                                 (string-append #$output "/bin")))))))
+    (native-inputs (list bc))
+    (inputs (list bash-minimal))
+    (synopsis "Boot deploy for PostmarketOS devices")
+    (description
+     "This package provides tools to generate and deploy images for
+PostmarketOS devices.")
+    (home-page "https://gitlab.com/postmarketOS/boot-deploy")
+    (license license:gpl3+)))
+
 (define-public python-androguard
   (package
     (name "python-androguard")
-- 
2.35.1

From 604e23fe8f2c624a70bdc26cd829dce539778323 Mon Sep 17 00:00:00 2001
From: Petr Hodina <[email-masked]>
Date: Sun, 18 Jul 2021 12:33:07 +0200
Subject: [PATCH 1/3] gnu: Add pmbootstrap.

* gnu/packages/python-xyz.scm (pmbootstrap): New variable.

diff --git a/gnu/packages/python-xyz.scm b/gnu/packages/python-xyz.scm
index 6132019a53..8c33364c40 100644
--- a/gnu/packages/python-xyz.scm
+++ b/gnu/packages/python-xyz.scm
@@ -1178,6 +1178,65 @@ (define-public python-shortuuid
 module and then similar looking characters are removed.")
     (license license:bsd-3)))
 
+(define-public pmbootstrap
+  (package
+    (name "pmbootstrap")
+    (version "1.44.1")
+    (source
+     (origin
+       (method url-fetch)
+       (uri (pypi-uri "pmbootstrap" version))
+       (sha256
+        (base32
+         "0hzfgf085b4h2pmbgfkx25sxq9a27m1l77jx7in48vfv8lihmhzh"))))
+    (build-system python-build-system)
+    (arguments
+     (list #:tests? #f
+       #:phases
+       #~(modify-phases %standard-phases
+         (add-after 'unpack 'replace-programs
+           (lambda* (#:key inputs #:allow-other-keys)
+             (substitute* "pmb/chroot/apk_static.py"
+               (("\"openssl\"") (string-append "\"" #$openssl
+                                               "/bin/openssl\"")))
+             (substitute* "pmb/config/__init__.py"
+               (("\"git\"") (string-append "\"" #$git
+                                           "/bin/git\""))
+               (("\"openssl\"") (string-append "\"" #$openssl
+                                               "/bin/openssl\""))
+               (("\"ps\"") (string-append "\"" #$procps
+                                          "/bin/ps\"")))))
+         (replace 'check
+           (lambda* (#:key tests? #:allow-other-keys)
+                                        ;(add-installed-pythonpath inputs outputs)
+             (when tests?
+               ;; To import pmb_test module
+               (setenv "PYTHONPATH"
+                       (string-append (assoc-ref %outputs "out") "/test/pmb_test:"
+                                      (getenv "PYTHONPATH")))
+               (invoke "pytest" "-vv"))))
+         ;; Circular dependency with pmbootstrap
+         (delete 'sanity-check))))
+    (native-inputs (list python-pytest))
+    (inputs (list git procps openssl))
+    (home-page "https://postmarketos.org")
+    (synopsis "Build and flash tool for postmarketOS")
+    (description
+     "Bootstrap program that abstracts everything in chroots and therefore
+basically runs on top of any Linux distribution.  Features:
+@enumerate
+@item chroot setup (distro-independent QEMU user emulation
+@item clean chroot shutdown (umount) and zapping
+@item build software as packages
+@item cross-compile all armhf-packages
+@item effective caching out of the box (survives chroot zaps)
+@item installation targets
+@item flasher abstractions
+@item logging
+@item security
+@end enumerate")
+    (license license:gpl3+)))
+
 (define-public python-logwrap
   (package
     (name "python-logwrap")
-- 
2.35.1

From 8b1c26dfddf10200dbd72be13322fdd835d257aa Mon Sep 17 00:00:00 2001
From: Petr Hodina <[email-masked]>
Date: Sun, 9 Jan 2022 19:22:51 +0100
Subject: [PATCH 2/3] gnu: Add pmos-installer.

* gnu/packages/android.scm (pmos-installer): New variable.

diff --git a/gnu/packages/android.scm b/gnu/packages/android.scm
index 04dc4b6499..aa9b0e0fe6 100644
--- a/gnu/packages/android.scm
+++ b/gnu/packages/android.scm
@@ -11,7 +11,7 @@
 ;;; Copyright © 2019 Ricardo Wurmus <[email-masked]>
 ;;; Copyright © 2020 Sergey Trofimov <[email-masked]>
 ;;; Copyright © 2021 Guillaume Le Vaillant <[email-masked]>
-;;; Copyright © 2021 Petr Hodina <[email-masked]>
+;;; Copyright © 2021, 2022 Petr Hodina <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -32,16 +32,25 @@ (define-module (gnu packages android)
   #:use-module (guix packages)
   #:use-module (guix download)
   #:use-module (guix gexp)
+  #:use-module (guix utils)
+  #:use-module (ice-9 match)
+  #:use-module (srfi srfi-1)
+  #:use-module (srfi srfi-26)
   #:use-module (guix git-download)
   #:use-module (guix build-system android-ndk)
   #:use-module (guix build-system gnu)
   #:use-module (guix build-system go)
   #:use-module (guix build-system python)
+  #:use-module (guix build-system copy)
   #:use-module (guix build-system trivial)
   #:use-module ((guix licenses) #:prefix license:)
   #:use-module (gnu packages)
+  #:use-module (gnu packages admin)
+  #:use-module (gnu packages base)
+  #:use-module (gnu packages bash)
   #:use-module (gnu packages check)
   #:use-module (gnu packages compression)
+  #:use-module (gnu packages cpio)
   #:use-module (gnu packages docker)
   #:use-module (gnu packages gcc)
   #:use-module (gnu packages gnupg)
@@ -1268,3 +1277,64 @@ (define-public enjarify
 applications.  Enjarify can translate the Dalvik bytecode back to equivalent
 Java bytecode, which simplifies the analysis of Android applications.")
     (license license:asl2.0)))
+
+(define-public pmos-installer
+  (package
+    (name "pmos-installer")
+    (version "1.0.0")
+    (source (origin
+              (method git-fetch)
+              (uri (git-reference
+                    (url "https://gitlab.com/sdm845-mainline/pmos-installer")
+                    (recursive? #t)
+                    (commit version)))
+              (file-name (git-file-name name version))
+              (sha256
+               (base32
+                "0lbdk2453bywdibys35zyf1j27a1m11a7q8jvmgjf99v77l9rrbx"))))
+    (build-system copy-build-system)
+    (arguments
+     `(#:install-plan '(("makeinstaller.sh" "bin/makeinstaller.sh") ("initrd"
+                                                                     "initrd"))
+       #:phases
+       (modify-phases %standard-phases
+         (add-after 'install 'wrap-shellscript
+           (lambda* (#:key inputs outputs #:allow-other-keys)
+             (let ((out (assoc-ref outputs "out")))
+               (substitute* (string-append out "/bin/makeinstaller.sh")
+                 ;; Typo in name
+                 ;; https://gitlab.com/sdm845-mainline/pmos-installer/-/issues/5
+                 (("vmlinuz-") "vmlinuz")
+                 ;; Path to initrd
+                 (("\"\\$\\(dirname \"\\$0\"\\)\"") (string-append out)))
+               (wrap-program (string-append out "/bin/makeinstaller.sh")
+                             `("PATH" ":" prefix
+                               ,(append (map (lambda (dir)
+                                               (string-append (assoc-ref
+                                                               inputs dir)
+                                                              "/bin"))
+                                             '("coreutils" "cpio"
+                                               "grep"
+                                               "zip"
+                                               "mkbootimg"
+                                               "pmbootstrap"
+                                               "sudo"
+                                               "sed"
+                                               "util-linux"
+                                               "which")))))))))))
+    (inputs (list bash-minimal
+                  coreutils
+                  pmbootstrap
+                  grep
+                  util-linux
+                  mkbootimg
+                  cpio
+                  zip
+                  sed
+                  which
+                  sudo))
+    (home-page "https://gitlab.com/sdm845-mainline/pmos-installer")
+    (synopsis "Flashable installer for postmarketOS")
+    (description "This package provides a flashable installer for
+        postmarketOS.")
+    (license license:gpl3+)))
-- 
2.35.1