[PATCH] system: images: wsl2: Create $XDG_RUNTIME_DIR on first login.

  • Done
  • quality assurance status badge
Details
5 participants
  • dan
  • Ludovic Courtès
  • Tobias Geerinckx-Rice
  • Mathieu Othacehe
  • (
Owner
unassigned
Submitted by
dan
Severity
normal
D
(address . guix-patches@gnu.org)
20221108200553.15545-1-i@dan.games
* gnu/system/images/wsl2.scm (wsl-boot-program): Create $XDG_RUNTIME_DIR on
first login.

copyright info
---
gnu/system/images/wsl2.scm | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)

Toggle diff (41 lines)
diff --git a/gnu/system/images/wsl2.scm b/gnu/system/images/wsl2.scm
index 80c2e775b4..e3e7503da3 100644
--- a/gnu/system/images/wsl2.scm
+++ b/gnu/system/images/wsl2.scm
@@ -1,6 +1,7 @@
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2022 Alex Griffin <a@ajgrf.com>
;;; Copyright © 2022 Mathieu Othacehe <othacehe@gnu.org>
+;;; Copyright © 2022 dan <i@dan.games>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -75,7 +76,11 @@ (define (wsl-boot-program user)
(let* ((pw (getpw #$user))
(shell (passwd:shell pw))
(sudo #+(file-append sudo "/bin/sudo"))
- (args (cdr (command-line))))
+ (args (cdr (command-line)))
+ (uid (passwd:uid pw))
+ (gid (passwd:gid pw))
+ (runtime-dir (string-append "/run/user/"
+ (number->string uid))))
;; Save the value of $PATH set by WSL. Useful for finding
;; Windows binaries to run with WSL's binfmt interop.
(setenv "WSLPATH" (getenv "PATH"))
@@ -88,6 +93,11 @@ (define (wsl-boot-program user)
MS_REMOUNT
#:update-mtab? #f)
+ ;; create XDG_RUNTIME_DIR for the login user
+ (unless (file-exists? runtime-dir)
+ (mkdir runtime-dir)
+ (chown runtime-dir uid gid))
+
;; Start login shell as user.
(apply execl sudo "sudo"
"--preserve-env=WSLPATH"

base-commit: 96ae718c516a289124a0b91ceeef78b20d187825
--
2.38.0
(
CO76S4UZHC7A.1RE7FL2ZZCXHP@guix-framework
On Tue Nov 8, 2022 at 8:05 PM GMT, dan wrote:
Toggle quote (19 lines)
> * gnu/system/images/wsl2.scm (wsl-boot-program): Create $XDG_RUNTIME_DIR on
> first login.
>
> copyright info

> --- a/gnu/system/images/wsl2.scm
> +++ b/gnu/system/images/wsl2.scm

> @@ -88,6 +93,11 @@ (define (wsl-boot-program user)
> MS_REMOUNT
> #:update-mtab? #f)
>

> + ;; create XDG_RUNTIME_DIR for the login user
> + (unless (file-exists? runtime-dir)
> + (mkdir runtime-dir)
> + (chown runtime-dir uid gid))
> +

Shouldn't this be handled by elogind/seatd?

Toggle quote (4 lines)
> ;; Start login shell as user.
> (apply execl sudo "sudo"
> "--preserve-env=WSLPATH"

-- (
D
c5634e2f-3739-4d4a-b9e5-a04ef7f5ee12@app.fastmail.com
On Tue, Nov 8, 2022, at 14:11, ( wrote:
Toggle quote (8 lines)
>> + ;; create XDG_RUNTIME_DIR for the login user
>> + (unless (file-exists? runtime-dir)
>> + (mkdir runtime-dir)
>> + (chown runtime-dir uid gid))
>> +
>
> Shouldn't this be handled by elogind/seatd?

I'm not familiar with the job of elogind/seatd. I might take a look. Other than that, I'm also not sure if these work on WSL2.

--
dan
(
CO773WJBB1O3.1VGM0YVMCG3OO@guix-framework
Heya,

On Tue Nov 8, 2022 at 8:23 PM GMT, dan wrote:
Toggle quote (2 lines)
> I'm not familiar with the job of elogind/seatd. I might take a look. Other than that, I'm also not sure if these work on WSL2.

elogind/seatd are tasked with setting up login sessions, which includes creating
XDG_RUNTIME_DIR. They probably do work on WSL, since I'm pretty sure desktops do?

-- (
(
CO7747KE750U.1H6WBTP2ZPZQQ@guix-framework
To be clear, s/desktops/desktop environments/.

-- (
D
031d4167-c217-06f7-2ea2-801781ab41c6@dan.games
On 11/9/2022 4:27 AM, ( wrote:
Toggle quote (3 lines)
> elogind/seatd are tasked with setting up login sessions, which includes creating
> XDG_RUNTIME_DIR. They probably do work on WSL, since I'm pretty sure desktops do?

i tried the following things:

adding `(syslog-service)' and `(service elogind-service-type)' to the
operating-system's service list. and when i login to wsl, it shows the
following error:

> sudo: pam_open_session: Error in service module
> sudo: policy plugin failed session initialization

also tried seatd, by adding `(udev-service)' and `(service
seatd-service-type)' to the service list. and when logging in, it shows:

> warning: 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 appropriate value and manually
execute the script by running '$HOME/.guix-home/on-first-login'

normally, when logging into wsl, users don't need to type their
password. i'm not sure if it related to the issue, but it might perform
differently with a normal linux distro.

--
dan
D
397fac84-206d-198d-e838-6f5d6f723998@dan.games
On 11/9/2022 4:27 AM, ( wrote:
Toggle quote (3 lines)
> elogind/seatd are tasked with setting up login sessions, which includes creating
> XDG_RUNTIME_DIR. They probably do work on WSL, since I'm pretty sure desktops do?

I searched on the internet and found the manual from Void Linux[1],
saying that seatd is not creating XDG_RUNTIME_DIR for login users.

[1]:

--
dan
T
T
Tobias Geerinckx-Rice wrote on 9 Nov 2022 13:26
(name . dan)(address . i@dan.games)(address . 59132@debbugs.gnu.org)
4f5c715e9dd8aef023d85615125b9fa9@tobias.gr
Hi dan,

Thanks! Why is this needed?

On 2022-11-08 21:05, dan wrote:
Toggle quote (2 lines)
> * gnu/system/images/wsl2.scm (wsl-boot-program): Create
> $XDG_RUNTIME_DIR
^^^^^^^^^^^^^^^^
There's no reference to this in the actual patch.

Kind regards,

T G-R

Sent from a Web browser. Excuse or enjoy my brevity.
D
(name . Tobias Geerinckx-Rice)(address . me@tobias.gr)(address . 59132@debbugs.gnu.org)
96da2673-8ad4-cd7f-cf3a-ce0cef3ca313@dan.games
Hi Tobias,

On 11/9/2022 8:26 PM, Tobias Geerinckx-Rice wrote:
Toggle quote (6 lines)
> Thanks!  Why is this needed?
>
> On 2022-11-08 21:05, dan wrote:
>> * gnu/system/images/wsl2.scm (wsl-boot-program): Create $XDG_RUNTIME_DIR
> ^^^^^^^^^^^^^^^^
> There's no reference to this in the actual patch.
In my understanding, user level shepherd services need XDG_RUNTIME_DIR
to run, and shepherd create a socket under XDG_RUNTIME_DIR/shepherd/.
I'm not sure how WSL handle user login, but what we usually do is just
type `wsl' in powershell, and it automatically logged into the default
account, without prompting for password input. Thus, relying ot elogind
or greetd doesn't really help, it's better for us to manually create the
directory.

There is also a warning on login, and I think it's from shepherd:
Toggle quote (4 lines)
> warning: 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 appropriate value and manually
> execute the script by running '$HOME/.guix-home/on-first-login
Anyway... I wasn't fully sure about if it's the right thing to do, since
I'm not familiar enough with both Linux and WSL. But at least this makes
user level services usable. If this is the right thing to do, I'll
update the patch with explanation included in the commit message.

Would like to hear feedback from someone authoritative!

--
dan
L
L
Ludovic Courtès wrote on 18 Nov 2022 15:00
Re: bug#59132: [PATCH] system: images: wsl2: Create $XDG_RUNTIME_DIR on first login.
87k03sbbvy.fsf_-_@gnu.org
Hi Mathieu,

Could you comment on this patch dan submitted?


Thanks in advance. :-)

Ludo’.

dan <i@dan.games> skribis:

Toggle quote (28 lines)
> Hi Tobias,
>
> On 11/9/2022 8:26 PM, Tobias Geerinckx-Rice wrote:
>> Thanks!  Why is this needed?
>> On 2022-11-08 21:05, dan wrote:
>>> * gnu/system/images/wsl2.scm (wsl-boot-program): Create $XDG_RUNTIME_DIR
>> ^^^^^^^^^^^^^^^^
>> There's no reference to this in the actual patch.
> In my understanding, user level shepherd services need XDG_RUNTIME_DIR
> to run, and shepherd create a socket under
> XDG_RUNTIME_DIR/shepherd/. I'm not sure how WSL handle user login, but
> what we usually do is just type `wsl' in powershell, and it
> automatically logged into the default account, without prompting for
> password input. Thus, relying ot elogind or greetd doesn't really
> help, it's better for us to manually create the directory.
>
> There is also a warning on login, and I think it's from shepherd:
>> warning: 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 appropriate value and manually
>> execute the script by running '$HOME/.guix-home/on-first-login
> Anyway... I wasn't fully sure about if it's the right thing to do,
> since I'm not familiar enough with both Linux and WSL. But at least
> this makes user level services usable. If this is the right thing to
> do, I'll update the patch with explanation included in the commit
> message.
>
> Would like to hear feedback from someone authoritative!
M
M
Mathieu Othacehe wrote on 26 Dec 2022 09:36
(name . dan)(address . i@dan.games)(address . 59132-done@debbugs.gnu.org)
87v8lypnnp.fsf@gnu.org
Hello,

Toggle quote (3 lines)
> * gnu/system/images/wsl2.scm (wsl-boot-program): Create $XDG_RUNTIME_DIR on
> first login.

I did set the XDG_RUNTIME_DIR variable as well, and applied as
c50cd1bbece27097456242f246f89c053e7cc1a2.

Thanks,

Mathieu
Closed
?