Merge pull request #43282 from Ma27/support-external-zsh-plugins
nixos/ohMyZsh: allow multiple derivations in `ZSH_CUSTOM`
This commit is contained in:
commit
8fb7ab9b32
|
@ -3,7 +3,30 @@
|
|||
with lib;
|
||||
|
||||
let
|
||||
|
||||
cfg = config.programs.zsh.ohMyZsh;
|
||||
|
||||
mkLinkFarmEntry = name: dir:
|
||||
let
|
||||
env = pkgs.buildEnv {
|
||||
name = "zsh-${name}-env";
|
||||
paths = cfg.customPkgs;
|
||||
pathsToLink = "/share/zsh/${dir}";
|
||||
};
|
||||
in
|
||||
{ inherit name; path = "${env}/share/zsh/${dir}"; };
|
||||
|
||||
mkLinkFarmEntry' = name: mkLinkFarmEntry name name;
|
||||
|
||||
custom =
|
||||
if cfg.custom != null then cfg.custom
|
||||
else if length cfg.customPkgs == 0 then null
|
||||
else pkgs.linkFarm "oh-my-zsh-custom" [
|
||||
(mkLinkFarmEntry' "themes")
|
||||
(mkLinkFarmEntry "completions" "site-functions")
|
||||
(mkLinkFarmEntry' "plugins")
|
||||
];
|
||||
|
||||
in
|
||||
{
|
||||
options = {
|
||||
|
@ -34,10 +57,19 @@ in
|
|||
};
|
||||
|
||||
custom = mkOption {
|
||||
default = "";
|
||||
type = types.str;
|
||||
default = null;
|
||||
type = with types; nullOr str;
|
||||
description = ''
|
||||
Path to a custom oh-my-zsh package to override config of oh-my-zsh.
|
||||
(Can't be used along with `customPkgs`).
|
||||
'';
|
||||
};
|
||||
|
||||
customPkgs = mkOption {
|
||||
default = [];
|
||||
type = types.listOf types.package;
|
||||
description = ''
|
||||
List of custom packages that should be loaded into `oh-my-zsh`.
|
||||
'';
|
||||
};
|
||||
|
||||
|
@ -67,7 +99,7 @@ in
|
|||
|
||||
environment.systemPackages = [ cfg.package ];
|
||||
|
||||
programs.zsh.interactiveShellInit = with builtins; ''
|
||||
programs.zsh.interactiveShellInit = ''
|
||||
# oh-my-zsh configuration generated by NixOS
|
||||
export ZSH=${cfg.package}/share/oh-my-zsh
|
||||
|
||||
|
@ -75,8 +107,8 @@ in
|
|||
"plugins=(${concatStringsSep " " cfg.plugins})"
|
||||
}
|
||||
|
||||
${optionalString (stringLength(cfg.custom) > 0)
|
||||
"ZSH_CUSTOM=\"${cfg.custom}\""
|
||||
${optionalString (custom != null)
|
||||
"ZSH_CUSTOM=\"${custom}\""
|
||||
}
|
||||
|
||||
${optionalString (stringLength(cfg.theme) > 0)
|
||||
|
@ -92,5 +124,15 @@ in
|
|||
|
||||
source $ZSH/oh-my-zsh.sh
|
||||
'';
|
||||
|
||||
assertions = [
|
||||
{
|
||||
assertion = cfg.custom != null -> cfg.customPkgs == [];
|
||||
message = "If `cfg.custom` is set for `ZSH_CUSTOM`, `customPkgs` can't be used!";
|
||||
}
|
||||
];
|
||||
|
||||
};
|
||||
|
||||
meta.doc = ./oh-my-zsh.xml;
|
||||
}
|
||||
|
|
125
nixos/modules/programs/zsh/oh-my-zsh.xml
Normal file
125
nixos/modules/programs/zsh/oh-my-zsh.xml
Normal file
|
@ -0,0 +1,125 @@
|
|||
<chapter xmlns="http://docbook.org/ns/docbook"
|
||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
||||
xmlns:xi="http://www.w3.org/2001/XInclude"
|
||||
version="5.0"
|
||||
xml:id="module-programs-zsh-ohmyzsh">
|
||||
|
||||
<title>Oh my ZSH</title>
|
||||
|
||||
<para><literal><link xlink:href="https://ohmyz.sh/">oh-my-zsh</link></literal> is a framework
|
||||
to manage your <link xlink:href="https://www.zsh.org/">ZSH</link> configuration
|
||||
including completion scripts for several CLI tools or custom prompt themes.</para>
|
||||
|
||||
<section><title>Basic usage</title>
|
||||
<para>The module uses the <literal>oh-my-zsh</literal> package with all available features. The
|
||||
initial setup using Nix expressions is fairly similar to the configuration format
|
||||
of <literal>oh-my-zsh</literal>.
|
||||
|
||||
<programlisting>
|
||||
{
|
||||
programs.ohMyZsh = {
|
||||
enable = true;
|
||||
plugins = [ "git" "python" "man" ];
|
||||
theme = "agnoster";
|
||||
};
|
||||
}
|
||||
</programlisting>
|
||||
|
||||
For a detailed explanation of these arguments please refer to the
|
||||
<link xlink:href="https://github.com/robbyrussell/oh-my-zsh/wiki"><literal>oh-my-zsh</literal> docs</link>.
|
||||
</para>
|
||||
<para>The expression generates the needed
|
||||
configuration and writes it into your <literal>/etc/zshrc</literal>.
|
||||
</para></section>
|
||||
|
||||
<section><title>Custom additions</title>
|
||||
|
||||
<para>Sometimes third-party or custom scripts such as a modified theme may be needed.
|
||||
<literal>oh-my-zsh</literal> provides the
|
||||
<link xlink:href="https://github.com/robbyrussell/oh-my-zsh/wiki/Customization#overriding-internals"><literal>ZSH_CUSTOM</literal></link>
|
||||
environment variable for this which points to a directory with additional scripts.</para>
|
||||
|
||||
<para>The module can do this as well:
|
||||
|
||||
<programlisting>
|
||||
{
|
||||
programs.ohMyZsh.custom = "~/path/to/custom/scripts";
|
||||
}
|
||||
</programlisting>
|
||||
</para></section>
|
||||
|
||||
<section><title>Custom environments</title>
|
||||
|
||||
<para>There are several extensions for <literal>oh-my-zsh</literal> packaged in <literal>nixpkgs</literal>.
|
||||
One of them is <link xlink:href="https://github.com/spwhitt/nix-zsh-completions">nix-zsh-completions</link>
|
||||
which bundles completion scripts and a plugin for <literal>oh-my-zsh</literal>.</para>
|
||||
|
||||
<para>Rather than using a single mutable path for <literal>ZSH_CUSTOM</literal>, it's also possible to
|
||||
generate this path from a list of Nix packages:
|
||||
|
||||
<programlisting>
|
||||
{ pkgs, ... }:
|
||||
{
|
||||
programs.ohMyZsh.customPkgs = with pkgs; [
|
||||
pkgs.nix-zsh-completions
|
||||
# and even more...
|
||||
];
|
||||
}
|
||||
</programlisting>
|
||||
|
||||
Internally a single store path will be created using <literal>buildEnv</literal>.
|
||||
Please refer to the docs of
|
||||
<link xlink:href="https://nixos.org/nixpkgs/manual/#sec-building-environment"><literal>buildEnv</literal></link>
|
||||
for further reference.</para>
|
||||
|
||||
<para><emphasis>Please keep in mind that this is not compatible with <literal>programs.ohMyZsh.custom</literal>
|
||||
as it requires an immutable store path while <literal>custom</literal> shall remain mutable! An evaluation failure
|
||||
will be thrown if both <literal>custom</literal> and <literal>customPkgs</literal> are set.</emphasis>
|
||||
</para></section>
|
||||
|
||||
<section><title>Package your own customizations</title>
|
||||
|
||||
<para>If third-party customizations (e.g. new themes) are supposed to be added to <literal>oh-my-zsh</literal>
|
||||
there are several pitfalls to keep in mind:</para>
|
||||
|
||||
<itemizedlist>
|
||||
<listitem>
|
||||
<para>To comply with the default structure of <literal>ZSH</literal> the entire output needs to be written to
|
||||
<literal>$out/share/zsh.</literal></para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>Completion scripts are supposed to be stored at <literal>$out/share/zsh/site-functions</literal>. This directory
|
||||
is part of the <literal><link xlink:href="http://zsh.sourceforge.net/Doc/Release/Functions.html">fpath</link></literal>
|
||||
and the package should be compatible with pure <literal>ZSH</literal> setups. The module will automatically link
|
||||
the contents of <literal>site-functions</literal> to completions directory in the proper store path.</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>The <literal>plugins</literal> directory needs the structure <literal>pluginname/pluginname.plugin.zsh</literal>
|
||||
as structured in the <link xlink:href="https://github.com/robbyrussell/oh-my-zsh/tree/91b771914bc7c43dd7c7a43b586c5de2c225ceb7/plugins">upstream repo.</link>
|
||||
</para>
|
||||
</listitem>
|
||||
</itemizedlist>
|
||||
|
||||
<para>
|
||||
A derivation for <literal>oh-my-zsh</literal> may look like this:
|
||||
<programlisting>
|
||||
{ stdenv, fetchFromGitHub }:
|
||||
|
||||
stdenv.mkDerivation rec {
|
||||
name = "exemplary-zsh-customization-${version}";
|
||||
version = "1.0.0";
|
||||
src = fetchFromGitHub {
|
||||
# path to the upstream repository
|
||||
};
|
||||
|
||||
dontBuild = true;
|
||||
installPhase = ''
|
||||
mkdir -p $out/share/zsh/site-functions
|
||||
cp {themes,plugins} $out/share/zsh
|
||||
cp completions $out/share/zsh/site-functions
|
||||
'';
|
||||
}
|
||||
</programlisting>
|
||||
</para>
|
||||
</section>
|
||||
</chapter>
|
|
@ -1,4 +1,4 @@
|
|||
{ stdenv, fetchFromGitHub }:
|
||||
{ stdenv, fetchFromGitHub, zsh }:
|
||||
|
||||
stdenv.mkDerivation {
|
||||
name = "lambda-mod-zsh-theme-unstable-2017-10-08";
|
||||
|
@ -10,9 +10,13 @@ stdenv.mkDerivation {
|
|||
rev = "61c373c8aa5556d51522290b82ad44e7166bced1";
|
||||
};
|
||||
|
||||
buildInputs = [ zsh ];
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/share/themes
|
||||
cp lambda-mod.zsh-theme $out/share/themes
|
||||
chmod +x lambda-mod.zsh-theme # only executable scripts are found by `patchShebangs`
|
||||
patchShebangs .
|
||||
|
||||
install -Dm0644 lambda-mod.zsh-theme $out/share/zsh/themes/lambda-mod.zsh-theme
|
||||
'';
|
||||
|
||||
meta = with stdenv.lib; {
|
||||
|
|
|
@ -15,15 +15,16 @@ stdenv.mkDerivation rec {
|
|||
};
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/share/zsh/site-functions
|
||||
mkdir -p $out/share/zsh/{site-functions,plugins/nix}
|
||||
cp _* $out/share/zsh/site-functions
|
||||
cp *.zsh $out/share/zsh/plugins/nix
|
||||
'';
|
||||
|
||||
meta = {
|
||||
meta = with stdenv.lib; {
|
||||
homepage = https://github.com/spwhitt/nix-zsh-completions;
|
||||
description = "ZSH completions for Nix, NixOS, and NixOps";
|
||||
license = stdenv.lib.licenses.bsd3;
|
||||
platforms = stdenv.lib.platforms.all;
|
||||
maintainers = [ stdenv.lib.maintainers.spwhitt stdenv.lib.maintainers.olejorgenb stdenv.lib.maintainers.hedning ];
|
||||
license = licenses.bsd3;
|
||||
platforms = platforms.all;
|
||||
maintainers = with maintainers; [ spwhitt olejorgenb hedning ma27 ];
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user