[PATCH] home: Let user configure XDG base directories.

  • Open
  • quality assurance status badge
Details
2 participants
  • Andrew Tropin
  • Antero Mejr
Owner
unassigned
Submitted by
Antero Mejr
Severity
normal
A
A
Antero Mejr wrote on 12 Dec 2022 04:00
(address . guix-patches@gnu.org)(name . Antero Mejr)(address . antero@mailbox.org)
20221212030049.4725-1-antero@mailbox.org
* gnu/home.scm (home-environment)[base-xdg-configuration]: New field.
* gnu/home/services/xdg.scm (ensure-xdg-base-dirs-on-activation): Make
XDG_RUNTIME_DIR directory if the configuration changes it from the default.
---
Allows making a runtime dir at ~/.local/runtime (or any other dir),
so users don't have to set up elogind or other greeters/PAM modules.

gnu/home.scm | 9 +++++++--
gnu/home/services/xdg.scm | 7 ++++++-
2 files changed, 13 insertions(+), 3 deletions(-)

Toggle diff (54 lines)
diff --git a/gnu/home.scm b/gnu/home.scm
index c95d1e0818..f100b575e3 100644
--- a/gnu/home.scm
+++ b/gnu/home.scm
@@ -39,6 +39,7 @@ (define-module (gnu home)
home-environment-essential-services
home-environment-services
home-environment-location
+ home-environment-base-xdg-configuration
home-environment-with-provenance
@@ -71,7 +72,10 @@ (define-record-type* <home-environment> home-environment
(location home-environment-location ; <location>
(default (and=> (current-source-location)
source-properties->location))
- (innate)))
+ (innate))
+
+ (base-xdg-configuration home-environment-base-xdg-configuration
+ (default (home-xdg-base-directories-configuration))))
(define (home-environment-default-essential-services he)
"Return the list of essential services for home environment."
@@ -83,7 +87,8 @@ (define (home-environment-default-essential-services he)
(service home-symlink-manager-service-type)
(service home-fontconfig-service-type)
- (service home-xdg-base-directories-service-type)
+ (service home-xdg-base-directories-service-type
+ (home-environment-base-xdg-configuration he))
(service home-shell-profile-service-type)
(service home-service-type)
diff --git a/gnu/home/services/xdg.scm b/gnu/home/services/xdg.scm
index 865f8b81d7..b62580461e 100644
--- a/gnu/home/services/xdg.scm
+++ b/gnu/home/services/xdg.scm
@@ -133,7 +133,12 @@ (define (ensure-xdg-base-dirs-on-activation config)
(configuration-field-name field) 'upper))))
;; XDG_RUNTIME_DIR shouldn't be created during activation
;; and will be provided by elogind or other service.
- (and (not (string=? "XDG_RUNTIME_DIR" variable))
+ ;; But if the user changes the value from the default,
+ ;; then we can make XDG_RUNTIME_DIR.
+ (and (or (not (string=? "XDG_RUNTIME_DIR" variable))
+ (not (string=? ((configuration-field-getter field)
+ config)
+ "${XDG_RUNTIME_DIR:-/run/user/$UID}")))
variable)))
home-xdg-base-directories-configuration-fields)))
--
2.38.1
A
A
Andrew Tropin wrote on 13 Dec 2022 05:25
87cz8o9bgz.fsf@trop.in
On 2022-12-12 03:00, Antero Mejr via Guix-patches via wrote:

Toggle quote (43 lines)
> * gnu/home.scm (home-environment)[base-xdg-configuration]: New field.
> * gnu/home/services/xdg.scm (ensure-xdg-base-dirs-on-activation): Make
> XDG_RUNTIME_DIR directory if the configuration changes it from the default.
> ---
> Allows making a runtime dir at ~/.local/runtime (or any other dir),
> so users don't have to set up elogind or other greeters/PAM modules.
>
> gnu/home.scm | 9 +++++++--
> gnu/home/services/xdg.scm | 7 ++++++-
> 2 files changed, 13 insertions(+), 3 deletions(-)
>
> diff --git a/gnu/home.scm b/gnu/home.scm
> index c95d1e0818..f100b575e3 100644
> --- a/gnu/home.scm
> +++ b/gnu/home.scm
> @@ -39,6 +39,7 @@ (define-module (gnu home)
> home-environment-essential-services
> home-environment-services
> home-environment-location
> + home-environment-base-xdg-configuration
>
> home-environment-with-provenance
>
> @@ -71,7 +72,10 @@ (define-record-type* <home-environment> home-environment
> (location home-environment-location ; <location>
> (default (and=> (current-source-location)
> source-properties->location))
> - (innate)))
> + (innate))
> +
> + (base-xdg-configuration home-environment-base-xdg-configuration
> + (default (home-xdg-base-directories-configuration))))
>
> (define (home-environment-default-essential-services he)
> "Return the list of essential services for home environment."
> @@ -83,7 +87,8 @@ (define (home-environment-default-essential-services he)
> (service home-symlink-manager-service-type)
>
> (service home-fontconfig-service-type)
> - (service home-xdg-base-directories-service-type)
> + (service home-xdg-base-directories-service-type
> + (home-environment-base-xdg-configuration he))

This change is not needed, you can set xdg dirs by extending
home-xdg-base-directories-service-type with adjusted
home-xdg-base-directories-configuration.

Toggle quote (21 lines)
> (service home-shell-profile-service-type)
>
> (service home-service-type)
> diff --git a/gnu/home/services/xdg.scm b/gnu/home/services/xdg.scm
> index 865f8b81d7..b62580461e 100644
> --- a/gnu/home/services/xdg.scm
> +++ b/gnu/home/services/xdg.scm
> @@ -133,7 +133,12 @@ (define (ensure-xdg-base-dirs-on-activation config)
> (configuration-field-name field) 'upper))))
> ;; XDG_RUNTIME_DIR shouldn't be created during activation
> ;; and will be provided by elogind or other service.
> - (and (not (string=? "XDG_RUNTIME_DIR" variable))
> + ;; But if the user changes the value from the default,
> + ;; then we can make XDG_RUNTIME_DIR.
> + (and (or (not (string=? "XDG_RUNTIME_DIR" variable))
> + (not (string=? ((configuration-field-getter field)
> + config)
> + "${XDG_RUNTIME_DIR:-/run/user/$UID}")))
> variable)))
> home-xdg-base-directories-configuration-fields)))

There is no way to understand upfront if directory containing
XDG_RUNTIME_DIR is writable and this is why it's a good idea to delegate
initialization of it to external thing and never try to create it here,
even if it has non-default value.

But in case you are sure it's writable and want to ensure the directory
created, just be this thing managing and providing XDG_RUNTIME_DIR and
extend activation script with the following G-expression:

#~(mkdir-p (getenv "XDG_RUNTIME_DIR"))

The full snippet:

Toggle snippet (6 lines)
(simple-service
'ensure-xdg-runtime-dir-exists
home-activation-service-type
#~(mkdir-p (getenv "XDG_RUNTIME_DIR")))

--
Best regards,
Andrew Tropin
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCgAdFiEEKEGaxlA4dEDH6S/6IgjSCVjB3rAFAmOX/qwACgkQIgjSCVjB
3rD81hAAkSvQI5SzFQT9K2+R7cnwgOYC6dNwbLgwpj6iaH2mTOalp4wXTMdyz7e+
5z0qC07nIcKHdLYtqjnSRU3d9sRhXTAoxvBx62OWNx2EPes0lDK2h+OLBPTF5qoF
wrH9JfryfmflT37dGf5A5dKr9yBumJapcQbmEWPQoy6/72gqbei1XHcneIpjz3uc
WzHadbW7nSGi8BOQIIyIoztK9ZLEiaAjnr4V83wyo/q8/TVgrR4D8KU9aF2oIURI
Y5T//8eyXV6cfHLM3U3J6KWx4m6NC+0SOsP/y9Xjg8WjugdjGVW22BHBGeB/Fz+H
x9qkQdZTTw/g9MqYK2iTA/QcxArsOf+y8D4mVFe/d7tLRDCf4lu5YGcAwY0IwGtb
Ei77a3vPzTQzkr69Ve4RvfqFSdjxDmj+KMSgvWAaX7zp9c8Iw4vz+xxIMBBIrXHb
Kt+5vGaZK9PI2u10t8mu9jx+DItuy1t2nXSe6lf0JlEnIktKb2FvkNwHrqQbpZgh
vBNYXY7uGtmij+Vg3oRMi5EuujQHkjtqYZPg8InPR97MscMDH1lPPJSgS/RaINS8
PQdTjFbGKP8CbCPqwidrXtLFEmi71t1jnv5a2dbZKUmNhyQW1ARMe8KvDmGVFCaY
4tyQhyOMqUnO4Lh5sLjOGuCLZ8xmnQUX/nHHfYCfLW9xWgtcpYY=
=wELh
-----END PGP SIGNATURE-----

A
A
Antero Mejr wrote on 13 Dec 2022 16:53
(name . Andrew Tropin)(address . andrew@trop.in)
87y1rbthce.fsf@mailbox.org
Andrew Tropin <andrew@trop.in> writes:
Toggle quote (5 lines)
> There is no way to understand upfront if directory containing
> XDG_RUNTIME_DIR is writable and this is why it's a good idea to delegate
> initialization of it to external thing and never try to create it here,
> even if it has non-default value.

Thank you for the snippet, that's a much better way of fixing my issue.

I still think guix home should (by default) be able to use all its
features without the requirement of having external programs installed.

For example, suppose you have a server that you want to set up your home
environment on, for when you login to do sysadmin tasks. That server
wouldn't have %desktop-services (elogind), nor would it have a custom
greeter like greetd. So XDG_RUNTIME_DIR will be unset.

If XDG_RUNTIME_DIR does not exist, can we make a fallback path to have
guix home put the shepherd socket and on-first-login-executed flag file
in ~/.local/var/run (or somewhere else writable) instead?
A
A
Andrew Tropin wrote on 7 Aug 2023 08:57
(name . Antero Mejr)(address . antero@mailbox.org)
87350vl4pq.fsf@trop.in
On 2022-12-13 15:53, Antero Mejr wrote:

Toggle quote (20 lines)
> Andrew Tropin <andrew@trop.in> writes:
>> There is no way to understand upfront if directory containing
>> XDG_RUNTIME_DIR is writable and this is why it's a good idea to delegate
>> initialization of it to external thing and never try to create it here,
>> even if it has non-default value.
>
> Thank you for the snippet, that's a much better way of fixing my issue.
>
> I still think guix home should (by default) be able to use all its
> features without the requirement of having external programs installed.
>
> For example, suppose you have a server that you want to set up your home
> environment on, for when you login to do sysadmin tasks. That server
> wouldn't have %desktop-services (elogind), nor would it have a custom
> greeter like greetd. So XDG_RUNTIME_DIR will be unset.
>
> If XDG_RUNTIME_DIR does not exist, can we make a fallback path to have
> guix home put the shepherd socket and on-first-login-executed flag file
> in ~/.local/var/run (or somewhere else writable) instead?

Without automatic cleanup (which is the case for elogind, pam_rundir and
other options providing XDG_RUNTIME_DIR) it will likely missbehave.

It's much trickier than it seems on the first sight. Theoretically it's
possible, but requires a lot of additional work to do it right.

In fact on-first-login script is a kinda hack to make shepherd started
somehow, but running user's shepherd is tricky on its own. Shutting it
down correctly (and all the processes managed by it) is even more
challenging. AFAIK, there is no easy and straightforward solution (even
in other init systems that we can quickly borrow), so it will require
time and effort to carefully design and implement it.

If you want to work on it - send you ideas, research and patches for the
possible solutions, I'll share my input :)

--
Best regards,
Andrew Tropin
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCgAdFiEEKEGaxlA4dEDH6S/6IgjSCVjB3rAFAmTQleEACgkQIgjSCVjB
3rDqyA/+Ifuvgo/hUJbOO/h3HV9DocSM4vg7VWybqB4wpv7/CeJ0VFg+55rxwTwH
Zyd9s+uo5++C5t2ausObDGG69PuFUY0Pksnb9kWIntw2R045O85LbbXEW1lYBQuV
u0yE/u80RhgJcx2cg9pfY8+rrPd+47Jkag4gWcb8ccgARLTnTbu+2/4w3DuzkM65
hynWQKr0zku2o5e33I7+Zks96KJDApMpP54Vhunl8W9wtRJfsiLUygmzFuEA2IGG
TMrNXBRJdAhyZpeBEpFcrtc3Qa8+1OHSg/UmGd9OmCfLYneA4IuN51qaDmZ4LjLU
sWiQdjW4BXQhhWg44wz+NwDNFBMK7jBHZ+/42Yh1ArQWJ61av3XnhjvBVyVrQPFw
vAZFfNAUgLBLSKHWs9fXF05NuIJLf3cWl+DS/3g7Aq8N29sH/1OeEw/F9PIvuDoX
XaqostVLGlAiTnyMkpUeHnzQsRYTZg7+fA8Qhtj2Jva6/fTvWvckXcJhjCd+RLck
dZrcIgkU3kqBxioCKwwNNJ70VAffPqH8iDDMwptGIjDrJnI+sQz/gH0mCqx6Zepj
urG9kvZRnw3+KiSe2QnhEaWP8zGyfiaqTV43xL3MkxVZmwFywrkurM9QEMQKg3oC
FEoRU7OHn5kKXhULZOz1a2alWOZnGPLr/mnb0vXOf29gnQcxtEI=
=gdmK
-----END PGP SIGNATURE-----

?