How to use powerlevel10k prompt with Zsh?

# zsh.nix
{ pkgs, ... }:

{
  programs.zsh = {
    enable = true;
      plugins = [
        {
          name = "powerlevel10k";
          src = pkgs.zsh-powerlevel10k;
          file = "share/zsh-powerlevel10k/powerlevel10k.zsh-theme";
        }
        {
          name = "powerlevel10k-config";
          src = ./p10k-config;
          file = "p10k.zsh";
        }
      ];
  };
}
error:
       … while calling the 'derivationStrict' builtin

         at /builtin/derivation.nix:9:12: (source not available)

       … while evaluating derivation 'home-manager-generation'
         whose name attribute is located at /nix/store/xwc3zfc544jg6zhr0wi6k8253s7mwlhi-source/pkgs/stdenv/generic/make-derivation.nix:353:7

       … while evaluating attribute 'buildCommand' of derivation 'home-manager-generation'

         at /nix/store/xwc3zfc544jg6zhr0wi6k8253s7mwlhi-source/pkgs/build-support/trivial-builders/default.nix:98:16:

           97|         enableParallelBuilding = true;
           98|         inherit buildCommand name;
             |                ^
           99|         passAsFile = [ "buildCommand" ]

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: getting status of '/nix/store/9msmqj7psvxw04x8vci1nlfk9cinbk70-source/modules/home/p10k.zsh': No such file or directory

Start with :
https://search.nixos.org/packages?channel=unstable&show=zsh-powerlevel10k&from=0&size=30&sort=relevance&type=packages&query=powerlevel

1 Like

error: getting status of ‘/nix/store/v4935803w9455zly212cx01ylhsl9fjl-source/modules/home/p10k-config’: No such file or directory

Not sure how to create that p10k-config directory in home.
With powerlevel10k generator it is putting p10k.zsh in home directory, and at least it works fine. Just want to move that config into not existent p10k-config directory.

I use Home manager for this:

home.packages = with pkgs; [ zsh-powerlevel10k meslo-lgs-nf ];
programs.zsh.enable = true;
home.file.".p10k.zsh".text = builtins.readFile ./p10k.zsh;

The whole (very messy ^^') configuration can be found here: https://github.com/mickours/nixos-config/blob/6694179962931efc54e802a61c7bff5b51ff8329/config/home.nix

1 Like

Thanks. I will look into it. Never used builtins before.

Hey nex, I found that I had to provide the plugin src slightly different in my zsh module: https://github.com/EmergentMind/nix-config/blob/14adb9899cb101d0599dc3d7aa88a70ba4cf0388/home/ta/common/core/zsh/default.nix

I can’t remember offhand why this was they case, and I’m unfortunately short on time to refresh my memory, but the relevant snippet is:

    plugins = [
      {
        name = "powerlevel10k-config";
        src = ./p10k;
        file = "p10k.zsh";
      }
      {
        name = "zsh-powerlevel10k";
        src = "${pkgs.zsh-powerlevel10k}/share/zsh-powerlevel10k/";
        file = "powerlevel10k.zsh-theme";
      }

There may be some other helpful bits in that module for you as well. Getting zsh, oh-my-zsh, and p10k to play nicely was a bit finicky at first.
Hope that helps!

1 Like

Tnx. Now it complains about not existent p10k directory:

error: getting status of '/nix/store/w9f7867cc8npgfj8pzjbld70wv99hisv-source/modules/home/p10k': No such file or directory

Just can’t make that directory. Maybe I will create one with home.file.

Already had 50k bookmarks about nix, and now it’s 50.002 :smiley:

That’s telling you that the path you provided is incorrect.
The snippet I posted is from my own nix-config so you will have to edit to match your own paths and naming.

Looks like where I have src = ./p10k; you will need to put src = ./p10k-config;

Yes, but that assume that I do have p10k or p10k-config directory, while I don’t have one in nix store.

Tried to move it to nix store with that line alone and it can’t do it.

home.file.".p10k.zsh".source = dotfiles/p10k.zsh;

Full path to a file that I can’t somehow put in nixstore: /home/mee/dotfiles/p10k.zsh

error: getting status of ‘/nix/store/n9wrmbp689i3r41b72dqr00b076d73mz-source/dotfiles’: No such file or directory

Thanks for help and all the links. I will reinstall system as something is messed up with nix-store for me.

Hmmm, you shouldn’t have to create the file in the nix-store yourself.

The src and file options specified in the plugin expression will tell nixos to where find your p10k.zsh file and it will move them to the store for you when you build the config.

This is a snippet from your zsh.nix in the original post, which is why I assumed you had a p10k-config directory:

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

You’ll need to update the src value to be the path to where your p10k.zsh file is located. The path your specify needs to be relative to wherever you have your zsh.nix file is located.

For example, let’s say you have your zsh.nix in home/mee/nix-config/zsh.nix, the src for that plugin would be ../dotfiles and nixos would look for your specified p10k.zsh file at that location.

Hopefully that helps.
Also, you may not need to reinstall. Selecting a previous generation on reboot will allow you to ‘rollback’ to a build prior to your nix-store getting messed up. :slight_smile:

1 Like

Thank you for explanation. That will definitely help me, once I’ll figure out how to properly install home manager in NixOS. I’ve also tried without that directory and something was really messed up. :laughing:

Based on your last reply I was able to solve the issue. I had no clue that my p10k.zsh need to be in relative path to zsh.nix.

All of my modules, including home.nix are in /etc/nixos directory. Moving p10k.zsh from ~ to /etc/nixos/dotfiles/ solved everything. Tnx. :slight_smile:

#/etc/nixos/modules/home/zsh.nix
{ pkgs, ... }:

{
  programs.zsh = {
    enable = true;
    plugins = [
      {
        name = "powerlevel10k-config";
        src = ../../dotfiles;
        file = "p10k.zsh";
      }
      {
        name = "zsh-powerlevel10k";
        src = "${pkgs.zsh-powerlevel10k}/share/zsh-powerlevel10k/";
        file = "powerlevel10k.zsh-theme";
      }
    ];
  };
}
2 Likes

Seems like this way the config won’t be portable - it’s hardcoded to the specific system.

I spent a fair bit of time blindly experimenting with nix syntax to come up with an elegant solution. In the end, I realized I can just do this:

programs.zsh.enable = true;                                                                                                    
programs.zsh.initExtra = "source ~/.p10k.zsh";
programs.zsh.plugins = [   
  {                                                                                   
    name = "powerlevel10k";                                                           
    src = pkgs.zsh-powerlevel10k;                                                     
    file = "share/zsh-powerlevel10k/powerlevel10k.zsh-theme";                         
  }
];

The p10k configuration wizard complains that it can’t write to ~/.zshrc, but I believe all it really wants to do is to add a line souring the ~/.p10k.zsh - file to which it can write freely.

If the file doesn’t exists there is no issue, the wizard runs the first time you open zsh. At the very end the option to append .zshrc won’t be there, but the second option will be akin to “I understand and I will deal with it manually myself”, which still saves config to the .p10k.zsh file. So we deal with it manually simply by using programs.zsh.initExtra. :slightly_smiling_face:

1 Like

I wonder if I can get the instant prompt to work… which requires adding a line to the top of the .zshrc…

Try programs.zsh.initExtraFirst

This worked, thanks!