Skip to content

Commit 8076968

Browse files
committed
Make default shell to zsh
1 parent 033def4 commit 8076968

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

.config/home-manager/home.nix

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{ config, userConfig, pkgs, ... }:
1+
{ config, userConfig, pkgs, lib, ... }:
22

33
{
44
home.username = builtins.getEnv "USER";
@@ -21,6 +21,23 @@
2121

2222
home.sessionVariables = userConfig.env;
2323

24+
# Set zsh as default shell on activation
25+
home.activation.make-zsh-default-shell = lib.hm.dag.entryAfter [ "writeBoundary" ] ''
26+
# if zsh is not the current shell
27+
PATH="/usr/bin:/bin:$PATH"
28+
ZSH_PATH="/home/${builtins.getEnv "USER"}/.nix-profile/bin/zsh"
29+
if [[ $(getent passwd ${builtins.getEnv "USER"}) != *"$ZSH_PATH" ]]; then
30+
echo "Setting zsh as default shell..."
31+
if ! grep -q $ZSH_PATH /etc/shells; then
32+
echo "Adding zsh to /etc/shells"
33+
run echo "$ZSH_PATH" | sudo tee -a /etc/shells
34+
fi
35+
echo "Running chsh to make zsh the default shell"
36+
run chsh -s $ZSH_PATH ${builtins.getEnv "USER"}
37+
echo "Zsh is now set as default shell!"
38+
fi
39+
'';
40+
2441
# Let Home Manager install and manage itself.
2542
programs.home-manager.enable = true;
2643

0 commit comments

Comments
 (0)