How to setup zsh/ohmyzsh in nixos?

2.3k Views Asked by At

my nixos config looks like this:

{ config, pkgs, ... }: {
  programs.zsh = {
    enable = true;
    ohMyZsh = {
        enable = true;
        plugins = [ "git" "zsh-history-substring-search" ];
    };    
  };
  users.users.USER.shell = pkgs.zsh;
  environment.systemPackages = [
    pkgs.oh-my-zsh
    pkgs.zsh
    pkgs.zsh-completions
    pkgs.zsh-powerlevel10k
    pkgs.zsh-syntax-highlighting
    pkgs.zsh-history-substring-search
  ];
}

and i kind of expected that my existing .zshrc just works, but this is not the case. For example when opening a new shell i get this error:

[oh-my-zsh] plugin 'zsh-history-substring-search' not found

But its clearly installed (see systemPackages).

Also i had this in my .zshrc file:

source /usr/share/zsh-theme-powerlevel10k/powerlevel10k.zsh-theme

which makes sense that it cannot be sourced (since its probably installed somewhere else), but my question now is: where is stuff actually installed in nixos? How can i find this file?

1

There are 1 best solutions below

0
Jayadeep KM On

The configuration looks correct. Here are some debugging ideas,

  1. Check where ohmyzsh is installed. Your zshrc should have a line source $ZSH/oh-my-zsh.sh generated. Run cd $ZSH to enter that directory.
  2. Inspect the oh-my-zsh.sh file. There should be a block similar to the one below (I use home-manager, so yours might look different)
# Add all defined plugins to fpath. This must be done
# before running compinit.
for plugin ($plugins); do
  if is_plugin "$ZSH_CUSTOM" "$plugin"; then
    fpath=("$ZSH_CUSTOM/plugins/$plugin" $fpath)
  elif is_plugin "$ZSH" "$plugin"; then
    fpath=("$ZSH/plugins/$plugin" $fpath)
  else
    echo "[oh-my-zsh] plugin '$plugin' not found"
  fi
done

Here you can find the plugins directory. In my case it was plugins folder in the same directory.

  1. Check if the plugins are present in that folder

fyi,

  • You can also enable syntax highlighting by setting programs.zsh.syntaxHighlighting.enable to true
  • You can set the theme using programs.zsh.ohMyZsh.theme instead of sourcing the theme file manually.