2018-04-11 19:46:53 +02:00
|
|
|
{ pkgs, buildEnv, runCommand, hostPlatform, stdenv, lib }:
|
2018-03-26 06:01:31 +02:00
|
|
|
|
2018-03-27 05:37:49 +02:00
|
|
|
# These are some unix tools that are commonly included in the /usr/bin
|
|
|
|
# and /usr/sbin directory under more normal distributions. Along with
|
|
|
|
# coreutils, these are commonly assumed to be available by build
|
|
|
|
# systems, but we can't assume they are available. In Nix, we list
|
|
|
|
# each program by name directly through this unixtools attribute.
|
|
|
|
|
|
|
|
# You should always try to use single binaries when available. For
|
|
|
|
# instance, if your program needs to use "ps", just list it as a build
|
|
|
|
# input, not "procps" which requires Linux.
|
|
|
|
|
2018-03-26 06:01:31 +02:00
|
|
|
let
|
|
|
|
|
2018-03-28 02:26:10 +02:00
|
|
|
singleBinary = cmd: providers: let
|
2018-05-01 16:37:57 +02:00
|
|
|
provider = lib.getBin providers.${hostPlatform.parsed.kernel.name};
|
2018-03-28 02:26:10 +02:00
|
|
|
in runCommand cmd {
|
|
|
|
meta.platforms = map (n: { kernel.name = n; }) (pkgs.lib.attrNames providers);
|
|
|
|
} ''
|
2018-05-01 16:37:57 +02:00
|
|
|
mkdir -p $out/bin $out/share/man/man1
|
2018-03-28 02:26:10 +02:00
|
|
|
|
2018-05-01 16:37:57 +02:00
|
|
|
if ! [ -x "${provider}/bin/${cmd}" ]; then
|
2018-03-28 02:26:10 +02:00
|
|
|
echo "Cannot find command ${cmd}"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2018-05-01 16:37:57 +02:00
|
|
|
cp "${provider}/bin/${cmd}" "$out/bin/${cmd}"
|
|
|
|
|
|
|
|
if [ -f "${provider}/share/man/man1/${cmd}.1.gz" ]; then
|
|
|
|
cp "${provider}/share/man/man1/${cmd}.1.gz" "$out/share/man/man1/${cmd}.1.gz"
|
|
|
|
fi
|
2018-03-28 02:26:10 +02:00
|
|
|
'';
|
2018-03-26 06:01:31 +02:00
|
|
|
|
|
|
|
in rec {
|
2018-03-27 05:37:49 +02:00
|
|
|
|
|
|
|
# more is unavailable in darwin
|
|
|
|
# just use less
|
|
|
|
more_compat = runCommand "more" {} ''
|
|
|
|
mkdir -p $out/bin
|
|
|
|
ln -s ${pkgs.less}/bin/less $out/bin/more
|
|
|
|
'';
|
|
|
|
|
|
|
|
# singular binaries
|
2018-03-26 06:01:31 +02:00
|
|
|
arp = singleBinary "arp" {
|
|
|
|
linux = pkgs.nettools;
|
|
|
|
darwin = pkgs.darwin.network_cmds;
|
|
|
|
};
|
2018-04-16 05:22:58 +02:00
|
|
|
col = singleBinary "col" {
|
|
|
|
linux = pkgs.utillinux;
|
|
|
|
darwin = pkgs.darwin.text_cmds;
|
|
|
|
};
|
2018-03-27 05:37:49 +02:00
|
|
|
eject = singleBinary "eject" {
|
|
|
|
linux = pkgs.utillinux;
|
2018-04-11 01:53:09 +02:00
|
|
|
};
|
|
|
|
getconf = singleBinary "getconf" {
|
2018-04-11 19:46:53 +02:00
|
|
|
linux = if hostPlatform.isMusl then pkgs.musl-getconf
|
|
|
|
else lib.getBin stdenv.cc.libc;
|
2018-04-11 04:18:42 +02:00
|
|
|
darwin = pkgs.darwin.system_cmds;
|
2018-04-11 01:53:09 +02:00
|
|
|
};
|
2018-04-11 19:46:53 +02:00
|
|
|
getent = singleBinary "getent" {
|
|
|
|
linux = if hostPlatform.isMusl then pkgs.musl-getent
|
|
|
|
# This may not be right on other platforms, but preserves existing behavior
|
|
|
|
else /* if hostPlatform.libc == "glibc" then */ pkgs.glibc.bin;
|
2018-03-27 05:37:49 +02:00
|
|
|
};
|
2018-03-26 06:01:31 +02:00
|
|
|
getopt = singleBinary "getopt" {
|
|
|
|
linux = pkgs.utillinux;
|
2018-03-27 20:17:10 +02:00
|
|
|
darwin = pkgs.getopt;
|
2018-03-26 06:01:31 +02:00
|
|
|
};
|
2018-04-13 01:36:21 +02:00
|
|
|
fdisk = singleBinary "fdisk" {
|
|
|
|
linux = pkgs.utillinux;
|
|
|
|
darwin = pkgs.darwin.diskdev_cmds;
|
|
|
|
};
|
|
|
|
fsck = singleBinary "fsck" {
|
|
|
|
linux = pkgs.utillinux;
|
|
|
|
darwin = pkgs.darwin.diskdev_cmds;
|
|
|
|
};
|
2018-03-26 06:01:31 +02:00
|
|
|
hexdump = singleBinary "hexdump" {
|
2018-04-11 21:50:27 +02:00
|
|
|
linux = pkgs.utillinux;
|
2018-03-26 06:01:31 +02:00
|
|
|
darwin = pkgs.darwin.shell_cmds;
|
|
|
|
};
|
|
|
|
hostname = singleBinary "hostname" {
|
|
|
|
linux = pkgs.nettools;
|
|
|
|
darwin = pkgs.darwin.shell_cmds;
|
|
|
|
};
|
|
|
|
ifconfig = singleBinary "ifconfig" {
|
|
|
|
linux = pkgs.nettools;
|
|
|
|
darwin = pkgs.darwin.network_cmds;
|
|
|
|
};
|
2018-03-27 05:37:49 +02:00
|
|
|
logger = singleBinary "logger" {
|
|
|
|
linux = pkgs.utillinux;
|
|
|
|
};
|
|
|
|
more = singleBinary "more" {
|
|
|
|
linux = pkgs.utillinux;
|
2018-03-27 20:17:10 +02:00
|
|
|
darwin = more_compat;
|
2018-03-27 05:37:49 +02:00
|
|
|
};
|
|
|
|
mount = singleBinary "mount" {
|
|
|
|
linux = pkgs.utillinux;
|
2018-04-13 00:17:26 +02:00
|
|
|
darwin = pkgs.darwin.diskdev_cmds;
|
2018-03-27 05:37:49 +02:00
|
|
|
};
|
2018-03-26 06:01:31 +02:00
|
|
|
netstat = singleBinary "netstat" {
|
|
|
|
linux = pkgs.nettools;
|
|
|
|
darwin = pkgs.darwin.network_cmds;
|
|
|
|
};
|
|
|
|
ping = singleBinary "ping" {
|
|
|
|
linux = pkgs.iputils;
|
|
|
|
darwin = pkgs.darwin.network_cmds;
|
|
|
|
};
|
|
|
|
ps = singleBinary "ps" {
|
|
|
|
linux = pkgs.procps;
|
2018-03-27 20:02:24 +02:00
|
|
|
darwin = pkgs.darwin.ps;
|
2018-03-26 06:01:31 +02:00
|
|
|
};
|
2018-04-13 01:36:21 +02:00
|
|
|
quota = singleBinary "quota" {
|
2018-04-13 17:41:46 +02:00
|
|
|
linux = pkgs.linuxquota;
|
2018-04-13 01:36:21 +02:00
|
|
|
darwin = pkgs.darwin.diskdev_cmds;
|
|
|
|
};
|
2018-03-26 06:01:31 +02:00
|
|
|
route = singleBinary "route" {
|
|
|
|
linux = pkgs.nettools;
|
|
|
|
darwin = pkgs.darwin.network_cmds;
|
|
|
|
};
|
|
|
|
script = singleBinary "script" {
|
|
|
|
linux = pkgs.utillinux;
|
|
|
|
darwin = pkgs.darwin.shell_cmds;
|
|
|
|
};
|
|
|
|
sysctl = singleBinary "sysctl" {
|
|
|
|
linux = pkgs.procps;
|
|
|
|
darwin = pkgs.darwin.system_cmds;
|
|
|
|
};
|
2018-04-13 01:36:21 +02:00
|
|
|
top = singleBinary "top" {
|
|
|
|
linux = pkgs.procps;
|
|
|
|
darwin = pkgs.darwin.top;
|
|
|
|
};
|
2018-03-27 05:37:49 +02:00
|
|
|
umount = singleBinary "umount" {
|
|
|
|
linux = pkgs.utillinux;
|
2018-04-13 00:17:26 +02:00
|
|
|
darwin = pkgs.darwin.diskdev_cmds;
|
2018-03-27 05:37:49 +02:00
|
|
|
};
|
2018-03-26 06:01:31 +02:00
|
|
|
whereis = singleBinary "whereis" {
|
|
|
|
linux = pkgs.utillinux;
|
|
|
|
darwin = pkgs.darwin.shell_cmds;
|
|
|
|
};
|
2018-03-27 05:37:49 +02:00
|
|
|
wall = singleBinary "wall" {
|
|
|
|
linux = pkgs.utillinux;
|
|
|
|
};
|
2018-03-26 06:01:31 +02:00
|
|
|
write = singleBinary "write" {
|
|
|
|
linux = pkgs.utillinux;
|
|
|
|
darwin = pkgs.darwin.basic_cmds;
|
|
|
|
};
|
|
|
|
|
|
|
|
# Compatibility derivations
|
2018-03-27 05:37:49 +02:00
|
|
|
# Provided for old usage of these commands.
|
2018-03-26 06:01:31 +02:00
|
|
|
|
|
|
|
procps = buildEnv {
|
|
|
|
name = "procps-compat";
|
2018-04-13 01:36:21 +02:00
|
|
|
paths = [ ps sysctl top ];
|
2018-03-26 06:01:31 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
utillinux = buildEnv {
|
|
|
|
name = "utillinux-compat";
|
2018-04-13 01:36:21 +02:00
|
|
|
paths = [ fsck fdisk getopt hexdump mount
|
2018-04-16 05:22:58 +02:00
|
|
|
script umount whereis write col ];
|
2018-03-26 06:01:31 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
nettools = buildEnv {
|
|
|
|
name = "nettools-compat";
|
2018-04-13 01:36:21 +02:00
|
|
|
paths = [ arp hostname ifconfig netstat route ];
|
2018-03-26 06:01:31 +02:00
|
|
|
};
|
|
|
|
}
|