Using an external oh-my-zsh theme with zsh in nix?

I’m trying to set up powerlevel10k which has a nixpkg with oh-my-zsh, but it doesn’t seem to let me configure it via the normal ZSH_THEME.

nix-env -i zsh oh-my-zsh powerlevel10k

I can’t set my ZSH_THEME in .zshrc to be powerlevel10k, since it’s not installed to the oh-my-zsh themes directory:

-- .nix-profile/
  -- share/
    -- oh-my-zsh/themes/
    -- zsh-powerlevel10k/

Does anybody know how I can set the ZSH_THEME in my .zshrc to look at powerlevel10k? This is for a machine running just nix, not nixos.

Are you using home-manager?

There I have something like this:

programs.zsh.plugins = [
    name = "powerlevel10k";
    src = pkgs.zsh-powerlevel10k;
    file = "share/zsh-powerlevel10k/powerlevel10k.zsh-theme";
    name = "powerlevel10k-config";
    src = lib.cleanSource ./p10k-config;
    file = "p10k.zsh";

Whereas the config is just the single .p10k.zsh which was generated with the wizard once. I’m planning to fiddle with it later, but there are more important things to do :smiley:

If you don’t use home-manager, but the theme is linked from your profile (as it looks like from your screenshot), just add that to your fpath.


Thanks for the advice!

I’m not using home manager, so I’ve added the theme to my fpath, but for setting the ZSH_THEME variable it looks like it is looking under the $ZSH/themes/$ZSH_THEME

This means even if I set the theme to be an absolute path or to the powerlevel10k theme, it just gives me an error saying no such file or directory: /home/<username>/.nix-profile/share/oh-my-zsh/themes/powerlevel10k

Hm, seems as if I missremembered things regarding ZSH, themes and the fpath

Then I do see 2 possibilities left.

  1. Softlink to the themes location in your profile
  2. Don’t use ZSH_THEME but source the file directly.

(PS: home-manager does basically a mix of both. The p10k files are linked from within my .config/zsh folder into the nix-store for discoverability, though still sourced from the zshrc.

Oh awesome - I didn’t realize I could just source the file directly instead of the ZSH_THEME variable.

Thanks so much :slight_smile:

Not sure I understand this;) “./p10k-config” is a directory? in the home directory and “p10k.zsh” is a file inside that directory?

Yes. It contains a single file, .p10k.zsh, as described in the cited post.

No, right besides the HM module that references it.

I’m sorry. I don’t get it;) I don’t get where this directory is located.

side by side to the file, in which I have written ./p10k-config, thats how a path expression in nix works.

To be more specific:

The cited code:

The folder:

I’m talking about my own p10k.zsh, which I have generated and I have in my home directory.

I have trouble understanding which directory to move this to and how to reference it there.

If I move it to ~/.config/powerlevel, can I do?:

src = lib.cleanSource ./config/powerlevel;
file = "p10k.zsh";

The path is relative to the file you mention it in.

Please read more about path-literals in the manual.

Right, I had to give an absolute path to include my own config. Thanks

      name = "powerlevel10k-config";
      src = lib.cleanSource "/home/b0ef/ds/platform/conf";
      file = "zsh-p10k.zsh";

That is not a path literal, thats a string, that can be coerced into an absolute path under some circumstances.

Either way, absolute pathes are bad for reproducibility. You should make sure that the p10k config actually becomes part of your configuration, and lies at a place thats easily discoverable/referable from the nix file. Preferably a sibling.

Right, that’s very bad for reproducibility, but the only way to make it reproducible is to include the contents of zsh-p10k.zsh into the home.nix file, but that’s not pretty, either. Another way is to push it to a repo of my own on github?

It does not need to be part of, just “beneath” or “besides” it, as I have.

There is no need for a repository (though it is recommended).

I assume you are using HM standalone, channels, and have everything in a single home.nix without extracting anything into modules or other files.

So you have your ~/.config/nixpkgs/home.nix which then contains the plugin like this:

      name = "powerlevel10k-config";
      src = ./conf;
      file = "zsh-p10k.zsh";

And then you have also ~/.config/nixpkgs/conf/zsh-p10k.zsh

The lib.cleanSource is actually not necessary and a left over from a time before I used flakes.

Right, thanks;)

As a side question, wouldn’t better reproducibility require URN, as in magnet links, instead of stuff on github?:wink: