summary refs log tree commit diff
path: root/nixos/modules/programs/zsh/oh-my-zsh.nix
blob: 335f596ca80f0abde2a0d980b650704a3f400ec2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
{ config, lib, pkgs, ... }:

with lib;

let
  cfg = config.programs.zsh.oh-my-zsh;
in
  {
    options = {
      programs.zsh.oh-my-zsh = {
        enable = mkOption {
          default = false;
          description = ''
            Enable oh-my-zsh.
          '';
        };

        plugins = mkOption {
          default = [];
          type = types.listOf(types.str);
          description = ''
            List of oh-my-zsh plugins
          '';
        };

        custom = mkOption {
          default = "";
          type = types.str;
          description = ''
            Path to a custom oh-my-zsh package to override config of oh-my-zsh.
          '';
        };

        theme = mkOption {
          default = "";
          type = types.str;
          description = ''
            Name of the theme to be used by oh-my-zsh.
          '';
        };
      };
    };

    config = mkIf cfg.enable {
      environment.systemPackages = with pkgs; [ oh-my-zsh ];

      programs.zsh.interactiveShellInit = with pkgs; with builtins; ''
        # oh-my-zsh configuration generated by NixOS
        export ZSH=${oh-my-zsh}/share/oh-my-zsh

        ${optionalString (length(cfg.plugins) > 0)
          "plugins=(${concatStringsSep " " cfg.plugins})"
        }

        ${optionalString (stringLength(cfg.custom) > 0)
          "ZSH_CUSTOM=\"${cfg.custom}\""
        }

        ${optionalString (stringLength(cfg.theme) > 0)
          "ZSH_THEME=\"${cfg.theme}\""
        }

        source $ZSH/oh-my-zsh.sh
      '';
    };
  }