nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 fetchurl,
4 bash,
5 tinycc,
6 gnumake,
7 gnupatch,
8 heirloom-devtools,
9 heirloom,
10}:
11let
12 pname = "heirloom";
13 version = "070715";
14
15 src = fetchurl {
16 url = "mirror://sourceforge/heirloom/heirloom/${version}/heirloom-${version}.tar.bz2";
17 sha256 = "sha256-6zP3C8wBmx0OCkHx11UtRcV6FicuThxIY07D5ESWow8=";
18 };
19
20 patches = [
21 # we pre-generate nawk's proctab.c as meslibc is not capable of running maketab
22 # during build time (insufficient sscanf support)
23 ./proctab.patch
24
25 # disable utilities that don't build successfully
26 ./disable-programs.patch
27
28 # "tcc -ar" doesn't support creating empty archives
29 ./tcc-empty-ar.patch
30 # meslibc doesn't have separate libm
31 ./dont-link-lm.patch
32 # meslibc's vprintf doesn't support %ll
33 ./vprintf.patch
34 # meslibc doesn't support sysconf()
35 ./sysconf.patch
36 # meslibc doesn't support locale
37 ./strcoll.patch
38 # meslibc doesn't support termios.h
39 ./termios.patch
40 # meslibc doesn't support utime.h
41 ./utime.patch
42 # meslibc doesn't support langinfo.h
43 ./langinfo.patch
44 # support building with meslibc
45 ./meslibc-support.patch
46 # remove socket functionality as unsupported by meslibc
47 ./cp-no-socket.patch
48 ];
49
50 makeFlags = [
51 # mk.config build options
52 "CC='tcc -B ${tinycc.libs}/lib -include ${./stubs.h} -include ${./musl.h}'"
53 "AR='tcc -ar'"
54 "RANLIB=true"
55 "STRIP=true"
56 "SHELL=${bash}/bin/sh"
57 "POSIX_SHELL=${bash}/bin/sh"
58 "DEFBIN=/bin"
59 "SV3BIN=/5bin"
60 "S42BIN=/5bin/s42"
61 "SUSBIN=/bin"
62 "SU3BIN=/5bin/posix2001"
63 "UCBBIN=/ucb"
64 "CCSBIN=/ccs/bin"
65 "DEFLIB=/lib"
66 "DEFSBIN=/bin"
67 "MANDIR=/share/man"
68 "LCURS=" # disable ncurses
69 "USE_ZLIB=0" # disable zlib
70 "IWCHAR='-I../libwchar'"
71 "LWCHAR='-L../libwchar -lwchar'"
72 ];
73in
74bash.runCommand "${pname}-${version}"
75 {
76 inherit pname version;
77
78 nativeBuildInputs = [
79 tinycc.compiler
80 gnumake
81 gnupatch
82 heirloom-devtools
83 ];
84
85 passthru.sed = bash.runCommand "${pname}-sed-${version}" { } ''
86 install -D ${heirloom}/bin/sed $out/bin/sed
87 '';
88
89 passthru.tests.get-version =
90 result:
91 bash.runCommand "${pname}-get-version-${version}" { } ''
92 ${result}/bin/banner Hello Heirloom
93 mkdir $out
94 '';
95
96 meta = with lib; {
97 description = "Heirloom Toolchest is a collection of standard Unix utilities";
98 homepage = "https://heirloom.sourceforge.net/tools.html";
99 license = with licenses; [
100 # All licenses according to LICENSE/
101 zlib
102 caldera
103 bsdOriginalUC
104 cddl
105 bsd3
106 gpl2Plus
107 lgpl21Plus
108 lpl-102
109 info-zip
110 ];
111 teams = [ teams.minimal-bootstrap ];
112 platforms = platforms.unix;
113 };
114 }
115 ''
116 # Unpack
117 unbz2 --file ${src} --output heirloom.tar
118 untar --file heirloom.tar
119 rm heirloom.tar
120 cd heirloom-${version}
121
122 # Patch
123 ${lib.concatMapStringsSep "\n" (f: "patch -Np0 -i ${f}") patches}
124 cp ${./proctab.c} nawk/proctab.c
125
126 # Build
127 # These tools are required during later build steps
128 export PATH="$PATH:$PWD/ed:$PWD/nawk:$PWD/sed"
129 make ${lib.concatStringsSep " " makeFlags}
130
131 # Install
132 make install ROOT=$out ${lib.concatStringsSep " " makeFlags}
133 ''