2018-03-26 04:01:31 +00:00
|
|
|
{ pkgs, buildEnv, runCommand, hostPlatform }:
|
|
|
|
|
2018-03-27 03:37:49 +00: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 04:01:31 +00:00
|
|
|
let
|
|
|
|
|
|
|
|
singleBinary = cmd: providers:
|
|
|
|
if builtins.hasAttr hostPlatform.parsed.kernel.name providers then
|
|
|
|
runCommand cmd {} ''
|
|
|
|
mkdir -p $out/bin
|
|
|
|
|
|
|
|
if ! [ -x "${providers.${hostPlatform.parsed.kernel.name}}/bin/${cmd}" ]; then
|
|
|
|
echo "Cannot find command ${cmd}"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
ln -s ${providers.${hostPlatform.parsed.kernel.name}}/bin/${cmd} $out/bin/${cmd}
|
|
|
|
''
|
|
|
|
else throw "${hostPlatform.parsed.kernel.name} does not have ${cmd}";
|
|
|
|
|
|
|
|
in rec {
|
2018-03-27 03:37:49 +00: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 04:01:31 +00:00
|
|
|
arp = singleBinary "arp" {
|
|
|
|
linux = pkgs.nettools;
|
|
|
|
darwin = pkgs.darwin.network_cmds;
|
|
|
|
};
|
2018-03-27 03:37:49 +00:00
|
|
|
eject = singleBinary "eject" {
|
|
|
|
linux = pkgs.utillinux;
|
|
|
|
};
|
2018-03-26 04:01:31 +00:00
|
|
|
getopt = singleBinary "getopt" {
|
|
|
|
linux = pkgs.utillinux;
|
|
|
|
darwin = pkgs.darwin.shell_cmds;
|
|
|
|
};
|
|
|
|
hexdump = singleBinary "hexdump" {
|
|
|
|
linux = pkgs.procps;
|
|
|
|
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 03:37:49 +00:00
|
|
|
logger = singleBinary "logger" {
|
|
|
|
linux = pkgs.utillinux;
|
|
|
|
};
|
|
|
|
modprobe = singleBinary "modprobe" {
|
|
|
|
linux = pkgs.utillinux;
|
|
|
|
};
|
|
|
|
more = singleBinary "more" {
|
|
|
|
linux = pkgs.utillinux;
|
|
|
|
darwin = pkgs.more_compat;
|
|
|
|
};
|
|
|
|
mount = singleBinary "mount" {
|
|
|
|
linux = pkgs.utillinux;
|
|
|
|
};
|
2018-03-26 04:01:31 +00: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 18:02:24 +00:00
|
|
|
darwin = pkgs.darwin.ps;
|
2018-03-26 04:01:31 +00: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-03-27 03:37:49 +00:00
|
|
|
umount = singleBinary "umount" {
|
|
|
|
linux = pkgs.utillinux;
|
|
|
|
};
|
2018-03-26 04:01:31 +00:00
|
|
|
whereis = singleBinary "whereis" {
|
|
|
|
linux = pkgs.utillinux;
|
|
|
|
darwin = pkgs.darwin.shell_cmds;
|
|
|
|
};
|
2018-03-27 03:37:49 +00:00
|
|
|
wall = singleBinary "wall" {
|
|
|
|
linux = pkgs.utillinux;
|
|
|
|
};
|
2018-03-26 04:01:31 +00:00
|
|
|
write = singleBinary "write" {
|
|
|
|
linux = pkgs.utillinux;
|
|
|
|
darwin = pkgs.darwin.basic_cmds;
|
|
|
|
};
|
|
|
|
|
|
|
|
# Compatibility derivations
|
2018-03-27 03:37:49 +00:00
|
|
|
# Provided for old usage of these commands.
|
2018-03-26 04:01:31 +00:00
|
|
|
|
|
|
|
procps = buildEnv {
|
|
|
|
name = "procps-compat";
|
|
|
|
paths = [ sysctl ps ];
|
|
|
|
};
|
|
|
|
|
|
|
|
utillinux = buildEnv {
|
|
|
|
name = "utillinux-compat";
|
|
|
|
paths = [ getopt hexdump script whereis write ];
|
|
|
|
};
|
|
|
|
|
|
|
|
nettools = buildEnv {
|
|
|
|
name = "nettools-compat";
|
|
|
|
paths = [ arp hostname netstat route ];
|
|
|
|
};
|
|
|
|
}
|