Discussion:
use zsh as login shell
宋文武
2014-11-27 15:58:38 UTC
Permalink
Currently, zsh doesn't work out of box.

IMO, we should use `/etc/environment' for system variables:
LANG=en_US.UTF-8
PATH=/run/current-system/profile/bin:/run/setuid-programs
And add `pam_env.so' to /etc/pam.d/login, to make tty login work.

With `/etc/profile', `/etc/zlogin' just:
source /etc/environment
to make `bash -l' and `zsh -l' work.

And `~/.bash_profile', `~/.zlogin' for user variables:
[[ $- == *i* ]] && source ~/.bashrc # only for bash

export PATH=$PATH:$HOME/.guix-profile/bin

Use `~/.bashrc', `~/.zshrc' for interactive settings:
PS1='$ '
alias ls='ls -p --color'
# $(guix package --search-paths)?


Note:
non-login interactive should inherit env from parent,
eg: `env -i $(which bash)' spawn a shell with no PATH (what I expect).
Ludovic Courtès
2014-11-27 20:15:36 UTC
Permalink
Post by 宋文武
Currently, zsh doesn't work out of box.
On the standalone system, right?
Post by 宋文武
LANG=en_US.UTF-8
PATH=/run/current-system/profile/bin:/run/setuid-programs
And add `pam_env.so' to /etc/pam.d/login, to make tty login work.
source /etc/environment
to make `bash -l' and `zsh -l' work.
Is ‘pam env’ needed at all if /etc/profile and /etc/zlogin are provided
anyway?
Post by 宋文武
[[ $- == *i* ]] && source ~/.bashrc # only for bash
export PATH=$PATH:$HOME/.guix-profile/bin
OK. It would be best to have $HOME/.guix-profile/bin in PATH installed
by /etc/{profile,zlogin}, though, so that it works out of the box.
Post by 宋文武
PS1='$ '
alias ls='ls -p --color'
# $(guix package --search-paths)?
OK.

Thanks for the very good summary! I never had this clear an
understanding of all this.

Would you like to submit a patch? The relevant parts are in (gnu
system) for /etc/profile, in (gnu system shadow) for the .bashrc
template, and in (gnu services base) for the PAM settings of the ‘login’
command.

Ludo’.
宋文武
2014-11-28 15:06:36 UTC
Permalink
Post by Ludovic Courtès
Post by 宋文武
Currently, zsh doesn't work out of box.
On the standalone system, right?
Yes.
Post by Ludovic Courtès
Post by 宋文武
LANG=en_US.UTF-8
PATH=/run/current-system/profile/bin:/run/setuid-programs
And add `pam_env.so' to /etc/pam.d/login, to make tty login work.
source /etc/environment
to make `bash -l' and `zsh -l' work.
Is ‘pam env’ needed at all if /etc/profile and /etc/zlogin are provided
anyway?
Yes, it's redundant.
Now I think the better way is just provide /etc/environment.
then `bash -l' would take ~/.bash_profile and ~/.profile.
We can have a default ~/.bash_profile like:
source /etc/environment
export PATH=$PATH:$HOME/.guix-profile/bin

And install skeletons only when needed by using:
(operating-system
(skeletons (list bash-profile)))

WDYT?
Post by Ludovic Courtès
Post by 宋文武
[[ $- == *i* ]] && source ~/.bashrc # only for bash
export PATH=$PATH:$HOME/.guix-profile/bin
OK. It would be best to have $HOME/.guix-profile/bin in PATH installed
by /etc/{profile,zlogin}, though, so that it works out of the box.
Post by 宋文武
PS1='$ '
alias ls='ls -p --color'
# $(guix package --search-paths)?
OK.
Thanks for the very good summary! I never had this clear an
understanding of all this.
In fact, I'm confused about this even now :)
Post by Ludovic Courtès
Would you like to submit a patch? The relevant parts are in (gnu
system) for /etc/profile, in (gnu system shadow) for the .bashrc
template, and in (gnu services base) for the PAM settings of the ‘login’
command.
Sure, I'll try to write a patch, thanks for the direction.
Post by Ludovic Courtès
Ludo’.
Ludovic Courtès
2014-11-28 22:26:30 UTC
Permalink
[...]
Post by 宋文武
Post by Ludovic Courtès
Post by 宋文武
LANG=en_US.UTF-8
PATH=/run/current-system/profile/bin:/run/setuid-programs
And add `pam_env.so' to /etc/pam.d/login, to make tty login work.
source /etc/environment
to make `bash -l' and `zsh -l' work.
Is ‘pam env’ needed at all if /etc/profile and /etc/zlogin are provided
anyway?
Yes, it's redundant.
Now I think the better way is just provide /etc/environment.
then `bash -l' would take ~/.bash_profile and ~/.profile.
source /etc/environment
export PATH=$PATH:$HOME/.guix-profile/bin
Currently, the .bashrc skeleton sources /etc/profile.

So, instead of what you suggest, what about having:

1. /etc/profile and /etc/zlogin (?) both source /etc/environment,
which uses plain Bourne syntax.

2. PATH is defined in /etc/environment and includes
~/.guix-profile/bin.

3. The skeleton for ~/.bash_profile sources /etc/profile, /etc/bashrc,
and ~/.bashrc.

4. The definition of PS1 is moved from /etc/profile to /etc/bashrc.

5. The skeleton for ~/.bashrc sources /etc/bashrc.

?

(I was reading the Bash manual to make sure (info "(bash) Bash Startup
Files"), and as an exercise, I’ve cleaned up my own ~/.bashrc and
~/.bash_profile accordingly, which fixes the issue I reported a couple
of weeks ago regarding ‘guix environment’.)

Thanks,
Ludo’.
宋文武
2014-11-29 03:24:13 UTC
Permalink
Post by Ludovic Courtès
[...]
Post by 宋文武
Post by Ludovic Courtès
Post by 宋文武
LANG=en_US.UTF-8
PATH=/run/current-system/profile/bin:/run/setuid-programs
And add `pam_env.so' to /etc/pam.d/login, to make tty login work.
source /etc/environment
to make `bash -l' and `zsh -l' work.
Is ‘pam env’ needed at all if /etc/profile and /etc/zlogin are provided
anyway?
Yes, it's redundant.
Now I think the better way is just provide /etc/environment.
then `bash -l' would take ~/.bash_profile and ~/.profile.
source /etc/environment
export PATH=$PATH:$HOME/.guix-profile/bin
Currently, the .bashrc skeleton sources /etc/profile.
1. /etc/profile and /etc/zlogin (?) both source /etc/environment,
which uses plain Bourne syntax.
2. PATH is defined in /etc/environment and includes
~/.guix-profile/bin.
/etc/environment is defined by pam_env to be a simple KEY=VAL file, with no
support for varibales substitute. If we do not use pam_env (linux specified?),
I think we should let /etc/zlogin source /etc/profile instead.

And we don't want /etc/zlogin when not using zsh at all,
IIUC while skeletons is configurable at the top os-expr, /etc/zlogin is
not.
Post by Ludovic Courtès
3. The skeleton for ~/.bash_profile sources /etc/profile, /etc/bashrc,
and ~/.bashrc.
4. The definition of PS1 is moved from /etc/profile to /etc/bashrc.
5. The skeleton for ~/.bashrc sources /etc/bashrc.
It seem too much, what I suggested is:
for login, su (pam_env): /etc/environment
for login shell: ~/.bash_profile, ~/.zlogin
for interactive: ~/.bashrc, ~/.zshrc
skeletons only installed when needed :)
Post by Ludovic Courtès
?
(I was reading the Bash manual to make sure (info "(bash) Bash Startup
Files"), and as an exercise, I’ve cleaned up my own ~/.bashrc and
~/.bash_profile accordingly, which fixes the issue I reported a couple
of weeks ago regarding ‘guix environment’.)
Thanks,
Ludo’.
Ludovic Courtès
2014-12-01 12:57:54 UTC
Permalink
[...]
Post by 宋文武
Post by Ludovic Courtès
1. /etc/profile and /etc/zlogin (?) both source /etc/environment,
which uses plain Bourne syntax.
2. PATH is defined in /etc/environment and includes
~/.guix-profile/bin.
/etc/environment is defined by pam_env to be a simple KEY=VAL file, with no
support for varibales substitute. If we do not use pam_env (linux specified?),
I think we should let /etc/zlogin source /etc/profile instead.
Yes, but they would contain almost the same lines, right? To what
extent is zsh Bourne- or Bash-compatible? Does ‘export foo=bar’ work
for zsh?

If it does, let’s just keep /etc/profile, and use it for both zsh and
Bash.
Post by 宋文武
And we don't want /etc/zlogin when not using zsh at all,
IIUC while skeletons is configurable at the top os-expr, /etc/zlogin is
not.
It’s OK to have a 2-KiB /etc/zlogin, even when one doesn’t use zsh.
Post by 宋文武
Post by Ludovic Courtès
3. The skeleton for ~/.bash_profile sources /etc/profile, /etc/bashrc,
and ~/.bashrc.
4. The definition of PS1 is moved from /etc/profile to /etc/bashrc.
5. The skeleton for ~/.bashrc sources /etc/bashrc.
for login, su (pam_env): /etc/environment
for login shell: ~/.bash_profile, ~/.zlogin
for interactive: ~/.bashrc, ~/.zshrc
skeletons only installed when needed :)
As a first step, what about always installing the skeletons? Then we
can see whether/how to refine that.

Thanks,
Ludo’.
宋文武
2014-12-02 14:43:20 UTC
Permalink
Post by Ludovic Courtès
[...]
Post by 宋文武
Post by Ludovic Courtès
1. /etc/profile and /etc/zlogin (?) both source /etc/environment,
which uses plain Bourne syntax.
2. PATH is defined in /etc/environment and includes
~/.guix-profile/bin.
/etc/environment is defined by pam_env to be a simple KEY=VAL file, with no
support for varibales substitute. If we do not use pam_env (linux specified?),
I think we should let /etc/zlogin source /etc/profile instead.
Yes, but they would contain almost the same lines, right? To what
extent is zsh Bourne- or Bash-compatible? Does ‘export foo=bar’ work
for zsh?
It does.
Post by Ludovic Courtès
If it does, let’s just keep /etc/profile, and use it for both zsh and
Bash.
Post by 宋文武
And we don't want /etc/zlogin when not using zsh at all,
IIUC while skeletons is configurable at the top os-expr, /etc/zlogin is
not.
It’s OK to have a 2-KiB /etc/zlogin, even when one doesn’t use zsh.
Post by 宋文武
Post by Ludovic Courtès
3. The skeleton for ~/.bash_profile sources /etc/profile, /etc/bashrc,
and ~/.bashrc.
4. The definition of PS1 is moved from /etc/profile to /etc/bashrc.
5. The skeleton for ~/.bashrc sources /etc/bashrc.
for login, su (pam_env): /etc/environment
for login shell: ~/.bash_profile, ~/.zlogin
for interactive: ~/.bashrc, ~/.zshrc
skeletons only installed when needed :)
As a first step, what about always installing the skeletons? Then we
can see whether/how to refine that.
No problem.
Post by Ludovic Courtès
Thanks,
Ludo’.
And this is what I have so far:
Ludovic Courtès
2014-12-04 23:10:35 UTC
Permalink
[...]
Post by Ludovic Courtès
Post by 宋文武
Post by Ludovic Courtès
3. The skeleton for ~/.bash_profile sources /etc/profile, /etc/bashrc,
and ~/.bashrc.
4. The definition of PS1 is moved from /etc/profile to /etc/bashrc.
5. The skeleton for ~/.bashrc sources /etc/bashrc.
for login, su (pam_env): /etc/environment
for login shell: ~/.bash_profile, ~/.zlogin
for interactive: ~/.bashrc, ~/.zshrc
skeletons only installed when needed :)
As a first step, what about always installing the skeletons? Then we
can see whether/how to refine that.
[...]
From 1e400957b29a47f63548df39b36a7c0f1d8a37d9 Mon Sep 17 00:00:00 2001
Date: Tue, 2 Dec 2014 21:40:52 +0800
Subject: [PATCH] gnu: Add /etc/environment.
* gnu/system.scm (default-/etc/environment): New procedure.
(etc-directory)[profile]: Remove it.
(etc-directory)[environment]: Add it.
* gnu/system/linux.scm (unix-pam-service): Add #:readenv? parameter.
* gnu/services/base.scm (mingetty-service): Pass #t as #:readenv?
to unix-pam-service.
* gnu/system/shadow.scm (default-skeletons): Add .bash_profile. Adjust .bashrc.
So you ended up choosing pam_env? I thought we had concluded that it
wasn’t needed, no? If it can be avoided, it’s better to do so, IMO.
+ (mlet %store-monad ((bash-profile (text-file "bash_profile" "\
+# honor ~/.bashrc if the shell is interactive
+[[ $- == *i* ]] && source ~/.bashrc
I don’t think the test is needed, because ~/.bash_profile is only read
by interactive Bash.
+# load system-wide environment varibales
+source /etc/environment
+
+# common varibales for user profile
+export PATH=$HOME/.guix-profile/bin:$HOME/.guix-profile/sbin:$PATH
+export INFOPATH=$HOME/.guix-profile/share/info:$INFOPATH\n"))
+ (bashrc (text-file "bashrc" "\
I think PS1 should go to /etc/profile. WDYT?

Thanks!

Ludo’.
Mark H Weaver
2014-12-05 05:11:29 UTC
Permalink
Post by Ludovic Courtès
+ (mlet %store-monad ((bash-profile (text-file "bash_profile" "\
+# honor ~/.bashrc if the shell is interactive
+[[ $- == *i* ]] && source ~/.bashrc
I don’t think the test is needed, because ~/.bash_profile is only read
by interactive Bash.
Indeed. However, it would be good to check if ~/.bashrc exists.
Section 6.2 of the Bash manual suggests this:

if [ -f ~/.bashrc ]; then . ~/.bashrc; fi
Post by Ludovic Courtès
+# load system-wide environment varibales
+source /etc/environment
+
+# common varibales for user profile
+export PATH=$HOME/.guix-profile/bin:$HOME/.guix-profile/sbin:$PATH
+export INFOPATH=$HOME/.guix-profile/share/info:$INFOPATH\n"))
+ (bashrc (text-file "bashrc" "\
I think PS1 should go to /etc/profile. WDYT?
I agree with 宋文武 that the PS1 setting belongs in the default
~/.bashrc skeleton. I would prefer to keep settings like this, that are
purely a matter of personal taste, out of system-wide files. Also,
/etc/profile is read by other shells, and I don't know that the syntax
above is portable.

Regards,
Mark
Ludovic Courtès
2014-12-05 18:54:12 UTC
Permalink
Post by Mark H Weaver
Post by Ludovic Courtès
+ (mlet %store-monad ((bash-profile (text-file "bash_profile" "\
+# honor ~/.bashrc if the shell is interactive
+[[ $- == *i* ]] && source ~/.bashrc
I don’t think the test is needed, because ~/.bash_profile is only read
by interactive Bash.
Indeed. However, it would be good to check if ~/.bashrc exists.
if [ -f ~/.bashrc ]; then . ~/.bashrc; fi
Yes.
Post by Mark H Weaver
Post by Ludovic Courtès
+# load system-wide environment varibales
+source /etc/environment
+
+# common varibales for user profile
+export PATH=$HOME/.guix-profile/bin:$HOME/.guix-profile/sbin:$PATH
+export INFOPATH=$HOME/.guix-profile/share/info:$INFOPATH\n"))
+ (bashrc (text-file "bashrc" "\
I think PS1 should go to /etc/profile. WDYT?
I agree with 宋文武 that the PS1 setting belongs in the default
~/.bashrc skeleton. I would prefer to keep settings like this, that are
purely a matter of personal taste, out of system-wide files. Also,
/etc/profile is read by other shells, and I don't know that the syntax
above is portable.
OK, that makes sense to me.

Ludo’.
宋文武
2014-12-05 11:21:31 UTC
Permalink
Post by Ludovic Courtès
[...]
Post by Ludovic Courtès
Post by 宋文武
Post by Ludovic Courtès
3. The skeleton for ~/.bash_profile sources /etc/profile, /etc/bashrc,
and ~/.bashrc.
4. The definition of PS1 is moved from /etc/profile to /etc/bashrc.
5. The skeleton for ~/.bashrc sources /etc/bashrc.
for login, su (pam_env): /etc/environment
for login shell: ~/.bash_profile, ~/.zlogin
for interactive: ~/.bashrc, ~/.zshrc
skeletons only installed when needed :)
As a first step, what about always installing the skeletons? Then we
can see whether/how to refine that.
[...]
From 1e400957b29a47f63548df39b36a7c0f1d8a37d9 Mon Sep 17 00:00:00 2001
Date: Tue, 2 Dec 2014 21:40:52 +0800
Subject: [PATCH] gnu: Add /etc/environment.
* gnu/system.scm (default-/etc/environment): New procedure.
(etc-directory)[profile]: Remove it.
(etc-directory)[environment]: Add it.
* gnu/system/linux.scm (unix-pam-service): Add #:readenv? parameter.
* gnu/services/base.scm (mingetty-service): Pass #t as #:readenv?
to unix-pam-service.
* gnu/system/shadow.scm (default-skeletons): Add .bash_profile. Adjust .bashrc.
So you ended up choosing pam_env? I thought we had concluded that it
wasn’t needed, no? If it can be avoided, it’s better to do so, IMO.
Ok, I'll take this approach this weekend :)
Post by Ludovic Courtès
+ (mlet %store-monad ((bash-profile (text-file "bash_profile" "\
+# honor ~/.bashrc if the shell is interactive
+[[ $- == *i* ]] && source ~/.bashrc
I don’t think the test is needed, because ~/.bash_profile is only read
by interactive Bash.
Yes, I'll do what Mark H Weaver suggest.
Post by Ludovic Courtès
+# load system-wide environment varibales
+source /etc/environment
+
+# common varibales for user profile
+export PATH=$HOME/.guix-profile/bin:$HOME/.guix-profile/sbin:$PATH
+export INFOPATH=$HOME/.guix-profile/share/info:$INFOPATH\n"))
+ (bashrc (text-file "bashrc" "\
I think PS1 should go to /etc/profile. WDYT?
+1 for Mark.
Post by Ludovic Courtès
Thanks!
Ludo’.
宋文武
2014-12-06 08:04:58 UTC
Permalink
My previous patches for bash/zsh did not put fish into consider.
It's not POSIX-compliant, I have to generate a different config file.

Gentoo/Exherho create different files for differnt shells, eg:
/etc/profile.env for sh
/etc/profile.csh for csh
both comming from /etc/env.d.

So, I could do something similar:
Ludovic Courtès
2014-12-06 15:09:11 UTC
Permalink
Post by 宋文武
My previous patches for bash/zsh did not put fish into consider.
It's not POSIX-compliant, I have to generate a different config file.
/etc/profile.env for sh
/etc/profile.csh for csh
It seems that /etc/profile is the standard name for Bourne shells, so I
would leave it under that name.

OK for /etc/profile.csh.
Post by 宋文武
both comming from /etc/env.d.
I don’t see a need to an /etc/env.d directory.

What about finalizing your previous patch, taking into account Mark’s
comments and mine, and then discussing Fish/csh support separately?
That would be easier for me.

Thanks!

Ludo’.
宋文武
2014-11-28 15:11:10 UTC
Permalink
Post by Ludovic Courtès
Post by 宋文武
Currently, zsh doesn't work out of box.
On the standalone system, right?
Yes.
Post by Ludovic Courtès
Post by 宋文武
LANG=en_US.UTF-8
PATH=/run/current-system/profile/bin:/run/setuid-programs
And add `pam_env.so' to /etc/pam.d/login, to make tty login work.
source /etc/environment
to make `bash -l' and `zsh -l' work.
Is ‘pam env’ needed at all if /etc/profile and /etc/zlogin are provided
anyway?
Yes, it's redundant.
Now I think the better way is just provide /etc/environment.
then `bash -l' would take ~/.bash_profile and ~/.profile.
We can have a default ~/.bash_profile like:
source /etc/environment
export PATH=$PATH:$HOME/.guix-profile/bin

And install skeletons only when needed by using:
(operating-system
(skeletons (list bash-profile)))

WDYT?
Post by Ludovic Courtès
Post by 宋文武
[[ $- == *i* ]] && source ~/.bashrc # only for bash
export PATH=$PATH:$HOME/.guix-profile/bin
OK. It would be best to have $HOME/.guix-profile/bin in PATH installed
by /etc/{profile,zlogin}, though, so that it works out of the box.
Post by 宋文武
PS1='$ '
alias ls='ls -p --color'
# $(guix package --search-paths)?
OK.
Thanks for the very good summary! I never had this clear an
understanding of all this.
In fact, I'm confused about this even now :)
Post by Ludovic Courtès
Would you like to submit a patch? The relevant parts are in (gnu
system) for /etc/profile, in (gnu system shadow) for the .bashrc
template, and in (gnu services base) for the PAM settings of the ‘login’
command.
Sure, I'll try to write a patch, thanks for the direction.
Post by Ludovic Courtès
Ludo’.
宋文武
2014-12-05 13:57:19 UTC
Permalink
Here are my new patches:
Yeh, just add ~/.zshrc to source /etc/profie is enough.
Ludovic Courtès
2014-12-06 22:35:55 UTC
Permalink
(I think I had overlooked this email earlier today, sorry for the
confusion.)
From 42ccd7a445c9676db6d2c7b2b0583db45be245aa Mon Sep 17 00:00:00 2001
Date: Fri, 5 Dec 2014 20:01:07 +0800
Subject: [PATCH 1/2] system: Cleanup bash startup files.
* gnu/system.scm (etc-directory) (bashrc): Rename to (profile).
'CPATH', 'LIBRARY_PATH': Remove.
'PS1', 'alias ls', 'alias ll': Move to ...
(.bashrc): ... here. Don't source /etc/profile.
(.bash_profile): New skeleton.
One last thing: I think CPATH and LIBRARY_PATH (and eventually
additional search path variables) should remain in /etc/profile.

WDYT?
From 043e4d9b6743654e048d3495cb5bfa592d17e6c4 Mon Sep 17 00:00:00 2001
Date: Fri, 5 Dec 2014 21:17:49 +0800
Subject: [PATCH 2/2] system: Add skeleton '.zshrc'.
* gnu/system/shadow.scm (default-skeletons): Add .zshrc.
OK.

Ludo’.

PS: In the future it may be easier for review to have one thread per
patch, as per ‘git send-email’.
宋文武
2014-12-07 04:06:49 UTC
Permalink
Post by Ludovic Courtès
(I think I had overlooked this email earlier today, sorry for the
confusion.)
Sorry for my mess.
Post by Ludovic Courtès
From 42ccd7a445c9676db6d2c7b2b0583db45be245aa Mon Sep 17 00:00:00 2001
Date: Fri, 5 Dec 2014 20:01:07 +0800
Subject: [PATCH 1/2] system: Cleanup bash startup files.
* gnu/system.scm (etc-directory) (bashrc): Rename to (profile).
'CPATH', 'LIBRARY_PATH': Remove.
'PS1', 'alias ls', 'alias ll': Move to ...
(.bashrc): ... here. Don't source /etc/profile.
(.bash_profile): New skeleton.
One last thing: I think CPATH and LIBRARY_PATH (and eventually
additional search path variables) should remain in /etc/profile.
I'll prefer use `guix environment' for dev, just install applications to
profile.
Post by Ludovic Courtès
WDYT?
From 043e4d9b6743654e048d3495cb5bfa592d17e6c4 Mon Sep 17 00:00:00 2001
Date: Fri, 5 Dec 2014 21:17:49 +0800
Subject: [PATCH 2/2] system: Add skeleton '.zshrc'.
* gnu/system/shadow.scm (default-skeletons): Add .zshrc.
Ah, this should be ~/.zlogin.
Post by Ludovic Courtès
OK.
Ludo’.
PS: In the future it may be easier for review to have one thread per
patch, as per ‘git send-email’.
Ok, I just wait for the msmtp to use git send-email :)
Ludovic Courtès
2014-12-07 20:35:48 UTC
Permalink
Post by 宋文武
Post by Ludovic Courtès
One last thing: I think CPATH and LIBRARY_PATH (and eventually
additional search path variables) should remain in /etc/profile.
I'll prefer use `guix environment' for dev, just install applications to
profile.
I agree that ‘guix environment’ is usually the preferred approach.

Yet, I thought it may be better to keep the other approach working out
of the box by default, to avoid unnecessary user frustration.

Thinking more, there are a number of other search path environment
variables that would be candidate for /etc/profile: GUILE_LOAD_PATH,
PKG_CONFIG_PATH, MANPATH, PERL5LIB, etc. But perhaps some of them are
better left handled by the user? How would we draw the line between
those that /etc/profile defines by default, and those that users have to
define by themselves?

Thanks,
Ludo’.

Loading...