Setup Zsh + Oh-my-zsh + PowerLevel10K - NixOS (without Home-manager)

Hello folks! Hope you’re doing good? :sunny:

Here’s my today’s challenge : How to setup complete terminal environment with Zsh + Oh-my-zsh + PowerLevel10K, using only nix derivation (only NixOS config, no Home-manager)

I’m not using Home-manager as I’m the only user (except root), and will ever be. I’m trying to achieve the most through Nix only, because I feel like it can do the job just fine.

Here’s my current config :

# shell.nix

{ pkgs, ... }: {
  environment.systemPackages = with pkgs; [ zsh-powerlevel10k ];
  programs.zsh = {
    enable = true;
    enableCompletion = true;
    enableBashCompletion = true;
    autosuggestions.enable = true;
    syntaxHighlighting.enable = true;
    histSize = 10000;
    shellAliases = {
      #...
    };
    setOptions = [
      "AUTO_CD"
    ]
    prompInit = ''
      source ${pkgs.zsh-powerlevel10k}/share/zsh-powerlevel10k/powerlevel10k.zsh-theme
    '';
    ohMyZsh = {
      enable = true;
      plugins = [ "git" "dirhistory" "history" ];
    };
  };
  users.defaultUserShell = pkgs.zsh;
  system.userActivationScripts.zshrc = "touch .zshrc";
  environment.shells = with pkgs; [ zsh ];
}

With the latter, I have all three components almost working as expected. What’s remaining is the declarative P10K config initialization… I’ve generated the (long) config (.p10k.zsh) through the “manual” (p10k configure) command, and since I’ve enabled the p10k “instant prompt” it added a code snippet to my .zshrc file too.

  • I’d like to provide/generate those two files declaratively when building generation (with the current config), how to achieve that? For both the default user (me) and root.
    • .p10k.zsh
    • .zshrc

Here’s some questions about my setup :

  • Is OMZ (Oh-my-zsh) required in my case?
  • Does the Zsh + OMZ + P10K stack makes sense out there, the way I use it?
    • I use zsh/omz to enjoy the plugins and theme eco-system around it, but if I can simplify it, let me know. I just want a CLI that makes my life easier.
  • Can root user inherit from those configs as well? When I sudo -i for example?
  • Can it integrate easily with nix-shell? how?

There’s a related thread, but it looks like home-manager config to me…

Thanks for your time! :pray: