Subject: [bug#78308] [PATCH v3 10/10] news: Add news entry for etc-bashrc-d-service-type.

From: Sergey Trofimov <[email-masked]>
Date: Tue, 20 May 2025 13:21:33 +0200

Hi Maxim,

a follow-up to my previous reply containing my proposal materialised to
a patch.

>From c674d1fdf83bb1bc7930b48f9c0333f2936563d2 Mon Sep 17 00:00:00 2001
Message-ID: <[email-masked]>
From: Sergey Trofimov <[email-masked]>
Date: Tue, 20 May 2025 13:18:29 +0200
Subject: [PATCH] source profile.d as intended

Change-Id: I37c0980ca66b2bfb8516df26d3376b16a009f855
---
 gnu/system.scm               | 10 +---------
 guix/build/profiles.scm      | 25 +++++++++++++++++++++++--
 guix/profiles.scm            |  4 +++-
 guix/scripts/environment.scm |  4 ++--
 4 files changed, 29 insertions(+), 14 deletions(-)

diff --git a/gnu/system.scm b/gnu/system.scm
index 2beca4b6d0..0969228f0a 100644
--- a/gnu/system.scm
+++ b/gnu/system.scm
@@ -1134,15 +1134,7 @@ (define* (operating-system-etc-service os)
 
 # Provide a default prompt.  The user's ~/.bashrc can override it.
 PS1='\\u@\\h \\w${GUIX_ENVIRONMENT:+ [env]}\\$ '
-
-# The 'bash-completion' package.
-if [ -f /run/current-system/profile/etc/profile.d/bash_completion.sh ]
-then
-  # Bash-completion sources ~/.bash_completion.  It installs a dynamic
-  # completion loader that searches its own completion files as well
-  # as those in ~/.guix-profile and /run/current-system/profile.
-  source /run/current-system/profile/etc/profile.d/bash_completion.sh
-fi\n")))
+")))
     (service etc-service-type
      `(("os-release" ,os-release)
        ("services" ,(file-append net-base "/etc/services"))
diff --git a/guix/build/profiles.scm b/guix/build/profiles.scm
index b19d93f971..a4854386fb 100644
--- a/guix/build/profiles.scm
+++ b/guix/build/profiles.scm
@@ -98,9 +98,30 @@ (define (build-etc/profile output search-paths)
 # to this specific profile generation.
 \n" port)
       (let ((variables (evaluate-search-paths search-paths
-                                              (list output))))
+                                              (list output)))
+            (profile-d (string-append output "/etc/profile.d"))
+            (guard-flag (string-append "GUIX_PROFILE_"
+                                       (string-take (basename output) 32)
+                                       "_LOADED")))
+
+        (format port "if [ \"x$~a\" = x ]; then\n" guard-flag)
         (for-each (write-environment-variable-definition port)
-                  (map (abstract-profile output) variables))))))
+                  (map (abstract-profile output) variables))
+
+        (format port "
+~a=1
+fi
+
+for i in ~a/*.sh; do
+    if [ -r \"$i\" ]; then
+        if [ \"${-#*i}\" != \"$-\" ]; then
+            . \"$i\"
+        else
+            . \"$i\" >/dev/null
+        fi
+    fi
+done"
+                guard-flag profile-d)))))
 
 (define* (ensure-writable-directory directory
                                     #:key (symlink symlink))
diff --git a/guix/profiles.scm b/guix/profiles.scm
index 264396401e..68ad6a6bc5 100644
--- a/guix/profiles.scm
+++ b/guix/profiles.scm
@@ -2165,7 +2165,9 @@ (define* (load-profile profile
                                  (string-append value separator current)
                                  value)
                              value)))))
-            (profile-search-paths profile manifest)))
+            (profile-search-paths profile manifest))
+  (setenv (string-append "GUIX_PROFILE_" (string-take (basename profile) 32)
+                         "_LOADED") "1"))
 
 (define (profile-regexp profile)
   "Return a regular expression that matches PROFILE's name and number."
diff --git a/guix/scripts/environment.scm b/guix/scripts/environment.scm
index 96bbc6c9fa..839ad7ce97 100644
--- a/guix/scripts/environment.scm
+++ b/guix/scripts/environment.scm
@@ -1123,8 +1123,8 @@ (define (guix-environment* opts)
                        (if container?
                            ;; The user's shell is likely not available
                            ;; within the container.
-                           '("/bin/sh")
-                           (list %default-shell))))
+                           '("/bin/sh" "--login")
+                           (list %default-shell "--login"))))
          (mappings   (pick-all opts 'file-system-mapping))
          (white-list (pick-all opts 'inherit-regexp)))

base-commit: e7d73a08d569904f8a71db5b84f5fafaf0dff188
-- 
2.49.0