ZSH installs via Home Manager but isn't working

ZSH installs into the directory I have declared in the following file, but autocd and the alias do not work. Am I missing something? I’m transitioning from a previous homebrew install of ZSH (already uninstalled), so hopefully nothing is conflicting.

My home_manager/modules/shell/zsh.nix:

{ config, lib, pkgs, ... }:

{
  programs.zsh = {
    enable = true;
    autocd = true;
    dotDir = ".config/zsh";
    enableAutosuggestions = true;
    enableCompletion = true;
    shellAliases = {
      l = "ls -la";
    };

    };
}

My ~/.config/zsh:

.zshenv -> /nix/store/1a4r07rx0cj0h61kadycrjk6hwv6znvl-home-manager-files/.config/zsh/.zshenv

.zshrc -> /nix/store/1a4r07rx0cj0h61kadycrjk6hwv6znvl-home-manager-files/.config/zsh/.zshrc

which zsh:

/Users/me/.nix-profile/bin/zsh

My home manager flake.nix:

{
description = "Home Manager configuration of me";

  inputs = {
    # Specify overlays. - not really what you're doing, these are just inputs, the overlay specification is down in your inline module
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
    home-manager = {
      url = "github:nix-community/home-manager";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs = { nixpkgs, home-manager, ... }: let
    username = "me";
    system = "x86_64-darwin";
  in {
    homeConfigurations.${username} = home-manager.lib.homeManagerConfiguration {
      pkgs = nixpkgs.legacyPackages.${system};
      modules = [
        ({
          home = {
            inherit username;
            homeDirectory = "/Users/${username}";
            stateVersion = "22.11";
          };

          programs.home-manager.enable = true;
          programs.helix.enable = true;
          programs.htop.enable = true;
          programs.lazygit.enable = true;
          programs.lsd.enable = true;
          programs.jq.enable = true;
          programs.alacritty.enable = true;
          programs.skim.enable = true;
        })

        ./home_manager/modules/cli/fzf.nix
        ./home_manager/modules/cli/git.nix
        ./home_manager/modules/gui/blender.nix
        ./home_manager/modules/gui/libreoffice.nix
        ./home_manager/modules/gui/iina.nix
        ./home_manager/modules/shell/zsh.nix
      ];
    };
  };
}
  • What is the content of ~/.zshenv?
  • Does it source the $HOME/.config/zsh/.zshenv?
  • Does that set ZDOTDIR?
  • Does echo $ZDOTDIR agree with what is set above?
  • Does $ZDOTDIR/.zshrc contain the aliases?
1 Like

Thanks @NobbZ,

~/.zshenv:

.zshenv -> /nix/store/1a4r07rx0cj0h61kadycrjk6hwv6znvl-home-manager-files/.zshenv

that’s also a link:

.zshenv -> /nix/store/z97rbjqljsdc57lyha5kak9n1i15czbq-hm_.zshenv

that has as content part of the alias I have set in home_manager/modules/shell/zsh.nix:

ls -la

In my /etc/zshenv I do have:

export ZDOTDIR="/Users/me/Library/Application Support/.config/zsh"

export XDG_CACHE_HOME="${HOME}/.cache"
export XDG_CACHE_DIRS="${HOME}/.cache"
export XDG_CACHE_DIR="${HOME}/.cache"
export XDG_CONFIG_HOME="${HOME}/.config"
export XDG_CONFIG_DIRS="${HOME}/.config"
export XDG_CONFIG_DIR="${HOME}/.config"
export XDG_DATA_HOME="${HOME}/share"
export XDG_DATA_DIRS="${HOME}/share"
export XDG_DATA_DIR="${HOME}/share"
export XDG_STATE_HOME="${HOME}/state"
export XDG_STATE_DIRS="${HOME}/state"
export XDG_STATE_DIR="${HOME}/state"
export XDG_BIN_HOME="${HOME}/.local/bin"
export XDG_BIN_DIRS="${HOME}/.local/bin"
export XDG_BIN_DIR="${HOME}/.local/bin"
export XDG_RUNTIME_HOME="${HOME}/.run"
export XDG_RUNTIME_DIRS="${HOME}/.run"
export XDG_RUNTIME_DIR="${HOME}/.run"

export NIX_STORE_DIR="/nix/store"
export NIX_DATA_DIR="/nix/var/nix/db"
export NIX_LOG_DIR="/nix/var/log/nix"
export NIX_STATE_DIR="/nix/var/nix"
export NIX_CONF_DIR="${XDG_CONFIG_HOME}/nix"
export NIX_CONF_DIR="${XDG_CONFIG_DIRS}/nix"
export NIX_CONF_DIR="${XDG_CONFIG_DIR}/nix"
export NIX_PROFILES="/nix/var/nix/profiles"

The multiple XDG paths are because of confusion I’ve seen about the spec and apps honoring different interpretations of the paths. So far they’ve worked fine with Nix and the NIX_CONF_DIR etc have worked well too, although the install script has ignored some attempts to change the paths. My original goal was to honour Apple’s settings eg use ~/Library/Application\ Support/ as the XDG_CONFIG_HOME but from memory the Nix installer ignored some of the paths.

So this attempt at installing nix, home manager, and apps (and zsh) is using ~/.config etc as per above, and I’m attempting to move as many dotfiles as possible out of my $HOME into those directories.

Are you explicitly running this zsh, or just opening a new terminal that runs it?

If the latter, you may need to either set the zsh path that your terminal uses, or use chsh to set the default in macOS.

Thanks @abathur,

I’m running zsh in a terminal via an iTerm profile with the custom shell setting:


/Users/me/.nix-profile/bin/zsh

See if you can add an -x flag in iTerm to activate trace? May make it more obvious if it’s stopping early?

Thanks @abathur,

Do you mean like this?

/Users/me/.nix-profile/bin/zsh -x

If so, iTerm isn’t allowing me to do that - as it’s removing the space to form:

/Users/me/.nix-profile/bin/zsh-x

Yeah. Drat.

I think if you can edit /etc/zshrc to add a “set -x” on a line by itself near the top it’ll have more or less the same effect.

1 Like

Thanks @abathur,

I did that and then opened another terminal/shell session, and this is the output before my command prompt:

+/etc/zshrc:4> [ -e /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh ']'
+/etc/zshrc:5> . /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh
+/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh:2> [ -n '' ']'
+/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh:3> __ETC_PROFILE_NIX_SOURCED=1
+/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh:5> export NIX_PROFILES='/nix/var/nix/profiles/default /Users/me/.nix-profile'
+/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh:8> [ -n '' ']'
+/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh:10> [ -e /etc/ssl/certs/ca-certificates.crt ']'
+/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh:12> [ -e /etc/ssl/ca-bundle.pem ']'
+/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh:14> [ -e /etc/ssl/certs/ca-bundle.crt ']'
+/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh:16> [ -e /etc/pki/tls/certs/ca-bundle.crt ']'
+/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh:33> check_nix_profiles
+check_nix_profiles:1> [ -n 5.9 ']'
+check_nix_profiles:5> setopt local_options shwordsplit
+check_nix_profiles:7> i=/nix/var/nix/profiles/default
+check_nix_profiles:8> [ -e /nix/var/nix/profiles/default/etc/ssl/certs/ca-bundle.crt ']'
+check_nix_profiles:9> export NIX_SSL_CERT_FILE=/nix/var/nix/profiles/default/etc/ssl/certs/ca-bundle.crt
+check_nix_profiles:7> i=/Users/me/.nix-profile
+check_nix_profiles:8> [ -e /Users/me/.nix-profile/etc/ssl/certs/ca-bundle.crt ']'
+/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh:34> unset -f check_nix_profiles
+/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh:37> export PATH=/Users/me/.nix-profile/bin:/nix/var/nix/profiles/default/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Library/Apple/usr/bin:/Applications/iTerm.app/Contents/Resources/utilities

You have not answered a single if my questions. Could you please revise them?

Aww @NobbZ, I thought I had answered at least

a single question

of yours -

What is the content of ~/.zshenv ?

and I thought that answer also answered:

* Does it source the `$HOME/.config/zsh/.zshenv` ?
* Does that set `ZDOTDIR` ?

However, my sincere apologies for not answering:

* Does `echo $ZDOTDIR` agree with what is set above?
* Does `$ZDOTDIR/.zshrc` contain the aliases?

I somehow missed those as I’ve been tending to a sick cat after an inter-city commute for work, between looking after a dead relatives property, while running a business.

Had I not been distracted and seen your thoughtful questions (as your help always is), I would have had ZSH fixed sooner… as I now have after your reminding me of your questions, which is well timed with my sitting back down in my office again with a full attention span. (The cat is well again too.)

I had forgotten that my setup script for my mac had set ZDOTDIR to ~/Library/Application\ Support/.config/zsh and have now corrected that to ~/.config/zsh, and autocd and the alias are working.

Many thanks for your help here @Nobbz and in every question you have helped me with (it’s why I have hearted them and thanked you each time for replying and helping me), and many thanks to @abathur too.