On 2021-11-05 17:58, Xinglu Chen wrote: > Hi, > > On Thu, Oct 07 2021, Andrew Tropin wrote: > >> On 2021-10-01 17:46, Jan Nieuwenhuizen wrote: >> >>> Hi, >>> >>> When using su or sudo to enter an account managed by guix home, I get >>> this error >>> >>> --8<---------------cut here---------------start------------->8--- >>> Backtrace: >>> 2 (primitive-load "/home/guix/.guix-home/on-first-login") >>> In ice-9/ports.scm: >>> 461:11 1 (call-with-output-file "/run/user/1003/on-first-login-…" …) >>> In unknown file: >>> 0 (open-file "/run/user/1003/on-first-login-executed" "w" …) >>> >>> ERROR: In procedure open-file: >>> In procedure open-file: No such file or directory: "/run/user/1003/on-first-login-executed" >>> --8<---------------cut here---------------end--------------->8--- >>> >>> [...] >> >> Thank you for a very detailed report. >> >> pam_elogind doesn't create a session, when the login shell spawned by >> sudo or su => XDG_RUNTIME_DIR not get created => this message appears. >> >> I think we can omit execution of any processes by on-first-login script >> in case session wasn't created. Added the check: >> >> From aab6df0298963fe91a6ebfd1dadbc1530eceeff7 Mon Sep 17 00:00:00 2001 >> From: Andrew Tropin >> 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. >> --- >> gnu/home-services.scm | 7 +++++-- >> 1 file changed, 5 insertions(+), 2 deletions(-) >> >> diff --git a/gnu/home-services.scm b/gnu/home-services.scm >> index 9f1e986616..0b77a1321d 100644 >> --- a/gnu/home-services.scm >> +++ b/gnu/home-services.scm >> @@ -286,8 +286,11 @@ will be put in @file{~/.guix-home/files}."))) >> ;; 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) >> + (when (not (file-exists? flag-file-path)) > > Use (unless …) instead of (when (not …)…). > >> + (begin #$@gexps (touch flag-file-path))) >> + (display "XDG_RUNTIME_DIR doesn't exists, the session wasn't >> +created, on-first-login script won't execute anything."))))) > > It would be good to tell the user how they could manually run the > script, that way they could manually set/create $XDG_RUNTIME_DIR and run > the script. > > "XDG_RUNTIME_DIR doesn't exist; the 'on-first-login' script won't > execute anything. You can manually execute the script by running > '$HOME/.guix-home/on-first-login' > > WDYT? Addressed suggestions, attaching updated patch.