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.
NobbZ
March 7, 2020, 9:38am
2
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
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
.
fpath+=(${HOME}/.nix-profile/share/zsh-powerlevel10k)
3 Likes
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
NobbZ
March 8, 2020, 8:12am
4
Hm, seems as if I missremembered things regarding ZSH, themes and the fpath
…
Then I do see 2 possibilities left.
Softlink to the themes location in your profile
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
Not sure I understand this;) “./p10k-config” is a directory? in the home directory and “p10k.zsh” is a file inside that directory?
NobbZ
November 27, 2022, 10:30pm
7
Yes. It contains a single file, .p10k.zsh
, as described in the cited post.
famadorian:
in the home directory
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.
NobbZ
November 27, 2022, 11:30pm
9
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:
https://github.com/NobbZ/nixos-config/tree/main/home/modules/profiles/base/p10k-config
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";
NobbZ
November 28, 2022, 9:12am
11
The path is relative to the file you mention it in.
Please read more about path-literals in the manual.
https://nixos.org/manual/nix/stable/language/values.html#type-path
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";
}
NobbZ
November 28, 2022, 10:37am
13
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?
NobbZ
November 28, 2022, 10:59am
15
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?
This is how I made it work for Spaceship:
{ lib, config, pkgs, ... }: {
home.packages = with pkgs; [
zsh
spaceship-prompt
];
programs.zsh = {
enable = true;
initExtra = ''
source ${pkgs.spaceship-prompt}/share/zsh/themes/spaceship.zsh-theme;
'';
}
Hi there,
This is how I manage to use my own custom zsh theme (and some plugins not presented in nixpkgs)
{ pkgs }:
let
threetimeslazy-theme = builtins.toFile "threetimeslazy.zsh-theme" ''
local user='%{$fg[magenta]%}%n@%{$fg[magenta]%}%m%{$reset_color%}'
local pwd='%{$fg[blue]%}$(shrink_path -f)>%{$reset_color%}'
local return_code='%(?..%{$fg[red]%}%? ↵%{$reset_color%})'
local git_branch='$(git_prompt_status)%{$reset_color%}$(git_prompt_info)%{$reset_color%}'
ZSH_THEME_RVM_PROMPT_OPTIONS="i v g"
ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[green]%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_DIRTY=""
ZSH_THEME_GIT_PROMPT_CLEAN=""
PROMPT="''${user} ''${pwd}
$ "
RPROMPT="''${return_code} ''${git_branch}"
'';
fast-syntax-highlighting = pkgs.fetchFromGitHub {
owner = "zdharma-continuum";
repo = "fast-syntax-highlighting";
rev = "v1.55";
sha256 = "sha256-DWVFBoICroKaKgByLmDEo4O+xo6eA8YO792g8t8R7kA=";
};
fzf-tab = pkgs.fetchFromGitHub {
owner = "Aloxaf";
repo = "fzf-tab";
rev = "v1.1.2";
sha256 = "sha256-Qv8zAiMtrr67CbLRrFjGaPzFZcOiMVEFLg1Z+N6VMhg=";
};
zsh-customs = pkgs.stdenv.mkDerivation {
name = "zsh-customs";
phases = [ "buildPhase" ];
buildPhase = ''
mkdir -p $out/themes
cp ${threetimeslazy-theme} $out/themes/threetimeslazy.zsh-theme
mkdir -p $out/plugins
cp -r ${fast-syntax-highlighting} $out/plugins/fast-syntax-highlighting
cp -r ${fzf-tab} $out/plugins/fzf-tab
'';
};
in
{
enable = true;
dotDir = ".config/zsh";
autocd = true;
autosuggestion.enable = true;
autosuggestion.strategy = ["completion" "history"];
oh-my-zsh = {
enable = true;
plugins = [
"git"
"fzf"
"fzf-tab"
"zoxide"
"fast-syntax-highlighting"
"shrink-path"
"kubectl"
"docker"
"colored-man-pages"
];
theme = "threetimeslazy";
custom = "${zsh-customs}";
};
}