~abcdw/rde-devel

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
7 2

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

Details
Message ID
<20230827205719.9110-1-ngraves@ngraves.fr>
DKIM signature
missing
Download raw message
Patch: +8 -2
[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 2/2] features: Add libreoffice.

Details
Message ID
<20230827205719.9110-2-ngraves@ngraves.fr>
In-Reply-To
<20230827205719.9110-1-ngraves@ngraves.fr> (view parent)
DKIM signature
missing
Download raw message
Patch: +110 -0
---
 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
Details
Message ID
<87ttsgg7i5.fsf@trop.in>
In-Reply-To
<20230827205719.9110-1-ngraves@ngraves.fr> (view parent)
DKIM signature
missing
Download raw message
On 2023-08-27 22:57, Nicolas Graves wrote:

> [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.

DATA_DIRS should usually contain some static data.  It seems
XDG_STATE_HOME fits better here, isn't it?

https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html

> +
>  (define* (feature-ungoogled-chromium
>            #:key
>            (ungoogled-chromium ungoogled-chromium/wayland)
>            (default-browser? #f)
> -          (startup-flags '()))
> +          (startup-flags '("--user-data-dir=$XDG_DATA_HOME/chromium")))

Probably it's better to add it as a first argument to executable
directly in desktop file, this way it will work even if user define his
own #:startup-flags and it still possible to override it by specifying
it one more time with different value.

>    "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)

-- 
Best regards,
Andrew Tropin
Details
Message ID
<87msy8bwsh.fsf@ngraves.fr>
In-Reply-To
<87ttsgg7i5.fsf@trop.in> (view parent)
DKIM signature
missing
Download raw message
On 2023-08-30 14:16, Andrew Tropin wrote:

> On 2023-08-27 22:57, Nicolas Graves wrote:
>
>> [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.
>
> DATA_DIRS should usually contain some static data.  It seems
> XDG_STATE_HOME fits better here, isn't it?
>
> https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html

It could, I don't have a strong opinion here. What lead me to settle for
DATA_HOME was the fact that basically all big applications which do not
fully comply with the XDG specification yet seem to do that (in mine, I
have nyxt, epiphany, webkitgtk...). Same thing for Libreoffice. 
>
>> +
>>  (define* (feature-ungoogled-chromium
>>            #:key
>>            (ungoogled-chromium ungoogled-chromium/wayland)
>>            (default-browser? #f)
>> -          (startup-flags '()))
>> +          (startup-flags '("--user-data-dir=$XDG_DATA_HOME/chromium")))
>
> Probably it's better to add it as a first argument to executable
> directly in desktop file, this way it will work even if user define his
> own #:startup-flags and it still possible to override it by specifying
> it one more time with different value.

Yes, I also have a discussion to raise about CLI in case of startup
flags. Basically, if we would want to start from command-line for some
reason, we might (or not) want the startup flags to apply. The simplest
use-case would be --incognito or --kiosk or --remote-debugging-port
here.

When we would lauch with either of these flags, we would want data to
still go to the right place and not create a new directory. In this
case, isn't it more simple to create a new wrapper executable with the
argument and then use it in the desktop file ? 

Same thing for my libreoffice patch. Also sorry if you test it, the
--no-logo part has to be replaced by --nologo. Will do it in a v2 after
this discussion. 

>
>>    "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)

-- 
Best regards,
Nicolas Graves
Details
Message ID
<87a5u7h2mi.fsf@trop.in>
In-Reply-To
<87msy8bwsh.fsf@ngraves.fr> (view parent)
DKIM signature
missing
Download raw message
On 2023-08-30 13:21, Nicolas Graves wrote:

> On 2023-08-30 14:16, Andrew Tropin wrote:
>
>> On 2023-08-27 22:57, Nicolas Graves wrote:
>>
>>> [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.
>>
>> DATA_DIRS should usually contain some static data.  It seems
>> XDG_STATE_HOME fits better here, isn't it?
>>
>> https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
>
> It could, I don't have a strong opinion here. What lead me to settle for
> DATA_HOME was the fact that basically all big applications which do not
> fully comply with the XDG specification yet seem to do that (in mine, I
> have nyxt, epiphany, webkitgtk...). Same thing for Libreoffice. 
>>
>>> +
>>>  (define* (feature-ungoogled-chromium
>>>            #:key
>>>            (ungoogled-chromium ungoogled-chromium/wayland)
>>>            (default-browser? #f)
>>> -          (startup-flags '()))
>>> +          (startup-flags '("--user-data-dir=$XDG_DATA_HOME/chromium")))
>>
>> Probably it's better to add it as a first argument to executable
>> directly in desktop file, this way it will work even if user define his
>> own #:startup-flags and it still possible to override it by specifying
>> it one more time with different value.
>
> Yes, I also have a discussion to raise about CLI in case of startup
> flags. Basically, if we would want to start from command-line for some
> reason, we might (or not) want the startup flags to apply. The simplest
> use-case would be --incognito or --kiosk or --remote-debugging-port
> here.
>
> When we would lauch with either of these flags, we would want data to
> still go to the right place and not create a new directory. In this
> case, isn't it more simple to create a new wrapper executable with the
> argument and then use it in the desktop file ? 

Yes, actually I also thoughts about using a wrapper for it.  Maybe we
can split startup flags into wrapper-startup-flags and
desktop-item-startup-flags or something like this.  Not now (or maybe
never), but in general it may be useful if they are added with a
service, so other features can extend the service to add more flags.

>
> Same thing for my libreoffice patch. Also sorry if you test it, the
> --no-logo part has to be replaced by --nologo. Will do it in a v2 after
> this discussion. 
>

I didn't test it yet, I was too tired yesterday, when was reading the
thread.  Actually it was unexpected place to find a libreoffice patch :)
Try to use --cover-letter when you want to combine a bunch of related
commits in one patch series.

>>
>>>    "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)

-- 
Best regards,
Andrew Tropin

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

Details
Message ID
<20230901103229.21669-1-ngraves@ngraves.fr>
In-Reply-To
<87ttsgg7i5.fsf@trop.in> (view parent)
DKIM signature
missing
Download raw message
Patch: +60 -7
[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 v2 2/2] features: Add libreoffice.

Details
Message ID
<20230901103229.21669-2-ngraves@ngraves.fr>
In-Reply-To
<20230901103229.21669-1-ngraves@ngraves.fr> (view parent)
DKIM signature
missing
Download raw message
Patch: +127 -0
---
 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

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

Details
Message ID
<87ledphtcc.fsf@trop.in>
In-Reply-To
<20230901103229.21669-1-ngraves@ngraves.fr> (view parent)
DKIM signature
missing
Download raw message
On 2023-09-01 12:32, Nicolas Graves wrote:

> [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")))))))))))

Please, try to keep commit messages consistent.

Applied both patches, didn't test them.  Thank you for working on it.

-- 
Best regards,
Andrew Tropin
Reply to thread Export thread (mbox)