~abcdw/rde-devel

feature: ungoogled-chromium: Change default user data dir. v1 APPLIED

Nicolas Graves: 4
 feature: ungoogled-chromium: Change default user data dir.
 feature: ungoogled-chromium: Change default user data dir.
 features: Add libreoffice.
 features: Add libreoffice.

 4 files changed, 305 insertions(+), 9 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~abcdw/rde-devel/patches/44062/mbox | git am -3
Learn more about email & git

[PATCH 1/2] feature: ungoogled-chromium: Change default user data dir. Export this patch

[startup-flags]: Add default for higher XDG base dirs compliance. More precise
predicate.
---
 src/rde/features/web-browsers.scm | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/rde/features/web-browsers.scm b/src/rde/features/web-browsers.scm
index d2ecf9a9..2d6eb20f 100644
--- a/src/rde/features/web-browsers.scm
+++ b/src/rde/features/web-browsers.scm
@@ -36,15 +36,21 @@
  #:export (feature-ungoogled-chromium
            feature-nyxt))

;; The issue with Chromium is that like Libreoffice, all user data is
;; managed in a single directory in ~/.config by default. Like Libreoffice,
;; the content of this single directory better matches XDG_STATE_HOME for the
;; most part, but since it still may contains config data, we prefer to put it
;; in XDG_DATA_HOME for user config safety while the issue is upstream.

(define* (feature-ungoogled-chromium
          #:key
          (ungoogled-chromium ungoogled-chromium/wayland)
          (default-browser? #f)
          (startup-flags '()))
          (startup-flags '("--user-data-dir=$XDG_DATA_HOME/chromium")))
  "Configure the Chromium browser."
  (ensure-pred any-package? ungoogled-chromium)
  (ensure-pred boolean? default-browser?)
  (ensure-pred list? startup-flags)
  (ensure-pred list-of-strings? startup-flags)

  (define f-name 'ungoogled-chromium)

-- 
2.41.0

[PATCH v2 1/2] feature: ungoogled-chromium: Change default user data dir. Export this patch

[startup-flags]: Add default for higher XDG base dirs compliance. More precise
predicate.
---
 src/rde/features/web-browsers.scm | 67 +++++++++++++++++++++++++++----
 1 file changed, 60 insertions(+), 7 deletions(-)

diff --git a/src/rde/features/web-browsers.scm b/src/rde/features/web-browsers.scm
index d2ecf9a9..86194c24 100644
--- a/src/rde/features/web-browsers.scm
+++ b/src/rde/features/web-browsers.scm
@@ -28,26 +28,78 @@
  #:use-module (gnu home services xdg)
  #:use-module (gnu packages browser-extensions)
  #:use-module (gnu packages chromium)
  #:use-module ((gnu packages base) #:select (glibc-utf8-locales))
  #:use-module (gnu packages bash)
  #:use-module (gnu packages web-browsers)
  #:use-module (gnu services)
  #:use-module (gnu system keyboard)
  #:use-module (guix build-system trivial)
  #:use-module (guix gexp)
  #:use-module (guix packages)
  #:use-module (ice-9 match)
  #:export (feature-ungoogled-chromium
            feature-nyxt))

;; The issue with Chromium is that like Libreoffice, all user data is
;; managed in a single directory in ~/.config by default. The content of this
;; single directory better matches XDG_STATE_HOME for the most part, but like
;; most non-XDG compliant big apps, we put it in XDG_DATA_HOME until they are.

(define* (feature-ungoogled-chromium
          #:key
          (ungoogled-chromium ungoogled-chromium/wayland)
          (default-browser? #f)
          (startup-flags '()))
          (default-startup-flags '("--user-data-dir=$XDG_DATA_HOME/chromium"))
          (desktop-startup-flags '("")))
  "Configure the Chromium browser."
  (ensure-pred any-package? ungoogled-chromium)
  (ensure-pred boolean? default-browser?)
  (ensure-pred list? startup-flags)
  (ensure-pred list-of-strings? default-startup-flags)
  (ensure-pred list-of-strings? desktop-startup-flags)

  (define f-name 'ungoogled-chromium)

  (define rde-ungoogled-chromium
    (package
      (inherit ungoogled-chromium)
      (inputs
       (list bash-minimal glibc-utf8-locales ungoogled-chromium))
      (build-system trivial-build-system)
      (arguments
       (list
        #:modules '((guix build utils))
        #:builder
        #~(begin
            (use-modules (guix build utils))
            (let* ((bash #$(this-package-input "bash-minimal"))
                   (chromium #$(this-package-input "ungoogled-chromium-wayland"))
                   (locales #$(this-package-input "glibc-utf8-locales"))
                   (exe (string-append #$output "/bin/chromium")))

              ;; Use a Unicode locale so we can substitute the file below.
              (setenv "GUIX_LOCPATH" (string-append locales "/lib/locale"))
              (setlocale LC_ALL "en_US.utf8")

              (mkdir-p (dirname exe))
              (symlink (string-append chromium "/bin/chromedriver")
                       (string-append #$output "/bin/chromedriver"))

              (call-with-output-file exe
                (lambda (port)
                  (format port "#!~a
exec ~a ~a $@"
                          (string-append bash "/bin/bash")
                          (string-append chromium "/bin/chromium")
                          (string-join '#$default-startup-flags " "))))
              (chmod exe #o555)

              ;; Provide the manual and .desktop file.
              (copy-recursively (string-append chromium "/share")
                                (string-append #$output "/share"))
              (substitute* (string-append
                            #$output "/share/applications/chromium.desktop")
                ((chromium) #$output))))))))

  (define (get-home-services config)
    "Return home services related to Ungoogled Chromium."
    (append
@@ -56,7 +108,8 @@
          (simple-service
           'set-chromium-as-default-browser
           home-environment-variables-service-type
           `(("BROWSER" . ,(file-append ungoogled-chromium "/bin/chromium"))))
           `(("BROWSER" .
              ,(file-append rde-ungoogled-chromium "/bin/chromium"))))
          (simple-service
           'chromium-xdg-defaults
           home-xdg-mime-applications-service-type
@@ -73,7 +126,7 @@
           f-name
           config
           `((with-eval-after-load 'browse-url
               (setq browse-url-chromium-arguments ',startup-flags))
               (setq browse-url-chromium-arguments ',desktop-startup-flags))
             ,@(if (get-value 'emacs-embark config)
                   `((with-eval-after-load 'embark
                       (define-key embark-url-map "c" 'browse-url-chromium)))
@@ -84,7 +137,7 @@
       'add-chromium-packages
       home-profile-service-type
       (list
        ungoogled-chromium
        rde-ungoogled-chromium
        ublock-origin/chromium))
      (simple-service
       'add-chromium-xdg-desktop-entry
@@ -99,8 +152,8 @@
           (config
            `((exec . ,#~(string-join
                          (list
                           #$(file-append ungoogled-chromium "/bin/chromium")
                           #$@startup-flags "%U")))
                           #$(file-append rde-ungoogled-chromium "/bin/chromium")
                           #$@desktop-startup-flags "%U")))
              (terminal . #f)
              (comment . "Access the Internet")))))))))))

-- 
2.41.0

[PATCH 2/2] features: Add libreoffice. Export this patch

---
 src/rde/features/libreoffice.scm | 110 +++++++++++++++++++++++++++++++
 1 file changed, 110 insertions(+)
 create mode 100644 src/rde/features/libreoffice.scm

diff --git a/src/rde/features/libreoffice.scm b/src/rde/features/libreoffice.scm
new file mode 100644
index 00000000..e72d6454
--- /dev/null
+++ b/src/rde/features/libreoffice.scm
@@ -0,0 +1,110 @@
;;; rde --- Reproducible development environment.
;;;
;;; Copyright © 2023 Nicolas Graves <ngraves@ngraves.fr>
;;;
;;; This file is part of rde.
;;;
;;; rde is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; rde is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with rde.  If not, see <http://www.gnu.org/licenses/>.

(define-module (rde features libreoffice)
  #:use-module (rde features)
  #:use-module (rde features predicates)
  #:use-module (gnu home services)
  #:use-module (gnu home services xdg)
  #:use-module (gnu packages libreoffice)
  #:use-module (gnu services)
  #:use-module (guix gexp)
  #:use-module (guix packages)
  #:use-module (guix build-system trivial)
  #:use-module (ice-9 match)
  #:export (feature-libreoffice))

;; The issue with Libreoffice is that like Chromium, all user data is
;; managed in a single directory in ~/.config by default. Like Chromium,
;; the content of this single directory better matches XDG_STATE_HOME for the
;; most part, but since it still may contains config data, we prefer to put it
;; in XDG_DATA_HOME for user config safety while the issue is upstream.

;; Modifing the place of this directory is however more tedious, since the
;; startup flag -env:UserInstallation=file:///tmp/test alone doesn't work
;; in Guix, and is hard to debug and fix -- knowledge of gdb and cpp needed,
;; long compilation times...

;; As a workaround, we modify the `bootstraprc' file in Libreoffice's output.
;; But there doesn't seem to be an option for indicating bootstraprc location,
;; so we make a complete copy with the desired changes. This also enables us
;; to easily change the flags in the desktop files.

(define (rde-libreoffice pkg xdg-data-home flags)
  (package
    (inherit pkg)
    (name "libreoffice")
    (source (origin (inherit (package-source pkg))))
    (build-system trivial-build-system)
    (arguments
     (list
      #:modules '((guix build utils))
      #:builder
      #~(begin
          (use-modules (guix build utils))
          (let* ((lo #$(file-append (this-package-native-input "libreoffice") "")))
            (copy-recursively lo #$output)
            (substitute* (string-append
                          #$output "/lib/libreoffice/program/bootstraprc")
              (("UserInstallation=.*")
               (string-append
                "UserInstallation=" #$xdg-data-home "/libreoffice")))
            (substitute*
                (find-files (string-append #$output "/share/applications"))
              (("^Exec=([^ ]*) (.*)" all bin rest)
               (string-join (list "Exec=" bin #$@flags rest))))))))
    ;; In native-inputs so that it can be collected if space is needed.
    (native-inputs (list pkg))
    (inputs '())
    (propagated-inputs '())))

(define* (feature-libreoffice
          #:key
          (libreoffice libreoffice)
          (startup-flags '("--no-logo")))
  "Configure LibreOffice."
  (ensure-pred file-like? libreoffice)
  (ensure-pred list-of-strings? startup-flags)

  (define f-name 'libreoffice)

  (define (get-home-services config)
    "Return home services related to LibreOffice."
    (require-value 'xdg-base-directories-configuration config)
    (let* ((data-home (home-xdg-base-directories-configuration-data-home
                       (get-value 'xdg-base-directories-configuration config)))
           (full-flags (cons*
                        (string-append "-env:UserInstallation=file://"
                                       (get-value 'home-directory config)
                                       (string-drop data-home 5) ; 5 <-> "$HOME"
                                       "/libreoffice")
                        startup-flags))
           (lo-data-home (string-append ; $SYSUSERHOME is the libreoffice syntax
                          "$SYSUSERHOME" (string-drop data-home 5))))
      (list
       (simple-service
        'add-libreoffice-package
         home-profile-service-type
         (list
          (rde-libreoffice libreoffice lo-data-home full-flags))))))

  (feature
   (name f-name)
   (values `((,f-name . #t)))
   (home-services-getter get-home-services)))
-- 
2.41.0

[PATCH v2 2/2] features: Add libreoffice. Export this patch

---
 src/rde/features/libreoffice.scm | 127 +++++++++++++++++++++++++++++++
 1 file changed, 127 insertions(+)
 create mode 100644 src/rde/features/libreoffice.scm

diff --git a/src/rde/features/libreoffice.scm b/src/rde/features/libreoffice.scm
new file mode 100644
index 00000000..83d499ec
--- /dev/null
+++ b/src/rde/features/libreoffice.scm
@@ -0,0 +1,127 @@
;;; rde --- Reproducible development environment.
;;;
;;; Copyright © 2023 Nicolas Graves <ngraves@ngraves.fr>
;;;
;;; This file is part of rde.
;;;
;;; rde is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; rde is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with rde.  If not, see <http://www.gnu.org/licenses/>.

(define-module (rde features libreoffice)
  #:use-module (rde features)
  #:use-module (rde features predicates)
  #:use-module (gnu home services)
  #:use-module (gnu home services xdg)
  #:use-module (gnu packages libreoffice)
  #:use-module (gnu services)
  #:use-module (guix gexp)
  #:use-module (guix packages)
  #:use-module (guix build-system trivial)
  #:use-module (ice-9 match)
  #:export (feature-libreoffice))

;; The issue with Libreoffice is that like Chromium, all user data is
;; managed in a single directory in ~/.config by default. The content of this
;; single directory better matches XDG_STATE_HOME for the most part, but like
;; most non-XDG compliant big apps, we put it in XDG_DATA_HOME until they are.

;; Modifing the place of this directory is however more tedious, since the
;; startup flag -env:UserInstallation=file:///tmp/test alone doesn't work
;; in Guix.

;; As a workaround, we modify the `bootstraprc' file in Libreoffice's output.
;; But there doesn't seem to be an option for indicating bootstraprc location,
;; so we make a complete copy with the desired changes. This also enables us
;; to easily change the flags in the desktop files.

;; TODO Patch libreoffice upstream so that it reads /etc/libreoffice/bootstraprc
;; instead (will enable to go from copy to wrap in RDE).

(define (rde-libreoffice pkg data-home-suffix home flags)
  (package
    (inherit pkg)
    (name "libreoffice")
    (source (origin (inherit (package-source pkg))))
    (build-system trivial-build-system)
    (arguments
     (list
      #:modules '((guix build utils))
      #:builder
      #~(begin
          (use-modules (guix build utils))
          (let* ((lo #$(this-package-native-input "libreoffice")))
            ;; Copy everything
            (copy-recursively lo #$output)
            ;; Symlinks are copied too... so they need to be remade.
            (delete-file (string-append #$output "/bin/libreoffice"))
            (delete-file (string-append #$output "/bin/soffice"))
            (symlink (string-append
                      #$output "/lib/libreoffice/program/soffice")
                     (string-append #$output "/bin/libreoffice"))
            (symlink (string-append
                      #$output "/lib/libreoffice/program/soffice")
                     (string-append #$output "/bin/soffice"))
            ;; Make the default user installation XDG_DATA_HOME
            (substitute* (string-append
                          #$output "/lib/libreoffice/program/bootstraprc")
              (("UserInstallation=.*")
               (string-append "UserInstallation=$SYSUSERHOME"
                              #$data-home-suffix "/libreoffice")))
            (substitute* (string-append
                          #$output "/lib/libreoffice/program/soffice")
              (("\"\\$\\@\"[[:space:]]$")
               (string-append "\"-env:UserInstallation=file://"
                              #$home #$data-home-suffix
                              "/libreoffice\" \"$@\"\n")))
            ;; Add other flags to applications desktop files.
            (substitute*
                (find-files (string-append #$output "/share/applications"))
              (("^Exec=([^ ]*) (.*)" all bin rest)
               (string-join
                (list "Exec=" (string-append #$output "/bin/libreoffice")
                      #$@flags rest))))))))
    ;; In native-inputs so that it can be collected if space is needed.
    (native-inputs (list pkg))
    (inputs '())
    (propagated-inputs '())))

(define* (feature-libreoffice
          #:key
          (libreoffice libreoffice)
          (startup-flags '("--nologo")))
  "Configure LibreOffice."
  (ensure-pred file-like? libreoffice)
  (ensure-pred list-of-strings? startup-flags)

  (define f-name 'libreoffice)

  (define (get-home-services config)
    "Return home services related to LibreOffice."
    (require-value 'xdg-base-directories-configuration config)
    (let* ((data-home (home-xdg-base-directories-configuration-data-home
                       (get-value 'xdg-base-directories-configuration config))))
      (list
       (simple-service
        'add-libreoffice-package
        home-profile-service-type
        (list
         (rde-libreoffice
          libreoffice
          (string-drop data-home (string-length "$HOME"))
          (get-value 'home-directory config)
          startup-flags))))))

  (feature
   (name f-name)
   (values `((,f-name . #t)))
   (home-services-getter get-home-services)))
-- 
2.41.0