nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 pkgs,
3 buildEnv,
4 runCommand,
5 lib,
6 stdenv,
7 freebsd,
8 binlore,
9}:
10
11# These are some unix tools that are commonly included in the /usr/bin
12# and /usr/sbin directory under more normal distributions. Along with
13# coreutils, these are commonly assumed to be available by build
14# systems, but we can't assume they are available. In Nix, we list
15# each program by name directly through this unixtools attribute.
16
17# You should always try to use single binaries when available. For
18# instance, if your program needs to use "ps", just list it as a build
19# input, not "procps" which requires Linux.
20
21let
22 inherit (lib)
23 getBin
24 getOutput
25 mapAttrs
26 platforms
27 ;
28
29 version = "1003.1-2008";
30
31 singleBinary =
32 cmd: providers:
33 let
34 provider = providers.${stdenv.hostPlatform.parsed.kernel.name} or providers.linux;
35 bin = "${getBin provider}/bin/${cmd}";
36 manDir = "${getOutput "man" provider}/share/man";
37 in
38 runCommand "${cmd}-${provider.name}"
39 {
40 meta = {
41 mainProgram = cmd;
42 priority = 10;
43 platforms = platforms.${stdenv.hostPlatform.parsed.kernel.name} or platforms.all;
44 };
45 inherit (provider) version pname;
46 passthru = {
47 inherit provider;
48 }
49 // lib.optionalAttrs (builtins.hasAttr "binlore" providers) {
50 binlore.out = (binlore.synthesize (getBin bins.${cmd}) providers.binlore);
51 };
52 preferLocalBuild = true;
53 }
54 ''
55 if ! [ -x ${bin} ]; then
56 echo Cannot find command ${cmd}
57 exit 1
58 fi
59
60 mkdir -p $out/bin
61 ln -s ${bin} $out/bin/${cmd}
62
63 if [ -d ${manDir} ]; then
64 manpages=($(cd ${manDir} ; find . -name '${cmd}*'))
65 for manpage in "''${manpages[@]}"; do
66 mkdir -p $out/share/man/$(dirname $manpage)
67 ln -s ${manDir}/$manpage $out/share/man/$manpage
68 done
69 fi
70 '';
71
72 # more is unavailable in darwin
73 # so we just use less
74 more_compat =
75 runCommand pkgs.less.name
76 {
77 inherit (pkgs.less) version pname;
78 }
79 ''
80 mkdir -p $out/bin
81 ln -s ${pkgs.less}/bin/less $out/bin/more
82 '';
83
84 bins = mapAttrs singleBinary {
85 # singular binaries
86 arp = {
87 linux = pkgs.net-tools;
88 darwin = pkgs.darwin.network_cmds;
89 freebsd = pkgs.freebsd.arp;
90 };
91 col = {
92 linux = pkgs.util-linux;
93 darwin = pkgs.darwin.text_cmds;
94 };
95 column = {
96 linux = pkgs.util-linux;
97 darwin = pkgs.darwin.text_cmds;
98 };
99 eject = {
100 linux = pkgs.util-linux;
101 };
102 getconf = {
103 linux = if stdenv.hostPlatform.libc == "glibc" then pkgs.libc else pkgs.netbsd.getconf;
104 darwin = pkgs.darwin.system_cmds;
105 # I don't see any obvious arg exec in the doc/manpage
106 binlore = ''
107 execer cannot bin/getconf
108 '';
109 };
110 getent = {
111 linux = if stdenv.hostPlatform.libc == "glibc" then pkgs.libc.getent else pkgs.netbsd.getent;
112 darwin = pkgs.netbsd.getent;
113 freebsd = pkgs.freebsd.getent;
114 openbsd = pkgs.openbsd.getent;
115 };
116 getopt = {
117 linux = pkgs.util-linux;
118 darwin = pkgs.getopt;
119 };
120 fdisk = {
121 linux = pkgs.util-linux;
122 darwin = pkgs.darwin.diskdev_cmds;
123 freebsd = pkgs.freebsd.fdisk;
124 };
125 fsck = {
126 linux = pkgs.util-linux;
127 darwin = pkgs.darwin.diskdev_cmds;
128 };
129 hexdump = {
130 linux = pkgs.util-linuxMinimal;
131 darwin = pkgs.darwin.shell_cmds;
132 };
133 hostname = {
134 linux = pkgs.hostname-debian;
135 darwin = pkgs.darwin.shell_cmds;
136 freebsd = pkgs.freebsd.bin;
137 openbsd = pkgs.openbsd.hostname;
138 };
139 ifconfig = {
140 linux = pkgs.net-tools;
141 darwin = pkgs.darwin.network_cmds;
142 freebsd = pkgs.freebsd.ifconfig;
143 openbsd = pkgs.openbsd.ifconfig;
144 };
145 killall = {
146 linux = pkgs.psmisc;
147 darwin = pkgs.darwin.shell_cmds;
148 };
149 locale = {
150 linux = pkgs.glibc;
151 darwin = pkgs.darwin.adv_cmds;
152 freebsd = pkgs.freebsd.locale;
153 # technically just targeting glibc version
154 # no obvious exec in manpage
155 binlore = ''
156 execer cannot bin/locale
157 '';
158 };
159 logger = {
160 linux = pkgs.util-linux;
161 darwin = pkgs.darwin.remote_cmds;
162 };
163 more = {
164 linux = pkgs.util-linux;
165 darwin = more_compat;
166 };
167 mount = {
168 linux = pkgs.util-linux;
169 darwin = pkgs.darwin.diskdev_cmds;
170 freebsd = freebsd.mount;
171 openbsd = pkgs.openbsd.mount;
172 # technically just targeting the darwin version; binlore already
173 # ids the util-linux copy as 'cannot'
174 # no obvious exec in manpage args; I think binlore flags 'can'
175 # on the code to run `mount_<filesystem>` variants
176 binlore = ''
177 execer cannot bin/mount
178 '';
179 };
180 netstat = {
181 linux = pkgs.net-tools;
182 darwin = pkgs.darwin.network_cmds;
183 freebsd = pkgs.freebsd.netstat;
184 };
185 ping = {
186 linux = pkgs.iputils;
187 darwin = pkgs.darwin.network_cmds;
188 freebsd = freebsd.ping;
189 };
190 ps = {
191 linux = pkgs.procps;
192 darwin = pkgs.darwin.ps;
193 freebsd = pkgs.freebsd.bin;
194 openbsd = pkgs.openbsd.ps;
195 # technically just targeting procps ps (which ids as can)
196 # but I don't see obvious exec in args; have yet to look
197 # for underlying cause in source
198 binlore = ''
199 execer cannot bin/ps
200 '';
201 };
202 quota = {
203 linux = pkgs.linuxquota;
204 darwin = pkgs.darwin.diskdev_cmds;
205 };
206 route = {
207 linux = pkgs.net-tools;
208 darwin = pkgs.darwin.network_cmds;
209 freebsd = pkgs.freebsd.route;
210 openbsd = pkgs.openbsd.route;
211 };
212 script = {
213 linux = pkgs.util-linux;
214 darwin = pkgs.darwin.shell_cmds;
215 };
216 sysctl = {
217 linux = pkgs.procps;
218 darwin = pkgs.darwin.system_cmds;
219 freebsd = pkgs.freebsd.sysctl;
220 openbsd = pkgs.openbsd.sysctl;
221 };
222 top = {
223 linux = pkgs.procps;
224 darwin = pkgs.darwin.top;
225 freebsd = pkgs.freebsd.top;
226 openbsd = pkgs.openbsd.top;
227 # technically just targeting procps top; haven't needed this in
228 # any scripts so far, but overriding it for consistency with ps
229 # override above and in procps. (procps also overrides 'free',
230 # but it isn't included here.)
231 binlore = ''
232 execer cannot bin/top
233 '';
234 };
235 umount = {
236 linux = pkgs.util-linux;
237 darwin = pkgs.darwin.diskdev_cmds;
238 };
239 whereis = {
240 linux = pkgs.util-linux;
241 darwin = pkgs.darwin.shell_cmds;
242 };
243 wall = {
244 linux = pkgs.util-linux;
245 darwin = pkgs.darwin.remote_cmds;
246 };
247 watch = {
248 linux = pkgs.procps;
249
250 # watch is the only command from procps that builds currently on
251 # Darwin/FreeBSD. Unfortunately no other implementations exist currently!
252 darwin = pkgs.callPackage ../os-specific/linux/procps-ng { };
253 freebsd = pkgs.callPackage ../os-specific/linux/procps-ng { };
254 openbsd = pkgs.callPackage ../os-specific/linux/procps-ng { };
255 };
256 write = {
257 linux = pkgs.util-linux;
258 darwin = pkgs.darwin.basic_cmds;
259 };
260 xxd = {
261 linux = pkgs.tinyxxd;
262 darwin = pkgs.tinyxxd;
263 freebsd = pkgs.tinyxxd;
264 };
265 };
266
267 makeCompat =
268 pname: paths:
269 buildEnv {
270 inherit paths pname version;
271 };
272
273 # Compatibility derivations
274 # Provided for old usage of these commands.
275 compat =
276 with bins;
277 mapAttrs makeCompat {
278 procps = [
279 ps
280 sysctl
281 top
282 watch
283 ];
284 util-linux = [
285 fsck
286 fdisk
287 getopt
288 hexdump
289 mount
290 script
291 umount
292 whereis
293 write
294 col
295 column
296 ];
297 net-tools = [
298 arp
299 hostname
300 ifconfig
301 netstat
302 route
303 ];
304 };
305in
306bins // compat