Subject: bug#50945: Guix home: No such file or directory: "/run/user/1003/on-first-login-executed"

From: Ludovic Courtès <[email-masked]>
Date: Sun, 14 Nov 2021 23:11:09 +0100

Hi Andrew and all,

Andrew Tropin <[email-masked]> skribis:

> On 2021-11-05 17:58, Xinglu Chen wrote:
> From 8b924b02ab917632047d6653f19d9b16175989bf Mon Sep 17 00:00:00 2001
> From: Andrew Tropin <[email-masked]>
> Date: Thu, 7 Oct 2021 08:12:04 +0300
> Subject: [PATCH] home-services: on-first-login: Check if XDG_RUNTIME_DIR
>  exists.
>
> * gnu/home-services.scm (on-first-login): on-first-login won't execute
> anything if XDG_RUNTIME_DIR doesn't exists.

Applied, with a “Fixes” line in the commit log.  However…

> +++ b/gnu/home/services.scm
> @@ -286,8 +286,13 @@ (define (compute-on-first-login-script _ gexps)
>         ;; XDG_RUNTIME_DIR dissapears on logout, that means such trick
>         ;; allows to launch on-first-login script on first login only
>         ;; after complete logout/reboot.
> -       (when (not (file-exists? flag-file-path))
> -         (begin #$@gexps (touch flag-file-path))))))
> +       (if (file-exists? xdg-runtime-dir)
> +           (unless (file-exists? flag-file-path)
> +             (begin #$@gexps (touch flag-file-path)))
> +           (display "XDG_RUNTIME_DIR doesn't exists, on-first-login script
> +won't execute anything.  You can check if xdg runtime directory exists,
> +XDG_RUNTIME_DIR variable is set to apropriate value and manually execute the
> +script by running '$HOME/.guix-home/on-first-login'")))))

This pattern is problematic because this text is not internationalized
(not subject to translation).  Part of caring about users in Guix
implies ensuring that all messages are internationalized.

The fact that the text is embedded in a generated script makes it a
little trickier.  In the installer, we address that by using the message
catalog of the ‘guix’ package like so:

    #~(begin
        (bindtextdomain "guix" (string-append #$guix "/share/locale"))
        (textdomain "guix")
        (setlocale LC_ALL ""))

The downside is that the script ends up depending on the ‘guix’ package;
we could optimize that later on.

At any rate, for these cases where you cannot avoid having messages
printed by generated scripts such as this one, the solution would be to:

  1. Add calls to ‘bindtextdomain’ and ‘textdomain’ as above
     (‘setlocale’ no longer needs to be called explicitly).

  2. Import (guix i18n) and wrap messages in ‘G_’ (or ‘N_’) calls.

  3. Ensure that each file that uses ‘G_’ or ‘N_’ is listed in
     po/guix/POTFILES.in.

Could one of you take a look?  :-)

> Also, added a note about elogind/XDG_RUNTIME_DIR to manual.
>
> From f5d35fd4f542a11226c0159ee32498e374ff40a2 Mon Sep 17 00:00:00 2001
> From: Andrew Tropin <[email-masked]>
> Date: Mon, 8 Nov 2021 12:22:04 +0300
> Subject: [PATCH] doc: Add a note about elogind and XDG_RUNTIME_DIR for Guix
>  Home.
>
> * doc/guix.texi (Declaring the Home Environment): Add a note about elogind and
> XDG_RUNTIME_DIR.

I tweaked the wording and applied.  Thank you!

Ludo’.