1{ lib
2, stdenv
3, fetchurl
4, fetchpatch
5, autoreconfHook
6, yodl
7, perl
8, groff
9, util-linux
10, texinfo
11, ncurses
12, pcre
13, buildPackages }:
14
15let
16 version = "5.9";
17in
18
19stdenv.mkDerivation {
20 pname = "zsh";
21 inherit version;
22 outputs = [ "out" "doc" "info" "man" ];
23
24 src = fetchurl {
25 url = "mirror://sourceforge/zsh/zsh-${version}.tar.xz";
26 sha256 = "sha256-m40ezt1bXoH78ZGOh2dSp92UjgXBoNuhCrhjhC1FrNU=";
27 };
28
29 patches = [
30 # fix location of timezone data for TZ= completion
31 ./tz_completion.patch
32 ];
33
34 strictDeps = true;
35 nativeBuildInputs = [ autoreconfHook perl groff texinfo pcre]
36 ++ lib.optionals stdenv.isLinux [ util-linux yodl ];
37
38 buildInputs = [ ncurses pcre ];
39
40 configureFlags = [
41 "--enable-maildir-support"
42 "--enable-multibyte"
43 "--with-tcsetpgrp"
44 "--enable-pcre"
45 "--enable-zprofile=${placeholder "out"}/etc/zprofile"
46 "--disable-site-fndir"
47 ];
48
49 # the zsh/zpty module is not available on hydra
50 # so skip groups Y Z
51 checkFlags = map (T: "TESTNUM=${T}") (lib.stringToCharacters "ABCDEVW");
52
53 # XXX: think/discuss about this, also with respect to nixos vs nix-on-X
54 postInstall = ''
55 make install.info install.html
56 mkdir -p $out/etc/
57 cat > $out/etc/zprofile <<EOF
58if test -e /etc/NIXOS; then
59 if test -r /etc/zprofile; then
60 . /etc/zprofile
61 else
62 emulate bash
63 alias shopt=false
64 . /etc/profile
65 unalias shopt
66 emulate zsh
67 fi
68 if test -r /etc/zprofile.local; then
69 . /etc/zprofile.local
70 fi
71else
72 # on non-nixos we just source the global /etc/zprofile as if we did
73 # not use the configure flag
74 if test -r /etc/zprofile; then
75 . /etc/zprofile
76 fi
77fi
78EOF
79 ${if stdenv.hostPlatform == stdenv.buildPlatform then ''
80 $out/bin/zsh -c "zcompile $out/etc/zprofile"
81 '' else ''
82 ${lib.getBin buildPackages.zsh}/bin/zsh -c "zcompile $out/etc/zprofile"
83 ''}
84 mv $out/etc/zprofile $out/etc/zprofile_zwc_is_used
85
86 rm $out/bin/zsh-${version}
87 mkdir -p $out/share/doc/
88 mv $out/share/zsh/htmldoc $out/share/doc/zsh-$version
89 '';
90 # XXX: patch zsh to take zwc if newer _or equal_
91
92 meta = {
93 description = "The Z shell";
94 longDescription = ''
95 Zsh is a UNIX command interpreter (shell) usable as an interactive login
96 shell and as a shell script command processor. Of the standard shells,
97 zsh most closely resembles ksh but includes many enhancements. Zsh has
98 command line editing, builtin spelling correction, programmable command
99 completion, shell functions (with autoloading), a history mechanism, and
100 a host of other features.
101 '';
102 license = "MIT-like";
103 homepage = "https://www.zsh.org/";
104 maintainers = with lib.maintainers; [ pSub artturin ];
105 platforms = lib.platforms.unix;
106 };
107
108 passthru = {
109 shellPath = "/bin/zsh";
110 };
111}