Subject: Re: vscodium

From: Leo Prikler <[email-masked]>
Date: Wed, 06 Jan 2021 23:38:53 +0100

Hello Hamzeh,

Am Donnerstag, den 07.01.2021, 00:19 +0330 schrieb Hamzeh Nasajpour:
> Hello,
> 
> I want to package the `vscode` in guix. Actually I packaged it, but I
> faced with some issues that I think the package definition needs some
> modifications.
> 
> I installed it and I get this error:
> ```
> $ codium --verbose
> Cannot upload crash dump: cannot exec /usr/bin/wget
> Unexpected crash report id length
> Failed to get crash dump id.
> Report Id:
> [1338:1217/162312.625705:ERROR:sandbox_linux.cc(374)]
> InitializeSandbox() called with multiple threads in process gpu-
> process.
> Cannot upload crash dump: cannot exec /usr/bin/wget
> Unexpected crash report id length
> Failed to get crash dump id.
> Report Id:
> 
> $ codium --verbose --disable-gpu
> Cannot upload crash dump: cannot exec /usr/bin/wget
> Unexpected crash report id length
> Failed to get crash dump id.
> Report Id:
> Cannot upload crash dump: cannot exec /usr/bin/wget
> Unexpected crash report id length
> Failed to get crash dump id.
> Report Id:
> ```
You probably want to patch the reference to /usr/bin/wget using
substitute*.  That being said, I'm not sure whether that will fix the
original issue.

> While I can run it with `--help` and `--version` options:
> ```
> $ codium --version
> 1.51.1
> e5a624b788d92b8d34d1392e4c4d9789406efe8f
> x64
> 
> $ codium --help
> VSCodium 1.51.1
> 
> Usage: codium [options][paths...]
> 
> To read from stdin, append '-' (e.g. 'ps aux | grep code | codium -')
> 
> Options
>   -d --diff <file> <file>           Compare two files with each
> other.
>   -a --add <folder>                 Add folder(s) to the last active
> window.
>   -g --goto <file:line[:character]> Open a file at the path on the
> specified line and character position.
>   -n --new-window                   Force to open a new window.
>   -r --reuse-window                 Force to open a file or folder in
> an already opened window.
>   --folder-uri <uri>                Opens a window with given folder
> uri(s)
>   --file-uri <uri>                  Opens a window with given file
> uri(s)
>   -w --wait                         Wait for the files to be closed
> before returning.
>   --locale <locale>                 The locale to use (e.g. en-US or
> zh-TW).
>   --user-data-dir <dir>             Specifies the directory that user
> data is kept in. Can be used to open multiple distinct instances of
> Code.
>   -h --help                         Print usage.
> 
> ...
> ```
> 
> The package definition is here:
> ```
> (define-module (px packages programming)
>   #:use-module ((guix licenses) #:prefix license:)
>   #:use-module (guix download)
>   #:use-module (guix packages)
>   #:use-module (guix utils)
>   #:use-module (guix build-system trivial)
>   #:use-module (gnu packages bash)
>   #:use-module (gnu packages bootstrap)
>   #:use-module (gnu packages commencement)
>   #:use-module (gnu packages compression)
>   #:use-module (gnu packages cups)
>   #:use-module (gnu packages elf)
>   #:use-module (gnu packages fontutils)
>   #:use-module (gnu packages gl)
>   #:use-module (gnu packages base)
>   #:use-module (gnu packages gcc)
>   #:use-module (gnu packages glib)
>   #:use-module (gnu packages gtk)
>   #:use-module (gnu packages linux)
>   #:use-module (gnu packages nss)
>   #:use-module (gnu packages xdisorg)
>   #:use-module (gnu packages xml)
>   #:use-module (gnu packages xorg))
>  
>  (define-public vscodium
>   (package
>     (name "vscodium")
>     (version "1.51.1")
>     (source (origin
>              (method url-fetch)
>              (uri "
> https://github.com/VSCodium/vscodium/releases/download/1.51.1/VSCodium-linux-x64-1.51.1.tar.gz
> ")
>              (sha256
>               (base32
>                "0hn4pqmabz3qf3bbqnn1fz7fcgzdkp2lwr2yzgmx8hhh3cff8bnb"
> ))))
>     (build-system trivial-build-system)
>     (arguments
>      `(#:modules ((guix build utils))
>        #:builder (begin
>                    (use-modules (guix build utils)
>                                 (srfi srfi-26))
>                    (let* ((source     (assoc-ref %build-inputs
> "source"))
>                           (alsa-lib   (assoc-ref %build-inputs "alsa-
> lib"))
>                           (at-spi2-atk (assoc-ref %build-inputs "at-
> spi2-atk"))
>                           (at-spi2-core(assoc-ref %build-inputs "at-
> spi2-core"))
>                           (atk        (assoc-ref %build-inputs
> "atk"))
>                           (bash       (assoc-ref %build-inputs
> "bash"))
>                           (cairo      (assoc-ref %build-inputs
> "cairo"))
>                           (coreutils  (assoc-ref %build-inputs
> "coreutils"))
>                           (cups       (assoc-ref %build-inputs
> "cups"))
>                           (dbus       (assoc-ref %build-inputs
> "dbus"))
>                           (expat      (assoc-ref %build-inputs
> "expat"))
>                           (fontconfig (assoc-ref %build-inputs
> "fontconfig"))
>                           (gcc        (assoc-ref %build-inputs
> "gcc"))
>                           (ar         (assoc-ref %build-inputs "gcc-
> toolchain"))
>                           (gdk-pixbuf (assoc-ref %build-inputs "gdk-
> pixbuf"))
>                           (glib       (assoc-ref %build-inputs
> "glib")) 
>                           (gzip       (assoc-ref %build-inputs
> "gzip"))
>                           (gtk        (assoc-ref %build-inputs
> "gtk+"))
>                           (pango      (assoc-ref %build-inputs
> "pango"))
>                           (patchelf   (assoc-ref %build-inputs
> "patchelf"))
>                           (tar        (assoc-ref %build-inputs
> "tar"))
>                           (xz         (assoc-ref %build-inputs "xz"))
>                           (libdrm     (assoc-ref %build-inputs
> "libdrm"))
>                           (libx11     (assoc-ref %build-inputs
> "libx11"))
>                           (libxcb     (assoc-ref %build-inputs
> "libxcb"))
>                           (libxcursor (assoc-ref %build-inputs
> "libxcursor"))
>                           (libxcomposite (assoc-ref %build-inputs
> "libxcomposite"))
>                           (libxdamage (assoc-ref %build-inputs
> "libxdamage"))
>                           (libxext    (assoc-ref %build-inputs
> "libxext"))
>                           (libxfixes  (assoc-ref %build-inputs
> "libxfixes"))
>                           (libxi      (assoc-ref %build-inputs
> "libxi"))
>                           (libxrandr  (assoc-ref %build-inputs
> "libxrandr"))
>                           (libxrender (assoc-ref %build-inputs
> "libxrender"))
>                           (libxss     (assoc-ref %build-inputs
> "libxscrnsaver"))
>                           (libxtst    (assoc-ref %build-inputs
> "libxtst"))
>                           (libnss     (assoc-ref %build-inputs
> "nss"))
>                           (libnspr    (assoc-ref %build-inputs
> "nspr"))
>                           (ld-so      (string-append (assoc-ref
> %build-inputs "glibc")
>                                            ,(glibc-dynamic-linker)))
>                           (mesa       (assoc-ref %build-inputs
> "mesa"))
>                           (bin-dir    (string-append %output "/bin"))
>                           (lib-dir    (string-append %output
> "/lib/vscode"))
>                           (codium-exec(string-append %output
> "/lib/vscode/codium")))
>                      (mkdir-p bin-dir)
>                      (setenv "PATH" (string-append 
>                                       (string-append
> ar         "/bin:")
>                                       (string-append
> bash       "/bin:")
>                                       (string-append
> coreutils  "/bin:")
>                                       (string-append
> gzip       "/bin:")
>                                       (string-append
> patchelf   "/bin:")
>                                       (string-append
> tar        "/bin:")
>                                       (string-append
> xz         "/bin:")))
>                      (invoke "tar" "xvf" source)
>                      (invoke "mkdir" "-p" lib-dir)
>                      (invoke "mkdir" "-p" bin-dir)
>                      (copy-recursively "." lib-dir)
>                      (substitute* (string-append lib-dir
> "/bin/codium")
>                              (("ELECTRON=" all) (string-append
> "VSCODE_PATH='" lib-dir "'\nELECTRON=")))
>                      (invoke "ln" "-s" (string-append lib-dir
> "/bin/codium") bin-dir)
>                      (invoke "patchelf" "--set-interpreter" ld-so
> codium-exec)
> 
> ;                     (substitute*
> '("usr/share/applications/codium.desktop")
> ;                             (("Exec=/usr/share/codium/codium")
> (string-append "Exec=" %output "/bin/codium")))
> ;                     (substitute* '("usr/share/applications/codium-
> url-handler.desktop")
> ;                             (("Exec=/usr/share/codium/codium")
> (string-append "Exec=" %output "/bin/codium")))
> ;                     (invoke "cp"
> "usr/share/codium/resources/app/resources/linux/code.png" (string-
> append %output "/share/pixmaps/code.png"))
>                      (invoke "cat" (string-append bin-dir "/codium"))
That is not a very usable package definition at all.  Please try to
build things from source instead of relying on patchelf-based hacks.

>                      (wrap-program codium-exec
>                              `("FONTCONFIG_PATH" ":" prefix
> (,(string-append fontconfig "/etc/fonts"))))
>                      (wrap-program codium-exec
>                              `("LD_LIBRARY_PATH" ":" prefix
> (,(string-append alsa-lib "/lib"))))
>                      (wrap-program codium-exec
>                              `("LD_LIBRARY_PATH" ":" prefix
> (,(string-append at-spi2-core "/lib"))))
>                      (wrap-program codium-exec
>                              `("LD_LIBRARY_PATH" ":" prefix
> (,(string-append at-spi2-atk "/lib"))))
>                      (wrap-program codium-exec
>                              `("LD_LIBRARY_PATH" ":" prefix
> (,(string-append atk "/lib"))))
>                      (wrap-program codium-exec
>                              `("LD_LIBRARY_PATH" ":" prefix
> (,(string-append dbus "/lib"))))
>                      (wrap-program codium-exec
>                              `("LD_LIBRARY_PATH" ":" prefix
> (,(string-append cairo "/lib"))))
>                      (wrap-program codium-exec
>                              `("LD_LIBRARY_PATH" ":" prefix
> (,(string-append cups "/lib"))))
>                      (wrap-program codium-exec
>                              `("LD_LIBRARY_PATH" ":" prefix
> (,(string-append expat "/lib"))))
>                      (wrap-program codium-exec
>                              `("LD_LIBRARY_PATH" ":" prefix
> (,(string-append gcc "/lib"))))
>                      (wrap-program codium-exec
>                              `("LD_LIBRARY_PATH" ":" prefix
> (,(string-append glib "/lib"))))
>                      (wrap-program codium-exec
>                              `("LD_LIBRARY_PATH" ":" prefix
> (,(string-append gdk-pixbuf "/lib"))))
>                      (wrap-program codium-exec
>                              `("LD_LIBRARY_PATH" ":" prefix
> (,(string-append gtk "/lib"))))
>                      (wrap-program codium-exec
>                              `("LD_LIBRARY_PATH" ":" prefix
> (,(string-append libdrm "/lib"))))
>                      (wrap-program codium-exec
>                              `("LD_LIBRARY_PATH" ":" prefix
> (,(string-append libx11 "/lib"))))
>                      (wrap-program codium-exec
>                              `("LD_LIBRARY_PATH" ":" prefix
> (,(string-append libxcb "/lib"))))
>                      (wrap-program codium-exec  
>                              `("LD_LIBRARY_PATH" ":" prefix
> (,(string-append libxcomposite "/lib"))))
>                      (wrap-program codium-exec  
>                              `("LD_LIBRARY_PATH" ":" prefix
> (,(string-append libxcursor "/lib"))))
>                      (wrap-program codium-exec
>                              `("LD_LIBRARY_PATH" ":" prefix
> (,(string-append libxdamage "/lib"))))
>                      (wrap-program codium-exec
>                              `("LD_LIBRARY_PATH" ":" prefix
> (,(string-append libxext "/lib"))))
>                      (wrap-program codium-exec
>                              `("LD_LIBRARY_PATH" ":" prefix
> (,(string-append libxfixes "/lib"))))
>                      (wrap-program codium-exec
>                              `("LD_LIBRARY_PATH" ":" prefix
> (,(string-append libxi "/lib"))))
>                      (wrap-program codium-exec
>                              `("LD_LIBRARY_PATH" ":" prefix
> (,(string-append libxrandr "/lib"))))
>                      (wrap-program codium-exec
>                              `("LD_LIBRARY_PATH" ":" prefix
> (,(string-append libxrender "/lib"))))
>                      (wrap-program codium-exec
>                              `("LD_LIBRARY_PATH" ":" prefix
> (,(string-append libxtst "/lib"))))
>                      (wrap-program codium-exec
>                              `("LD_LIBRARY_PATH" ":" prefix
> (,(string-append libxss "/lib"))))
>                      (wrap-program codium-exec
>                              `("LD_LIBRARY_PATH" ":" prefix
> (,(string-append libnss "/lib/nss"))))
>                      (wrap-program codium-exec
>                              `("LD_LIBRARY_PATH" ":" prefix
> (,(string-append libnspr "/lib"))))
>                      (wrap-program codium-exec
>                              `("LD_LIBRARY_PATH" ":" prefix
> (,(string-append mesa "/lib"))))
>                      (wrap-program codium-exec
>                              `("LD_LIBRARY_PATH" ":" prefix
> (,(string-append pango "/lib"))))
> 					 #t))))
You should actually be able to do all this in a single wrap-program.
>     (native-inputs `(("alsa-lib" ,alsa-lib)
>                      ("at-spi2-atk" ,at-spi2-atk)
>                      ("coreutils" ,coreutils)
>                      ("cairo" ,cairo)
>                      ("cups" ,cups)
>                      ("dbus" ,dbus)
>                      ("expat" ,expat)
>                      ("fontconfig" ,fontconfig)
>                      ("gcc" ,gcc "lib")
>                      ("gcc-toolchain" ,gcc-toolchain)
>                      ("glib" ,glib)
>                      ("gdk-pixbuf" ,gdk-pixbuf)
>                      ("gtk+" ,gtk+)
>                      ("glibc" ,glibc)
>                      ("libdrm" ,libdrm)
>                      ("libxcb" ,libxcb)
>                      ("libxcursor" ,libxcursor)
>                      ("libx11" ,libx11)
>                      ("libxcomposite" ,libxcomposite)
>                      ("libxdamage" ,libxdamage)
>                      ("libxext" ,libxext)
>                      ("libxfixes" ,libxfixes)
>                      ("libxi" ,libxi)
>                      ("libxrandr" ,libxrandr)
>                      ("libxrender" ,libxrender)
>                      ("libxscrnsaver" ,libxscrnsaver)
>                      ("libxtst" ,libxtst)
>                      ("mesa" ,mesa)
>                      ("gzip" ,gzip)
>                      ("pango" ,pango)
>                      ("patchelf" ,patchelf)
>                      ("nss" ,nss)
>                      ("nspr" ,nspr)
>                      ("tar" ,tar)
>                      ("xz" ,xz)))
A lot of those native-inputs should probably be regular inputs.
> 	(inputs `(("bash" ,bash)
> 	          ("zlib" ,zlib)))
> 	(home-page "https://github.com/VSCodium/vscodium")
>     (synopsis "Free/Libre Open Source Software Binaries of VSCode")
>     (description
>      "Free/Libre Open Source Software Binaries of VSCode.")
Free blobs are still blobs.  Just like with the Linux kernel or
Chromium, you will have to download the original source, then apply
whatever patches VSCodium applies (if any) and build VSCodium using the
patched source.  See any package, that uses computed origins.
>     (license license:expat)))
> ```
> 
> Do you have any idea? Please help, I need this IDE urgently :)
I'm not sure how urgent "urgently" is, but in my opinion you don't need
a package description to figure out the correct set of arguments
towards patchelf.  That said, if you do have the chance to invest time
into a proper definition, you should really try to build from source.

As far as getting this into Guix itself is concerned, I fear that
Microsoft's heavy branding might make it hard to comply with the FSDG. 
IIUC VSCodium undoes some of the branding, but I have no idea how
thorough they are.

Regards,
Leo