[PATCH 0/9] Improve profile initialization on foreign distros plus misc improvements

  • Open
  • quality assurance status badge
Details
One participant
  • Liam Hupfer
Owner
unassigned
Submitted by
Liam Hupfer
Severity
normal
L
L
Liam Hupfer wrote 5 days ago
(address . guix-patches@gnu.org)(name . Liam Hupfer)(address . liam@hpfr.net)
cover.1738814583.git.liam@hpfr.net
Hi Guix! Hope those who attended enjoyed Guix Days and FOSDEM. Looks
like the Whippet talk is the first recording from the DMC track to go
up!

This series modifies the /etc/profile.d/zzz-guix.sh deployed by
guix-install.sh (and tweaks Guix Home’s setup-environment script) to
make search path initialization a little more consistent based on my
experiences using Guix on NixOS and Ubuntu. Currently, new users tend to
end up with numerous duplicate search path entries, which can be
confusing when trying to grok profiles and search paths early on.

Ironically, NixOS and Ubuntu both ship “native” Guix packages. I
figured I should start by improving the upstream installation script,
though, since it tends to inspire foreign distros’ Guix package recipes.
While I’m here, I did some general tidying as well.

The most contentious change is the removal of any attempt to initialize
Guix Home from /etc/profile.d/. The rationale here is that Guix Home
has more in common with Guix System than the ‘guix pull’ and default
imperative user profiles. Guix Home can do arbitrary things at profile
initialization. It initializes itself in ~/.profile by default and
documents shell configuration to source ~.profile if the user doesn’t
also manage their shell with Guix Home. Since Guix Home can manage
itself, we can keep it self-contained rather than trying to keep
/etc/profile.d/zzz-guix.sh in lockstep with Guix Home’s dedicated
initialization code.

I tested the updated install script in a Debian container via Incus (LXD
successor) and the updates to Guix Home via ‘./pre-inst-env guix home
container home-test.scm’ with a small home environment. Additional
testing is appreciated, of course!

Along with the Guix Home team, Vagrant is Cc’d since these changes may
inform changes to the Debian package (thank you for developing it,
btw!). I help maintain the NixOS module and plan to update it
accordingly once these changes make it through review.

Thanks!

Liam Hupfer (9):
home: services: setup-environment: Use GUIX_PROFILE.
home: services: Unset variables after profile init.
home: services: setup-environment: Set GUIX_LOCPATH.
guix-install.sh: Remove system-level Guix Home initialization.
guix-install.sh: Improve Guix profile sourcing.
guix-install.sh: Add to MANPATH.
guix-install.sh: Appease shellcheck.
guix-install.sh: Add msg helpers and use stderr consistently.
guix-install.sh: Check for existing installation before downloading.

etc/guix-install.sh | 264 ++++++++++++++++++++---------------
gnu/home/services.scm | 32 +++--
gnu/home/services/shells.scm | 3 +-
3 files changed, 171 insertions(+), 128 deletions(-)


base-commit: 52c05f3b120e641c8bd2d68cfcf0d6af947de27b
--
2.47.1
L
L
Liam Hupfer wrote 5 days ago
[PATCH 1/9] home: services: setup-environment: Use GUIX_PROFILE.
(address . 76082@debbugs.gnu.org)(name . Liam Hupfer)(address . liam@hpfr.net)
2094e26655b1bdd87417b090ddda9761a0458d38.1738815703.git.liam@hpfr.net
setup-environment already defines this variable. Use it since it’s more
concise.

* gnu/home/services.scm (environment-variables->setup-environment-script):
Use GUIX_PROFILE.

Change-Id: Ib75d8df6294976f4e95cfa7d607dc0ba21ddd258
---
gnu/home/services.scm | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)

Toggle diff (48 lines)
diff --git a/gnu/home/services.scm b/gnu/home/services.scm
index 39c9033ad6..bbf2ba2404 100644
--- a/gnu/home/services.scm
+++ b/gnu/home/services.scm
@@ -277,28 +277,28 @@ (define (environment-variables->setup-environment-script vars)
(display "\
HOME_ENVIRONMENT=$HOME/.guix-home
GUIX_PROFILE=\"$HOME_ENVIRONMENT/profile\"
-PROFILE_FILE=\"$HOME_ENVIRONMENT/profile/etc/profile\"
+PROFILE_FILE=\"$GUIX_PROFILE/etc/profile\"
[ -f $PROFILE_FILE ] && . $PROFILE_FILE
case $XDG_DATA_DIRS in
- *$HOME_ENVIRONMENT/profile/share*) ;;
- *) export XDG_DATA_DIRS=$HOME_ENVIRONMENT/profile/share:$XDG_DATA_DIRS ;;
+ *$GUIX_PROFILE/share*) ;;
+ *) export XDG_DATA_DIRS=$GUIX_PROFILE/share:$XDG_DATA_DIRS ;;
esac
case $MANPATH in
- *$HOME_ENVIRONMENT/profile/share/man*) ;;
- *) export MANPATH=$HOME_ENVIRONMENT/profile/share/man:$MANPATH
+ *$GUIX_PROFILE/share/man*) ;;
+ *) export MANPATH=$GUIX_PROFILE/share/man:$MANPATH
esac
case $INFOPATH in
- *$HOME_ENVIRONMENT/profile/share/info*) ;;
- *) export INFOPATH=$HOME_ENVIRONMENT/profile/share/info:$INFOPATH ;;
+ *$GUIX_PROFILE/share/info*) ;;
+ *) export INFOPATH=$GUIX_PROFILE/share/info:$INFOPATH ;;
esac
case $XDG_CONFIG_DIRS in
- *$HOME_ENVIRONMENT/profile/etc/xdg*) ;;
- *) export XDG_CONFIG_DIRS=$HOME_ENVIRONMENT/profile/etc/xdg:$XDG_CONFIG_DIRS ;;
+ *$GUIX_PROFILE/etc/xdg*) ;;
+ *) export XDG_CONFIG_DIRS=$GUIX_PROFILE/etc/xdg:$XDG_CONFIG_DIRS ;;
esac
case $XCURSOR_PATH in
- *$HOME_ENVIRONMENT/profile/share/icons*) ;;
- *) export XCURSOR_PATH=$HOME_ENVIRONMENT/profile/share/icons:$XCURSOR_PATH ;;
+ *$GUIX_PROFILE/share/icons*) ;;
+ *) export XCURSOR_PATH=$GUIX_PROFILE/share/icons:$XCURSOR_PATH ;;
esac
" port)

base-commit: 52c05f3b120e641c8bd2d68cfcf0d6af947de27b
--
2.47.1
L
L
Liam Hupfer wrote 5 days ago
[PATCH 2/9] home: services: Unset variables after profile init.
(address . 76082@debbugs.gnu.org)(name . Liam Hupfer)(address . liam@hpfr.net)
25ffb457020cb7ad0bbc9b9ff62736ed01ff0002.1738815703.git.liam@hpfr.net
While they aren’t exported, these temporary variables show up in the
resulting shell, cluttering tab completion and declare -p.

* gnu/home/services.scm (environment-variables->setup-environment-script):
Unset shell variables.
* gnu/home/services/shells.scm (add-shell-profile-file): Likewise.

Change-Id: Ibb634849d9f38c1a9a44c0d493e92231364de958
---
gnu/home/services.scm | 6 +++++-
gnu/home/services/shells.scm | 3 ++-
2 files changed, 7 insertions(+), 2 deletions(-)

Toggle diff (40 lines)
diff --git a/gnu/home/services.scm b/gnu/home/services.scm
index bbf2ba2404..165bc33b05 100644
--- a/gnu/home/services.scm
+++ b/gnu/home/services.scm
@@ -275,7 +275,8 @@ (define (environment-variables->setup-environment-script vars)
(lambda (port)
(set-port-encoding! port "UTF-8")
(display "\
-HOME_ENVIRONMENT=$HOME/.guix-home
+# NOTE: Set HOME_ENVIRONMENT before sourcing (home-shell-profile-service-type ensures
+# ~/.profile does)
GUIX_PROFILE=\"$HOME_ENVIRONMENT/profile\"
PROFILE_FILE=\"$GUIX_PROFILE/etc/profile\"
[ -f $PROFILE_FILE ] && . $PROFILE_FILE
@@ -301,6 +302,9 @@ (define (environment-variables->setup-environment-script vars)
*) export XCURSOR_PATH=$GUIX_PROFILE/share/icons:$XCURSOR_PATH ;;
esac
+# Keep the shell environment clean.
+unset GUIX_PROFILE PROFILE_FILE
+
" port)
(display
#$(environment-variable-shell-definitions vars)
diff --git a/gnu/home/services/shells.scm b/gnu/home/services/shells.scm
index ee6b09f17c..bab5730c3d 100644
--- a/gnu/home/services/shells.scm
+++ b/gnu/home/services/shells.scm
@@ -89,7 +89,8 @@ (define (add-shell-profile-file config)
"\
HOME_ENVIRONMENT=$HOME/.guix-home
. $HOME_ENVIRONMENT/setup-environment
-$HOME_ENVIRONMENT/on-first-login\n"
+$HOME_ENVIRONMENT/on-first-login
+unset HOME_ENVIRONMENT\n"
(serialize-configuration
config
(filter-configuration-fields
--
2.47.1
L
L
Liam Hupfer wrote 5 days ago
[PATCH 3/9] home: services: setup-environment: Set GUIX_LOCPATH.
(address . 76082@debbugs.gnu.org)(name . Liam Hupfer)(address . liam@hpfr.net)
f3b1a81be5e919c63d329ef6ffd768239bee69b2.1738815703.git.liam@hpfr.net
Locales installed via Guix Home should be exposed to Guix packages by
default.

* gnu/home/services.scm (environment-variables->setup-environment-script):
Set GUIX_LOCPATH.

Change-Id: Ic61f0832312479ba36f471d92a12e7b4e296389f
---
gnu/home/services.scm | 4 ++++
1 file changed, 4 insertions(+)

Toggle diff (17 lines)
diff --git a/gnu/home/services.scm b/gnu/home/services.scm
index 165bc33b05..9f50635d5c 100644
--- a/gnu/home/services.scm
+++ b/gnu/home/services.scm
@@ -281,6 +281,10 @@ (define (environment-variables->setup-environment-script vars)
PROFILE_FILE=\"$GUIX_PROFILE/etc/profile\"
[ -f $PROFILE_FILE ] && . $PROFILE_FILE
+case $GUIX_LOCPATH in
+ *$GUIX_PROFILE/lib/locale*) ;;
+ *) export GUIX_LOCPATH=$GUIX_PROFILE/lib/locale:$GUIX_LOCPATH ;;
+esac
case $XDG_DATA_DIRS in
*$GUIX_PROFILE/share*) ;;
*) export XDG_DATA_DIRS=$GUIX_PROFILE/share:$XDG_DATA_DIRS ;;
--
2.47.1
L
L
Liam Hupfer wrote 5 days ago
[PATCH 4/9] guix-install.sh: Remove system-level Guix Home initialization.
(address . 76082@debbugs.gnu.org)(name . Liam Hupfer)(address . liam@hpfr.net)
e63a2a0b73f6d0147ccb4fe814dd9c6e6ecd14ff.1738815703.git.liam@hpfr.net
Guix Home handles its own profile initialization in ~/.profile and
documents shell setup accordingly. It does more than what is done here,
including running an on-first-login script to start a user Shepherd
instance. In general, changes and improvements to Guix Home
initialization are unlikely to propagate to the foreign distro install
script, since many Guix contributors only use Guix via Guix System and
Guix Home does not depend on system-level initialization anyway.

Avoid partially initializing Guix Home in /etc/profile.d to keep search
path variables free of redundant entries. Instead, leave a comment
directing users to the relevant manual section.

* etc/guix-install.sh (sys_create_init_profile): Remove system-level
Guix Home initialization.

Change-Id: Ib78aa0382268a789298d4980ee394d99a602a5ca
---
etc/guix-install.sh | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)

Toggle diff (19 lines)
diff --git a/etc/guix-install.sh b/etc/guix-install.sh
index 22d54c0c83..8dda149edf 100755
--- a/etc/guix-install.sh
+++ b/etc/guix-install.sh
@@ -665,10 +665,8 @@ GUIX_LOCPATH="$GUIX_PROFILE/lib/locale${GUIX_LOCPATH:+:}$GUIX_LOCPATH"
# searches 'Info-default-directory-list'.
export INFOPATH="$_GUIX_PROFILE/share/info:$GUIX_PROFILE/share/info:$INFOPATH"
-GUIX_PROFILE="$HOME/.guix-home/profile"
-[ -f "$GUIX_PROFILE/etc/profile" ] && . "$GUIX_PROFILE/etc/profile"
-[ -L "$GUIX_PROFILE" ] && \
-GUIX_LOCPATH="$GUIX_PROFILE/lib/locale${GUIX_LOCPATH:+:}$GUIX_LOCPATH"
+# NOTE: Guix Home handles its own profile initialization in ~/.profile. See
+# info '(guix) Configuring the Shell'.
export GUIX_LOCPATH
--
2.47.1
L
L
Liam Hupfer wrote 5 days ago
[PATCH 5/9] guix-install.sh: Improve Guix profile sourcing.
(address . 76082@debbugs.gnu.org)(name . Liam Hupfer)(address . liam@hpfr.net)
1c3233c704528b298ba3fb884bc8ab29b8b84001.1738815703.git.liam@hpfr.net
Make both profiles use GUIX_PROFILE and reorder some code so each
profile is handled in one contiguous block. The user’s profile now
takes precedence over the ‘guix pull’ profile on INFOPATH. If the user
already has an info reader in their Guix profile, don’t add a duplicate
entry to INFOPATH. If the user doesn’t have an imperative
~/.guix-profile (i.e. they manage software with Guix Home and ‘guix
shell’), don’t add an unnecessary entry to INFOPATH. Clean up after
ourselves by unsetting the temporary GUIX_PROFILE variable, which only
needs to be set when sourcing.

* etc/guix-install.sh (sys_create_init_profile): Improve Guix profile
sourcing.

Change-Id: Ibceb354012d23d24deeb39b1ec02790873396a6b
---
etc/guix-install.sh | 50 +++++++++++++++++++++++++++------------------
1 file changed, 30 insertions(+), 20 deletions(-)

Toggle diff (68 lines)
diff --git a/etc/guix-install.sh b/etc/guix-install.sh
index 8dda149edf..9a1d898b4b 100755
--- a/etc/guix-install.sh
+++ b/etc/guix-install.sh
@@ -649,31 +649,41 @@ export XDG_CONFIG_DIRS="${XDG_CONFIG_DIRS:-/etc/xdg}"
export XDG_CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}"
# no default for XDG_RUNTIME_DIR (depends on foreign distro for semantics)
-# _GUIX_PROFILE: `guix pull` profile
-_GUIX_PROFILE="$HOME/.config/guix/current"
-export PATH="$_GUIX_PROFILE/bin${PATH:+:}$PATH"
-
-# GUIX_PROFILE: User's default profile and home profile
+# `guix pull` profile
+GUIX_PROFILE="$HOME/.config/guix/current"
+export PATH="$GUIX_PROFILE/bin${PATH:+:}$PATH"
+# Add to INFOPATH so the latest Guix documentation is available to info
+# readers. When INFOPATH is unset, add a trailing colon so that Emacs searches
+# 'Info-default-directory-list'.
+export INFOPATH="$GUIX_PROFILE/share/info:$INFOPATH"
+# Expose the latest Guix modules to Guile so guix shell and repls spawned by
+# e.g. Geiser work out of the box.
+export GUILE_LOAD_PATH="$GUIX_PROFILE/share/guile/site/3.0${GUILE_LOAD_PATH:+:}$GUILE_LOAD_PATH"
+export GUILE_LOAD_COMPILED_PATH="$GUIX_PROFILE/lib/guile/3.0/site-ccache${GUILE_LOAD_COMPILED_PATH:+:}$GUILE_LOAD_COMPILED_PATH"
+
+# User's default profile, if it exists
GUIX_PROFILE="$HOME/.guix-profile"
-[ -f "$GUIX_PROFILE/etc/profile" ] && . "$GUIX_PROFILE/etc/profile"
-[ -L "$GUIX_PROFILE" ] && \
-GUIX_LOCPATH="$GUIX_PROFILE/lib/locale${GUIX_LOCPATH:+:}$GUIX_LOCPATH"
-
-# Export INFOPATH so that the updated info pages can be found
-# and read by both /usr/bin/info and/or $GUIX_PROFILE/bin/info
-# When INFOPATH is unset, add a trailing colon so that Emacs
-# searches 'Info-default-directory-list'.
-export INFOPATH="$_GUIX_PROFILE/share/info:$GUIX_PROFILE/share/info:$INFOPATH"
+if [ -L "$GUIX_PROFILE" ]; then
+ . "$GUIX_PROFILE/etc/profile"
+
+ # see info '(guix) Application Setup'
+ export GUIX_LOCPATH="$GUIX_PROFILE/lib/locale${GUIX_LOCPATH:+:}$GUIX_LOCPATH"
+
+ # INFOPATH may be handled by $GUIX_PROFILE/etc/profile if the user installs
+ # an info reader via Guix. If the user doesn’t, explicitly add to INFOPATH
+ # so documentation for software from ‘guix install’ is available to the
+ # system info reader.
+ case $INFOPATH in
+ *$GUIX_PROFILE/share/info*) ;;
+ *) export INFOPATH="$GUIX_PROFILE/share/info:$INFOPATH" ;;
+ esac
+fi
# NOTE: Guix Home handles its own profile initialization in ~/.profile. See
# info '(guix) Configuring the Shell'.
-export GUIX_LOCPATH
-
-# Make Guix modules available
-export GUILE_LOAD_PATH="$_GUIX_PROFILE/share/guile/site/3.0${GUILE_LOAD_PATH:+:}$GUILE_LOAD_PATH"
-export GUILE_LOAD_COMPILED_PATH="$_GUIX_PROFILE/lib/guile/3.0/site-ccache${GUILE_LOAD_COMPILED_PATH:+:}$GUILE_LOAD_COMPILED_PATH"
-
+# Clean up after ourselves.
+unset GUIX_PROFILE
EOF
}
--
2.47.1
L
L
Liam Hupfer wrote 5 days ago
[PATCH 6/9] guix-install.sh: Add to MANPATH.
(address . 76082@debbugs.gnu.org)(name . Liam Hupfer)(address . liam@hpfr.net)
ff18c002f88537656d38869ff92a7707fe2ba96c.1738815703.git.liam@hpfr.net
Guix and Guix-provided software also have man pages. If the user
doesn’t install man-db via Guix, they should still be able to read
Guix-provided man pages.

* etc/guix-install.sh (sys_create_init_profile): Add to MANPATH.

Change-Id: Ibceb354012d23d24deeb39b1ec02790873396a6b
---
etc/guix-install.sh | 20 +++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)

Toggle diff (45 lines)
diff --git a/etc/guix-install.sh b/etc/guix-install.sh
index 9a1d898b4b..ef338e89f7 100755
--- a/etc/guix-install.sh
+++ b/etc/guix-install.sh
@@ -652,10 +652,12 @@ export XDG_CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}"
# `guix pull` profile
GUIX_PROFILE="$HOME/.config/guix/current"
export PATH="$GUIX_PROFILE/bin${PATH:+:}$PATH"
-# Add to INFOPATH so the latest Guix documentation is available to info
-# readers. When INFOPATH is unset, add a trailing colon so that Emacs searches
-# 'Info-default-directory-list'.
+# Add to INFOPATH and MANPATH so the latest Guix documentation is available to
+# info and man readers. When INFOPATH is unset, add a trailing colon so Emacs
+# searches 'Info-default-directory-list'. When MANPATH is unset, add a
+# trailing colon so the system default search path is used.
export INFOPATH="$GUIX_PROFILE/share/info:$INFOPATH"
+export MANPATH="$GUIX_PROFILE/share/man:$MANPATH"
# Expose the latest Guix modules to Guile so guix shell and repls spawned by
# e.g. Geiser work out of the box.
export GUILE_LOAD_PATH="$GUIX_PROFILE/share/guile/site/3.0${GUILE_LOAD_PATH:+:}$GUILE_LOAD_PATH"
@@ -669,14 +671,18 @@ if [ -L "$GUIX_PROFILE" ]; then
# see info '(guix) Application Setup'
export GUIX_LOCPATH="$GUIX_PROFILE/lib/locale${GUIX_LOCPATH:+:}$GUIX_LOCPATH"
- # INFOPATH may be handled by $GUIX_PROFILE/etc/profile if the user installs
- # an info reader via Guix. If the user doesn’t, explicitly add to INFOPATH
- # so documentation for software from ‘guix install’ is available to the
- # system info reader.
+ # Documentation search paths may be handled by $GUIX_PROFILE/etc/profile if
+ # the user installs info and man readers via Guix. If the user doesn’t,
+ # explicitly add to them so documentation for software from ‘guix install’
+ # is available to the system info and man readers.
case $INFOPATH in
*$GUIX_PROFILE/share/info*) ;;
*) export INFOPATH="$GUIX_PROFILE/share/info:$INFOPATH" ;;
esac
+ case $MANPATH in
+ *$GUIX_PROFILE/share/man*) ;;
+ *) export MANPATH="$GUIX_PROFILE/share/man:$MANPATH"
+ esac
fi
# NOTE: Guix Home handles its own profile initialization in ~/.profile. See
--
2.47.1
L
L
Liam Hupfer wrote 5 days ago
[PATCH 7/9] guix-install.sh: Appease shellcheck.
(address . 76082@debbugs.gnu.org)(name . Liam Hupfer)(address . liam@hpfr.net)
470303f6526912c2f03a4661c0e4afa8aa538b4e.1738815703.git.liam@hpfr.net
* etc/guix-install.sh: Appease shellcheck.

Change-Id: I24f0d13bb254c08d4fe45f5aa3b74bbc6a9a9d88
---
etc/guix-install.sh | 31 ++++++++++++++++---------------
1 file changed, 16 insertions(+), 15 deletions(-)

Toggle diff (120 lines)
diff --git a/etc/guix-install.sh b/etc/guix-install.sh
index ef338e89f7..340c3a394f 100755
--- a/etc/guix-install.sh
+++ b/etc/guix-install.sh
@@ -51,8 +51,8 @@
# installation required the user to extract Guix packs under /gnu to
# satisfy its dependencies.
-if [ "x$BASH_VERSION" = "x" ]
-then
+# shellcheck disable=2268 # try to support vintage shells
+if [ "x$BASH_VERSION" = "x" ]; then
exec bash "$0" "$@"
fi
@@ -85,6 +85,7 @@ REQUIRE=(
# Add variables using form FOO_INIT_REQUIRE when init system FOO dependencies
# should be checked.
+# shellcheck disable=2034 # interpolated by add_init_sys_require
SYSV_INIT_REQUIRE=(
"daemonize"
)
@@ -159,7 +160,7 @@ chk_require()
add_init_sys_require()
{ # Add the elements of FOO_INIT_SYS to REQUIRE
local init_require="${INIT_SYS}_REQUIRE[@]"
- if [[ ! -z "$init_require" ]]; then
+ if [[ -n "$init_require" ]]; then
# Have to add piecemeal because ${!foo[@]} performs direct array key
# expansion, not indirect plain array expansion.
for r in "${!init_require}"; do
@@ -398,7 +399,9 @@ sys_create_store()
~root/.config/guix/current
GUIX_PROFILE=~root/.config/guix/current
- # shellcheck disable=SC1090
+ # The profile just prepends to search paths, which is not needed for
+ # effective linting.
+ # shellcheck disable=SC1091
source "${GUIX_PROFILE}/etc/profile"
_msg "${PAS}activated root profile at ${GUIX_PROFILE}"
}
@@ -435,12 +438,12 @@ sys_create_build_user()
for i in $(seq -w 1 10); do
if id "guixbuilder${i}" &>/dev/null; then
_msg "${INF}user is already in the system, reset"
- usermod -g guixbuild -G guixbuild${KVMGROUP} \
+ usermod -g guixbuild -G guixbuild"$KVMGROUP" \
-d /var/empty -s "$(which nologin)" \
-c "Guix build user $i" \
"guixbuilder${i}";
else
- useradd -g guixbuild -G guixbuild${KVMGROUP} \
+ useradd -g guixbuild -G guixbuild"$KVMGROUP" \
-d /var/empty -s "$(which nologin)" \
-c "Guix build user $i" --system \
"guixbuilder${i}";
@@ -453,7 +456,7 @@ sys_delete_build_user()
{
for i in $(seq -w 1 10); do
if id -u "guixbuilder${i}" &>/dev/null; then
- userdel -f guixbuilder${i}
+ userdel -f guixbuilder"$i"
fi
done
@@ -559,7 +562,7 @@ sys_delete_guix_daemon()
local local_bin
local var_guix
- _debug "--- [ $FUNCNAME ] ---"
+ _debug "--- [ ${FUNCNAME[0]} ] ---"
info_path="/usr/local/share/info"
local_bin="/usr/local/bin"
@@ -703,7 +706,7 @@ sys_create_shell_completion()
{ # Just in case
for dir_shell in $bash_completion $zsh_completion $fish_completion; do
- [ -d "$dir_shell" ] || mkdir -p $dir_shell
+ [ -d "$dir_shell" ] || mkdir -p "$dir_shell"
done;
# Don't use globing here as we also need to delete the files when
@@ -737,8 +740,10 @@ sys_customize_bashrc()
for bashrc in /home/*/.bashrc /root/.bashrc; do
test -f "$bashrc" || continue
+ # shellcheck disable=SC2016 # intended search for variable reference
grep -Fq '$GUIX_ENVIRONMENT' "$bashrc" && continue
cp "${bashrc}" "${bashrc}.bak"
+ # shellcheck disable=SC2016,SC2028 # intended literal shell output
echo '
# Automatically added by the Guix install script.
if [ -n "$GUIX_ENVIRONMENT" ]; then
@@ -788,11 +793,7 @@ sys_delete_user_profiles()
rm -rf ~root/.cache/guix
_msg "${INF}removing .guix-profile, .cache/guix and .config/guix of all /home users"
- for user in `ls -1 /home`; do
- rm -f /home/$user/.guix-profile
- rm -rf /home/$user/.cache/guix
- rm -rf /home/$user/.config/guix
- done
+ rm -rf /home/*/{.guix-profile,{.cache,.config}/guix}
}
welcome()
@@ -940,7 +941,7 @@ main()
if [ '--uninstall' = "${uninstall_flag}" ]; then
main_uninstall
else
- echo "unsupported parameters: $@"
+ echo "unsupported parameters: $*"
exit 1
fi
fi
--
2.47.1
L
L
Liam Hupfer wrote 5 days ago
[PATCH 8/9] guix-install.sh: Add msg helpers and use stderr consistently.
(address . 76082@debbugs.gnu.org)(name . Liam Hupfer)(address . liam@hpfr.net)
15ab3b91f03b6d46fc1014b073576a4006da3de3.1738815703.git.liam@hpfr.net
Add helpers to avoid repeated manual concatenation.

_err and _msg "$ERR are used interchangeably with their only difference
being output stream; convert all errors to use _err.

* etc/guix-install.sh: Add msg helpers and consolidate errors to stderr.

Change-Id: I06e97ccc50d108ed9e279ae80c6b2386d7b8c36b
---
etc/guix-install.sh | 149 ++++++++++++++++++++++++--------------------
1 file changed, 82 insertions(+), 67 deletions(-)

Toggle diff (470 lines)
diff --git a/etc/guix-install.sh b/etc/guix-install.sh
index 340c3a394f..7a731962b3 100755
--- a/etc/guix-install.sh
+++ b/etc/guix-install.sh
@@ -110,7 +110,7 @@ GPG_SIGNING_KEYS[127547]=27D586A4F8900854329FF09F1260E46482E63562 # maxim
_err()
{ # All errors go to stderr.
- printf "[%s]: %s\n" "$(date +%s.%3N)" "$1"
+ printf "[%s]: ${ERR}%s\n" "$(date +%s.%3N)" "$1"
}
_msg()
@@ -118,6 +118,21 @@ _msg()
printf "[%s]: %s\n" "$(date +%s.%3N)" "$1"
}
+_msg_pass()
+{
+ _msg "$PAS$1"
+}
+
+_msg_warn()
+{
+ _msg "$WAR$1"
+}
+
+_msg_info()
+{
+ _msg "$INF$1"
+}
+
_debug()
{
if [ "${DEBUG}" = '1' ]; then
@@ -127,7 +142,7 @@ _debug()
die()
{
- _err "${ERR}$*"
+ _err "$*"
exit 1
}
@@ -154,7 +169,7 @@ chk_require()
[ "${#warn}" -ne 0 ] && die "Missing commands: ${warn[*]}."
- _msg "${PAS}verification of required commands completed"
+ _msg_pass "verification of required commands completed"
}
add_init_sys_require()
@@ -195,7 +210,7 @@ Would you like me to fetch it for you?"; then
fi
# If we reach this point, the key is (still) missing. Report further
# missing keys, if any, but then abort the installation.
- _err "${ERR}Missing OpenPGP public key ($gpg_key_id).
+ _err "Missing OpenPGP public key ($gpg_key_id).
Fetch it with this command:
wget \"https://sv.gnu.org/people/viewgpg.php?user_id=$user_id\" -O - | \
@@ -227,24 +242,24 @@ chk_term()
chk_init_sys()
{ # Return init system type name.
if [[ $(/sbin/init --version 2>/dev/null) =~ upstart ]]; then
- _msg "${INF}init system is: upstart"
+ _msg_info "init system is: upstart"
INIT_SYS="upstart"
return 0
elif [[ $(systemctl 2>/dev/null) =~ -\.mount ]]; then
- _msg "${INF}init system is: systemd"
+ _msg_info "init system is: systemd"
INIT_SYS="systemd"
return 0
elif [[ -f /etc/init.d/cron && ! -h /etc/init.d/cron ]]; then
- _msg "${INF}init system is: sysv-init"
+ _msg_info "init system is: sysv-init"
INIT_SYS="sysv-init"
return 0
elif [[ $(openrc --version 2>/dev/null) =~ \(OpenRC ]]; then
- _msg "${INF}init system is: OpenRC"
+ _msg_info "init system is: OpenRC"
INIT_SYS="openrc"
return 0
else
INIT_SYS="NA"
- _err "${ERR}Init system could not be detected."
+ _err "Init system could not be detected."
fi
}
@@ -291,12 +306,12 @@ chk_sys_nscd()
{ # Check if nscd is up and suggest to start it or install it
if [ "$(type -P pidof)" ]; then
if [ ! "$(pidof nscd)" ]; then
- _msg "${WAR}We recommend installing and/or starting your distribution 'nscd' service"
- _msg "${WAR}Please read 'info guix \"Application Setup\"' about \"Name Service Switch\""
+ _msg_warn "We recommend installing and/or starting your distribution 'nscd' service"
+ _msg_warn "Please read 'info guix \"Application Setup\"' about \"Name Service Switch\""
fi
else
- _msg "${INF}We cannot determine if your distribution 'nscd' service is running"
- _msg "${INF}Please read 'info guix \"Application Setup\"' about \"Name Service Switch\""
+ _msg_info "We cannot determine if your distribution 'nscd' service is running"
+ _msg_info "Please read 'info guix \"Application Setup\"' about \"Name Service Switch\""
fi
}
@@ -334,7 +349,7 @@ guix_get_bin_list()
default_ver="guix-binary-${latest_ver}.${ARCH_OS}"
if [[ "${#bin_ver_ls}" -ne "0" ]]; then
- _msg "${PAS}Release for your system: ${default_ver}"
+ _msg_pass "Release for your system: ${default_ver}"
else
die "Could not obtain list of Guix releases."
fi
@@ -352,21 +367,21 @@ guix_get_bin()
_debug "--- [ ${FUNCNAME[0]} ] ---"
- _msg "${INF}Downloading Guix release archive"
+ _msg_info "Downloading Guix release archive"
wget --help | grep -q '\--show-progress' \
&& wget_args=("--no-verbose" "--show-progress")
if wget "${wget_args[@]}" -P "$dl_path" \
"${url}/${bin_ver}.tar.xz" "${url}/${bin_ver}.tar.xz.sig"; then
- _msg "${PAS}download completed."
+ _msg_pass "download completed."
else
die "could not download ${url}/${bin_ver}.tar.xz."
fi
pushd "${dl_path}" >/dev/null
if gpg --verify "${bin_ver}.tar.xz.sig" >/dev/null 2>&1; then
- _msg "${PAS}Signature is valid."
+ _msg_pass "Signature is valid."
popd >/dev/null
else
die "could not verify the signature."
@@ -382,18 +397,18 @@ sys_create_store()
if [[ -e /var/guix && -e /gnu ]]; then
if [ -n "$GUIX_ALLOW_OVERWRITE" ]; then
- _msg "${WAR}Overwriting existing installation!"
+ _msg_warn "Overwriting existing installation!"
else
die "A previous Guix installation was found. Refusing to overwrite."
fi
fi
cd "$tmp_path"
- _msg "${INF}Installing /var/guix and /gnu..."
+ _msg_info "Installing /var/guix and /gnu..."
# Strip (skip) the leading ‘.’ component, which fails on read-only ‘/’.
tar --extract --strip-components=1 --file "$pkg" -C /
- _msg "${INF}Linking the root user's profile"
+ _msg_info "Linking the root user's profile"
mkdir -p ~root/.config/guix
ln -sf /var/guix/profiles/per-user/root/current-guix \
~root/.config/guix/current
@@ -403,18 +418,18 @@ sys_create_store()
# effective linting.
# shellcheck disable=SC1091
source "${GUIX_PROFILE}/etc/profile"
- _msg "${PAS}activated root profile at ${GUIX_PROFILE}"
+ _msg_pass "activated root profile at ${GUIX_PROFILE}"
}
sys_delete_store()
{
- _msg "${INF}removing /var/guix"
+ _msg_info "removing /var/guix"
rm -rf /var/guix
- _msg "${INF}removing /gnu"
+ _msg_info "removing /gnu"
rm -rf /gnu
- _msg "${INF}removing ~root/.config/guix"
+ _msg_info "removing ~root/.config/guix"
rm -rf ~root/.config/guix
}
@@ -424,20 +439,20 @@ sys_create_build_user()
_debug "--- [ ${FUNCNAME[0]} ] ---"
if getent group guixbuild > /dev/null; then
- _msg "${INF}group guixbuild exists"
+ _msg_info "group guixbuild exists"
else
groupadd --system guixbuild
- _msg "${PAS}group <guixbuild> created"
+ _msg_pass "group <guixbuild> created"
fi
if getent group kvm > /dev/null; then
- _msg "${INF}group kvm exists and build users will be added to it"
+ _msg_info "group kvm exists and build users will be added to it"
local KVMGROUP=,kvm
fi
for i in $(seq -w 1 10); do
if id "guixbuilder${i}" &>/dev/null; then
- _msg "${INF}user is already in the system, reset"
+ _msg_info "user is already in the system, reset"
usermod -g guixbuild -G guixbuild"$KVMGROUP" \
-d /var/empty -s "$(which nologin)" \
-c "Guix build user $i" \
@@ -447,7 +462,7 @@ sys_create_build_user()
-d /var/empty -s "$(which nologin)" \
-c "Guix build user $i" --system \
"guixbuilder${i}";
- _msg "${PAS}user added <guixbuilder${i}>"
+ _msg_pass "user added <guixbuilder${i}>"
fi
done
}
@@ -460,7 +475,7 @@ sys_delete_build_user()
fi
done
- _msg "${INF}delete group guixbuild"
+ _msg_info "delete group guixbuild"
if getent group guixbuild &>/dev/null; then
groupdel -f guixbuild
fi
@@ -486,7 +501,7 @@ sys_enable_guix_daemon()
/etc/init/ &&
configure_substitute_discovery /etc/init/guix-daemon.conf &&
start guix-daemon; } &&
- _msg "${PAS}enabled Guix daemon via upstart"
+ _msg_pass "enabled Guix daemon via upstart"
;;
systemd)
{ install_unit()
@@ -511,7 +526,7 @@ sys_enable_guix_daemon()
systemctl daemon-reload &&
systemctl start guix-daemon; } &&
- _msg "${PAS}enabled Guix daemon via systemd"
+ _msg_pass "enabled Guix daemon via systemd"
;;
sysv-init)
{ mkdir -p /etc/init.d;
@@ -524,7 +539,7 @@ sys_enable_guix_daemon()
update-rc.d guix-daemon defaults &&
update-rc.d guix-daemon enable &&
service guix-daemon start; } &&
- _msg "${PAS}enabled Guix daemon via sysv"
+ _msg_pass "enabled Guix daemon via sysv"
;;
openrc)
{ mkdir -p /etc/init.d;
@@ -536,15 +551,15 @@ sys_enable_guix_daemon()
rc-update add guix-daemon default &&
rc-service guix-daemon start; } &&
- _msg "${PAS}enabled Guix daemon via OpenRC"
+ _msg_pass "enabled Guix daemon via OpenRC"
;;
NA|*)
- _msg "${ERR}unsupported init system; run the daemon manually:"
+ _err "unsupported init system; run the daemon manually:"
echo " ~root/.config/guix/current/bin/guix-daemon --build-users-group=guixbuild"
;;
esac
- _msg "${INF}making the guix command available to other users"
+ _msg_info "making the guix command available to other users"
[ -e "$local_bin" ] || mkdir -p "$local_bin"
ln -sf "${var_guix}/bin/guix" "$local_bin"
@@ -570,28 +585,28 @@ sys_delete_guix_daemon()
case "$INIT_SYS" in
upstart)
- _msg "${INF}stopping guix-daemon"
+ _msg_info "stopping guix-daemon"
stop guix-daemon
- _msg "${INF}removing guix-daemon"
+ _msg_info "removing guix-daemon"
rm /etc/init/guix-daemon.conf
;;
systemd)
if [ -f /etc/systemd/system/guix-daemon.service ]; then
- _msg "${INF}disabling guix-daemon"
+ _msg_info "disabling guix-daemon"
systemctl disable guix-daemon
- _msg "${INF}stopping guix-daemon"
+ _msg_info "stopping guix-daemon"
systemctl stop guix-daemon
- _msg "${INF}removing guix-daemon"
+ _msg_info "removing guix-daemon"
rm -f /etc/systemd/system/guix-daemon.service
fi
if [ -f /etc/systemd/system/gnu-store.mount ]; then
- _msg "${INF}disabling gnu-store.mount"
+ _msg_info "disabling gnu-store.mount"
systemctl disable gnu-store.mount
- _msg "${INF}stopping gnu-store.mount"
+ _msg_info "stopping gnu-store.mount"
systemctl stop gnu-store.mount
- _msg "${INF}removing gnu-store.mount"
+ _msg_info "removing gnu-store.mount"
rm -f /etc/systemd/system/gnu-store.mount
fi
systemctl daemon-reload
@@ -603,16 +618,16 @@ sys_delete_guix_daemon()
rm -rf /etc/init.d/guix-daemon
;;
NA|*)
- _msg "${ERR}unsupported init system; disable, stop and remove the daemon manually:"
+ _err "unsupported init system; disable, stop and remove the daemon manually:"
echo " ~root/.config/guix/current/bin/guix-daemon --build-users-group=guixbuild"
;;
esac
- _msg "${INF}removing $local_bin/guix"
+ _msg_info "removing $local_bin/guix"
rm -f "$local_bin"/guix
- _msg "${INF}removing $info_path/guix*"
+ _msg_info "removing $info_path/guix*"
rm -f "$info_path"/guix*
}
@@ -629,10 +644,10 @@ project's build farms?"; then
local key=~root/.config/guix/current/share/guix/$host.pub
[ -f "$key" ] \
&& guix archive --authorize < "$key" \
- && _msg "${PAS}Authorized public key for $host"
+ && _msg_pass "Authorized public key for $host"
done
else
- _msg "${INF}Skipped authorizing build farm public keys"
+ _msg_info "Skipped authorizing build farm public keys"
fi
}
@@ -715,7 +730,7 @@ sys_create_shell_completion()
ln -sf ${var_guix}/etc/bash_completion.d/guix-daemon "$bash_completion";
ln -sf ${var_guix}/share/zsh/site-functions/_guix "$zsh_completion";
ln -sf ${var_guix}/share/fish/vendor_completions.d/guix.fish "$fish_completion"; } &&
- _msg "${PAS}installed shell completion"
+ _msg_pass "installed shell completion"
}
sys_delete_shell_completion()
@@ -726,7 +741,7 @@ sys_delete_shell_completion()
zsh_completion=/usr/share/zsh/site-functions
fish_completion=/usr/share/fish/vendor_completions.d
- _msg "${INF}removing shell completion"
+ _msg_info "removing shell completion"
rm -f "$bash_completion"/guix;
rm -f "$bash_completion"/guix-daemon;
@@ -753,7 +768,7 @@ if [ -n "$GUIX_ENVIRONMENT" ]; then
fi
' >> "$bashrc"
done
- _msg "${PAS}Bash shell prompt successfully customized for Guix"
+ _msg_pass "Bash shell prompt successfully customized for Guix"
}
sys_maybe_setup_selinux()
@@ -782,17 +797,17 @@ sys_maybe_setup_selinux()
sys_delete_init_profile()
{
- _msg "${INF}removing /etc/profile.d/guix.sh"
+ _msg_info "removing /etc/profile.d/guix.sh"
rm -f /etc/profile.d/guix.sh
}
sys_delete_user_profiles()
{
- _msg "${INF}removing ~root/.guix-profile"
+ _msg_info "removing ~root/.guix-profile"
rm -f ~root/.guix-profile
rm -rf ~root/.cache/guix
- _msg "${INF}removing .guix-profile, .cache/guix and .config/guix of all /home users"
+ _msg_info "removing .guix-profile, .cache/guix and .config/guix of all /home users"
rm -rf /home/*/{.guix-profile,{.cache,.config}/guix}
}
@@ -841,8 +856,8 @@ EOF
if [ "$char" ]; then
echo
echo "...that ($char) was not a return!"
- _msg "${WAR}Use newlines to automate installation, e.g.: yes '' | ${0##*/}"
- _msg "${WAR}Any other method is unsupported and likely to break in future."
+ _msg_warn "Use newlines to automate installation, e.g.: yes '' | ${0##*/}"
+ _msg_warn "Any other method is unsupported and likely to break in future."
fi
}
@@ -861,7 +876,7 @@ main_install()
chk_sys_arch
chk_sys_nscd
- _msg "${INF}system is ${ARCH_OS}"
+ _msg_info "system is ${ARCH_OS}"
umask 0022
tmp_path="$(mktemp -t -d guix.XXXXXX)"
@@ -874,7 +889,7 @@ main_install()
if ! [[ $GUIX_BINARY_FILE_NAME =~ $ARCH_OS ]]; then
_err "$ARCH_OS not in ${GUIX_BINARY_FILE_NAME}; aborting"
fi
- _msg "${INF}Using manually provided binary ${GUIX_BINARY_FILE_NAME}"
+ _msg_info "Using manually provided binary ${GUIX_BINARY_FILE_NAME}"
GUIX_BINARY_FILE_NAME=$(realpath "$GUIX_BINARY_FILE_NAME")
fi
@@ -887,14 +902,14 @@ main_install()
sys_create_shell_completion
sys_customize_bashrc
- _msg "${INF}cleaning up ${tmp_path}"
+ _msg_info "cleaning up ${tmp_path}"
rm -r "${tmp_path}"
- _msg "${PAS}Guix has successfully been installed!"
- _msg "${INF}Run 'info guix' to read the manual."
+ _msg_pass "Guix has successfully been installed!"
+ _msg_info "Run 'info guix' to read the manual."
# Required to source /etc/profile in desktop environments.
- _msg "${INF}Please log out and back in to complete the installation."
+ _msg_info "Please log out and back in to complete the installation."
}
main_uninstall()
@@ -908,7 +923,7 @@ main_uninstall()
chk_init_sys
chk_sys_arch
- _msg "${INF}system is ${ARCH_OS}"
+ _msg_info "system is ${ARCH_OS}"
# stop the build, package system.
sys_delete_guix_daemon
@@ -922,12 +937,12 @@ main_uninstall()
sys_delete_shell_completion
# these directories are created on the fly during usage.
- _msg "${INF}removing /etc/guix"
+ _msg_info "removing /etc/guix"
rm -rf /etc/guix
- _msg "${INF}removing /var/log/guix"
+ _msg_info "removing /var/log/guix"
rm -rf /var/log/guix
- _msg "${PAS}Guix has successfully been uninstalled!"
+ _msg_pass "Guix has successfully been uninstalled!"
}
main()
--
2.47.1
L
L
Liam Hupfer wrote 5 days ago
[PATCH 9/9] guix-install.sh: Check for existing installation before downloading.
(address . 76082@debbugs.gnu.org)(name . Liam Hupfer)(address . liam@hpfr.net)
3bdb2d798b0ef6ffbba1f20e7263e47be6e9b9e3.1738815703.git.liam@hpfr.net
Previously, the check came after guix_get_bin. There’s no need to fetch
the rather large release archive if there’s an existing installation, so
check first. Refactor the check into a function similar to other
preflight checks.

* etc/guix-install.sh: Check for existing installation before
downloading.

Change-Id: I5506fb1cacdc88bd6355e8dfa1f690acf7886c1f
---
etc/guix-install.sh | 24 ++++++++++++++----------
1 file changed, 14 insertions(+), 10 deletions(-)

Toggle diff (51 lines)
diff --git a/etc/guix-install.sh b/etc/guix-install.sh
index 7a731962b3..297a726ad6 100755
--- a/etc/guix-install.sh
+++ b/etc/guix-install.sh
@@ -315,6 +315,19 @@ chk_sys_nscd()
fi
}
+chk_existing()
+{ # Avoid clobbering existing installations.
+ _debug "--- [ ${FUNCNAME[0]} ] ---"
+
+ if [[ -e /var/guix && -e /gnu ]]; then
+ if [ -n "$GUIX_ALLOW_OVERWRITE" ]; then
+ _msg_warn "Overwriting existing installation!"
+ else
+ die "A previous Guix installation was found. Refusing to overwrite."
+ fi
+ fi
+}
+
# Configure substitute discovery according to user's preferences.
# $1 is the installed service file to edit.
configure_substitute_discovery() {
@@ -393,16 +406,6 @@ sys_create_store()
local pkg="$1"
local tmp_path="$2"
- _debug "--- [ ${FUNCNAME[0]} ] ---"
-
- if [[ -e /var/guix && -e /gnu ]]; then
- if [ -n "$GUIX_ALLOW_OVERWRITE" ]; then
- _msg_warn "Overwriting existing installation!"
- else
- die "A previous Guix installation was found. Refusing to overwrite."
- fi
- fi
-
cd "$tmp_path"
_msg_info "Installing /var/guix and /gnu..."
# Strip (skip) the leading ‘.’ component, which fails on read-only ‘/’.
@@ -875,6 +878,7 @@ main_install()
chk_gpg_keyring
chk_sys_arch
chk_sys_nscd
+ chk_existing
_msg_info "system is ${ARCH_OS}"
--
2.47.1
?
Your comment

Commenting via the web interface is currently disabled.

To comment on this conversation send an email to 76082@debbugs.gnu.org

To respond to this issue using the mumi CLI, first switch to it
mumi current 76082
Then, you may apply the latest patchset in this issue (with sign off)
mumi am -- -s
Or, compose a reply to this issue
mumi compose
Or, send patches to this issue
mumi send-email *.patch