2018-08-20 19:43:41 +01:00
|
|
|
{ pkgs, buildEnv, runCommand, lib, stdenv }:
|
2018-03-26 05:01:31 +01:00
|
|
|
|
2018-03-27 04:37:49 +01: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-07-08 21:09:47 +01:00
|
|
|
with lib;
|
|
|
|
|
2018-03-26 05:01:31 +01:00
|
|
|
let
|
2018-05-24 05:38:35 +01:00
|
|
|
version = "1003.1-2008";
|
|
|
|
|
2018-03-28 01:26:10 +01:00
|
|
|
singleBinary = cmd: providers: let
|
2018-08-20 19:43:41 +01:00
|
|
|
provider = providers.${stdenv.hostPlatform.parsed.kernel.name};
|
2018-07-08 21:09:47 +01:00
|
|
|
bin = "${getBin provider}/bin/${cmd}";
|
|
|
|
manpage = "${getOutput "man" provider}/share/man/man1/${cmd}.1.gz";
|
2018-05-24 05:38:35 +01:00
|
|
|
in runCommand "${cmd}-${version}" {
|
2018-07-08 21:09:47 +01:00
|
|
|
meta.platforms = map (n: { kernel.name = n; }) (attrNames providers);
|
|
|
|
passthru = { inherit provider; };
|
2018-07-09 00:23:10 +01:00
|
|
|
preferLocalBuild = true;
|
2018-03-28 01:26:10 +01:00
|
|
|
} ''
|
2018-07-09 00:23:10 +01:00
|
|
|
if ! [ -x ${bin} ]; then
|
|
|
|
echo Cannot find command ${cmd}
|
2018-03-28 01:26:10 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2018-07-09 00:23:10 +01:00
|
|
|
mkdir -p $out/bin
|
|
|
|
ln -s ${bin} $out/bin/${cmd}
|
2018-07-04 20:24:58 +01:00
|
|
|
|
2018-07-09 00:23:10 +01:00
|
|
|
if [ -f ${manpage} ]; then
|
|
|
|
mkdir -p $out/share/man/man1
|
|
|
|
ln -s ${manpage} $out/share/man/man1/${cmd}.1.gz
|
2018-07-04 20:24:58 +01:00
|
|
|
fi
|
2018-03-28 01:26:10 +01:00
|
|
|
'';
|
2018-03-26 05:01:31 +01:00
|
|
|
|
2018-03-27 04:37:49 +01:00
|
|
|
# more is unavailable in darwin
|
2018-07-08 21:09:47 +01:00
|
|
|
# so we just use less
|
2018-05-24 05:38:35 +01:00
|
|
|
more_compat = runCommand "more-${version}" {} ''
|
2018-03-27 04:37:49 +01:00
|
|
|
mkdir -p $out/bin
|
|
|
|
ln -s ${pkgs.less}/bin/less $out/bin/more
|
|
|
|
'';
|
|
|
|
|
2018-07-08 21:09:47 +01:00
|
|
|
bins = mapAttrs singleBinary {
|
2018-05-07 18:44:56 +01:00
|
|
|
# singular binaries
|
|
|
|
arp = {
|
|
|
|
linux = pkgs.nettools;
|
|
|
|
darwin = pkgs.darwin.network_cmds;
|
|
|
|
};
|
|
|
|
col = {
|
|
|
|
linux = pkgs.utillinux;
|
|
|
|
darwin = pkgs.darwin.text_cmds;
|
|
|
|
};
|
|
|
|
eject = {
|
|
|
|
linux = pkgs.utillinux;
|
|
|
|
};
|
2018-05-08 21:37:10 +01:00
|
|
|
getconf = {
|
2018-08-20 19:43:41 +01:00
|
|
|
linux = if stdenv.hostPlatform.libc == "glibc" then pkgs.glibc
|
2018-05-31 17:33:36 +01:00
|
|
|
else pkgs.netbsd.getconf;
|
2018-05-08 15:36:00 +01:00
|
|
|
darwin = pkgs.darwin.system_cmds;
|
|
|
|
};
|
|
|
|
getent = {
|
2018-08-20 19:43:41 +01:00
|
|
|
linux = if stdenv.hostPlatform.libc == "glibc" then pkgs.glibc
|
2018-05-31 17:33:36 +01:00
|
|
|
else pkgs.netbsd.getent;
|
|
|
|
darwin = pkgs.netbsd.getent;
|
2018-05-08 15:36:00 +01:00
|
|
|
};
|
2018-05-07 18:44:56 +01:00
|
|
|
getopt = {
|
|
|
|
linux = pkgs.utillinux;
|
|
|
|
darwin = pkgs.getopt;
|
|
|
|
};
|
|
|
|
fdisk = {
|
|
|
|
linux = pkgs.utillinux;
|
|
|
|
darwin = pkgs.darwin.diskdev_cmds;
|
|
|
|
};
|
|
|
|
fsck = {
|
|
|
|
linux = pkgs.utillinux;
|
|
|
|
darwin = pkgs.darwin.diskdev_cmds;
|
|
|
|
};
|
|
|
|
hexdump = {
|
|
|
|
linux = pkgs.utillinux;
|
|
|
|
darwin = pkgs.darwin.shell_cmds;
|
|
|
|
};
|
|
|
|
hostname = {
|
|
|
|
linux = pkgs.nettools;
|
|
|
|
darwin = pkgs.darwin.shell_cmds;
|
|
|
|
};
|
|
|
|
ifconfig = {
|
|
|
|
linux = pkgs.nettools;
|
|
|
|
darwin = pkgs.darwin.network_cmds;
|
|
|
|
};
|
2018-06-27 21:45:52 +01:00
|
|
|
killall = {
|
|
|
|
linux = pkgs.psmisc;
|
|
|
|
darwin = pkgs.darwin.shell_cmds;
|
|
|
|
};
|
2018-06-11 16:19:31 +01:00
|
|
|
locale = {
|
|
|
|
linux = pkgs.glibc;
|
2018-06-11 19:46:46 +01:00
|
|
|
darwin = pkgs.netbsd.locale;
|
2018-06-11 16:19:31 +01:00
|
|
|
};
|
2018-05-07 18:44:56 +01:00
|
|
|
logger = {
|
|
|
|
linux = pkgs.utillinux;
|
|
|
|
};
|
|
|
|
more = {
|
|
|
|
linux = pkgs.utillinux;
|
|
|
|
darwin = more_compat;
|
|
|
|
};
|
|
|
|
mount = {
|
|
|
|
linux = pkgs.utillinux;
|
|
|
|
darwin = pkgs.darwin.diskdev_cmds;
|
|
|
|
};
|
|
|
|
netstat = {
|
|
|
|
linux = pkgs.nettools;
|
|
|
|
darwin = pkgs.darwin.network_cmds;
|
|
|
|
};
|
|
|
|
ping = {
|
|
|
|
linux = pkgs.iputils;
|
|
|
|
darwin = pkgs.darwin.network_cmds;
|
|
|
|
};
|
|
|
|
ps = {
|
|
|
|
linux = pkgs.procps;
|
|
|
|
darwin = pkgs.darwin.ps;
|
|
|
|
};
|
|
|
|
quota = {
|
|
|
|
linux = pkgs.linuxquota;
|
|
|
|
darwin = pkgs.darwin.diskdev_cmds;
|
|
|
|
};
|
|
|
|
route = {
|
|
|
|
linux = pkgs.nettools;
|
|
|
|
darwin = pkgs.darwin.network_cmds;
|
|
|
|
};
|
|
|
|
script = {
|
|
|
|
linux = pkgs.utillinux;
|
|
|
|
darwin = pkgs.darwin.shell_cmds;
|
|
|
|
};
|
|
|
|
sysctl = {
|
|
|
|
linux = pkgs.procps;
|
|
|
|
darwin = pkgs.darwin.system_cmds;
|
|
|
|
};
|
|
|
|
top = {
|
|
|
|
linux = pkgs.procps;
|
|
|
|
darwin = pkgs.darwin.top;
|
|
|
|
};
|
|
|
|
umount = {
|
|
|
|
linux = pkgs.utillinux;
|
|
|
|
darwin = pkgs.darwin.diskdev_cmds;
|
|
|
|
};
|
|
|
|
whereis = {
|
|
|
|
linux = pkgs.utillinux;
|
|
|
|
darwin = pkgs.darwin.shell_cmds;
|
|
|
|
};
|
|
|
|
wall = {
|
|
|
|
linux = pkgs.utillinux;
|
|
|
|
};
|
2018-07-08 21:09:25 +01:00
|
|
|
watch = {
|
|
|
|
linux = pkgs.procps;
|
|
|
|
|
|
|
|
# watch is the only command from procps that builds currently on
|
|
|
|
# Darwin. Unfortunately no other implementations exist currently!
|
|
|
|
darwin = pkgs.callPackage ../os-specific/linux/procps-ng {};
|
|
|
|
};
|
2018-05-07 18:44:56 +01:00
|
|
|
write = {
|
|
|
|
linux = pkgs.utillinux;
|
|
|
|
darwin = pkgs.darwin.basic_cmds;
|
|
|
|
};
|
2018-07-04 20:24:58 +01:00
|
|
|
xxd = {
|
|
|
|
linux = pkgs.vim;
|
|
|
|
darwin = pkgs.vim;
|
|
|
|
};
|
2018-03-27 04:37:49 +01:00
|
|
|
};
|
2018-05-07 18:44:56 +01:00
|
|
|
|
2018-07-08 21:09:47 +01:00
|
|
|
makeCompat = pname: paths:
|
|
|
|
buildEnv {
|
|
|
|
name = "${pname}-${version}";
|
|
|
|
inherit paths;
|
|
|
|
};
|
2018-03-26 05:01:31 +01:00
|
|
|
|
|
|
|
# Compatibility derivations
|
2018-03-27 04:37:49 +01:00
|
|
|
# Provided for old usage of these commands.
|
2018-05-07 18:44:56 +01:00
|
|
|
compat = with bins; lib.mapAttrs makeCompat {
|
2018-07-08 21:09:25 +01:00
|
|
|
procps = [ ps sysctl top watch ];
|
2018-05-07 18:44:56 +01:00
|
|
|
utillinux = [ fsck fdisk getopt hexdump mount
|
|
|
|
script umount whereis write col ];
|
|
|
|
nettools = [ arp hostname ifconfig netstat route ];
|
2018-03-26 05:01:31 +01:00
|
|
|
};
|
2018-05-07 18:44:56 +01:00
|
|
|
in bins // compat
|