2018-08-20 18:43:41 +00:00
|
|
|
{ pkgs, buildEnv, runCommand, lib, stdenv }:
|
2018-03-26 04:01:31 +00:00
|
|
|
|
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
|
2024-03-06 01:59:07 +00:00
|
|
|
inherit (lib)
|
|
|
|
getBin
|
|
|
|
getOutput
|
|
|
|
mapAttrs
|
|
|
|
platforms
|
|
|
|
;
|
|
|
|
|
2018-05-24 04:38:35 +00:00
|
|
|
version = "1003.1-2008";
|
|
|
|
|
2018-03-28 00:26:10 +00:00
|
|
|
singleBinary = cmd: providers: let
|
2019-06-05 02:45:11 +00:00
|
|
|
provider = providers.${stdenv.hostPlatform.parsed.kernel.name} or providers.linux;
|
2018-07-08 20:09:47 +00:00
|
|
|
bin = "${getBin provider}/bin/${cmd}";
|
|
|
|
manpage = "${getOutput "man" provider}/share/man/man1/${cmd}.1.gz";
|
2021-01-16 22:10:04 +00:00
|
|
|
in runCommand "${cmd}-${provider.name}" {
|
2019-02-19 02:09:47 +00:00
|
|
|
meta = {
|
2022-03-27 03:55:17 +00:00
|
|
|
mainProgram = cmd;
|
2019-02-19 02:09:47 +00:00
|
|
|
priority = 10;
|
2024-03-06 01:59:07 +00:00
|
|
|
platforms = platforms.${stdenv.hostPlatform.parsed.kernel.name} or platforms.all;
|
2019-02-19 02:09:47 +00:00
|
|
|
};
|
2018-07-08 20:09:47 +00:00
|
|
|
passthru = { inherit provider; };
|
2018-07-08 23:23:10 +00:00
|
|
|
preferLocalBuild = true;
|
2018-03-28 00:26:10 +00:00
|
|
|
} ''
|
2018-07-08 23:23:10 +00:00
|
|
|
if ! [ -x ${bin} ]; then
|
|
|
|
echo Cannot find command ${cmd}
|
2018-03-28 00:26:10 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2018-07-08 23:23:10 +00:00
|
|
|
mkdir -p $out/bin
|
|
|
|
ln -s ${bin} $out/bin/${cmd}
|
2018-07-04 19:24:58 +00:00
|
|
|
|
2018-07-08 23:23:10 +00:00
|
|
|
if [ -f ${manpage} ]; then
|
|
|
|
mkdir -p $out/share/man/man1
|
|
|
|
ln -s ${manpage} $out/share/man/man1/${cmd}.1.gz
|
2018-07-04 19:24:58 +00:00
|
|
|
fi
|
2018-03-28 00:26:10 +00:00
|
|
|
'';
|
2018-03-26 04:01:31 +00:00
|
|
|
|
2018-03-27 03:37:49 +00:00
|
|
|
# more is unavailable in darwin
|
2018-07-08 20:09:47 +00:00
|
|
|
# so we just use less
|
2021-01-16 22:10:04 +00:00
|
|
|
more_compat = runCommand "more-${pkgs.less.name}" {} ''
|
2018-03-27 03:37:49 +00:00
|
|
|
mkdir -p $out/bin
|
|
|
|
ln -s ${pkgs.less}/bin/less $out/bin/more
|
|
|
|
'';
|
|
|
|
|
2018-07-08 20:09:47 +00:00
|
|
|
bins = mapAttrs singleBinary {
|
2018-05-07 17:44:56 +00:00
|
|
|
# singular binaries
|
|
|
|
arp = {
|
|
|
|
linux = pkgs.nettools;
|
|
|
|
darwin = pkgs.darwin.network_cmds;
|
|
|
|
};
|
|
|
|
col = {
|
2020-11-24 15:29:28 +00:00
|
|
|
linux = pkgs.util-linux;
|
2018-05-07 17:44:56 +00:00
|
|
|
darwin = pkgs.darwin.text_cmds;
|
|
|
|
};
|
2019-01-23 21:35:11 +00:00
|
|
|
column = {
|
2020-11-24 15:29:28 +00:00
|
|
|
linux = pkgs.util-linux;
|
2023-05-13 16:30:12 +00:00
|
|
|
darwin = pkgs.darwin.text_cmds;
|
2019-01-23 21:35:11 +00:00
|
|
|
};
|
2018-05-07 17:44:56 +00:00
|
|
|
eject = {
|
2020-11-24 15:29:28 +00:00
|
|
|
linux = pkgs.util-linux;
|
2018-05-07 17:44:56 +00:00
|
|
|
};
|
2018-05-08 20:37:10 +00:00
|
|
|
getconf = {
|
2020-02-28 17:04:10 +00:00
|
|
|
linux = if stdenv.hostPlatform.libc == "glibc" then pkgs.stdenv.cc.libc
|
2018-05-31 16:33:36 +00:00
|
|
|
else pkgs.netbsd.getconf;
|
2018-05-08 14:36:00 +00:00
|
|
|
darwin = pkgs.darwin.system_cmds;
|
|
|
|
};
|
|
|
|
getent = {
|
2023-05-22 17:53:52 +00:00
|
|
|
linux = if stdenv.hostPlatform.libc == "glibc" then pkgs.stdenv.cc.libc.getent
|
2018-05-31 16:33:36 +00:00
|
|
|
else pkgs.netbsd.getent;
|
|
|
|
darwin = pkgs.netbsd.getent;
|
2018-05-08 14:36:00 +00:00
|
|
|
};
|
2018-05-07 17:44:56 +00:00
|
|
|
getopt = {
|
2020-11-24 15:29:28 +00:00
|
|
|
linux = pkgs.util-linux;
|
2018-05-07 17:44:56 +00:00
|
|
|
darwin = pkgs.getopt;
|
|
|
|
};
|
|
|
|
fdisk = {
|
2020-11-24 15:29:28 +00:00
|
|
|
linux = pkgs.util-linux;
|
2018-05-07 17:44:56 +00:00
|
|
|
darwin = pkgs.darwin.diskdev_cmds;
|
|
|
|
};
|
|
|
|
fsck = {
|
2020-11-24 15:29:28 +00:00
|
|
|
linux = pkgs.util-linux;
|
2018-05-07 17:44:56 +00:00
|
|
|
darwin = pkgs.darwin.diskdev_cmds;
|
|
|
|
};
|
|
|
|
hexdump = {
|
2020-11-24 15:29:28 +00:00
|
|
|
linux = pkgs.util-linux;
|
2018-05-07 17:44:56 +00:00
|
|
|
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 20:45:52 +00:00
|
|
|
killall = {
|
|
|
|
linux = pkgs.psmisc;
|
|
|
|
darwin = pkgs.darwin.shell_cmds;
|
|
|
|
};
|
2018-06-11 15:19:31 +00:00
|
|
|
locale = {
|
|
|
|
linux = pkgs.glibc;
|
2023-05-13 16:30:12 +00:00
|
|
|
darwin = pkgs.darwin.adv_cmds;
|
2018-06-11 15:19:31 +00:00
|
|
|
};
|
2018-05-07 17:44:56 +00:00
|
|
|
logger = {
|
2020-11-24 15:29:28 +00:00
|
|
|
linux = pkgs.util-linux;
|
2018-05-07 17:44:56 +00:00
|
|
|
};
|
|
|
|
more = {
|
2020-11-24 15:29:28 +00:00
|
|
|
linux = pkgs.util-linux;
|
2018-05-07 17:44:56 +00:00
|
|
|
darwin = more_compat;
|
|
|
|
};
|
|
|
|
mount = {
|
2020-11-24 15:29:28 +00:00
|
|
|
linux = pkgs.util-linux;
|
2018-05-07 17:44:56 +00:00
|
|
|
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 = {
|
2020-11-24 15:29:28 +00:00
|
|
|
linux = pkgs.util-linux;
|
2018-05-07 17:44:56 +00:00
|
|
|
darwin = pkgs.darwin.shell_cmds;
|
|
|
|
};
|
|
|
|
sysctl = {
|
|
|
|
linux = pkgs.procps;
|
|
|
|
darwin = pkgs.darwin.system_cmds;
|
|
|
|
};
|
|
|
|
top = {
|
|
|
|
linux = pkgs.procps;
|
|
|
|
darwin = pkgs.darwin.top;
|
|
|
|
};
|
|
|
|
umount = {
|
2020-11-24 15:29:28 +00:00
|
|
|
linux = pkgs.util-linux;
|
2018-05-07 17:44:56 +00:00
|
|
|
darwin = pkgs.darwin.diskdev_cmds;
|
|
|
|
};
|
|
|
|
whereis = {
|
2020-11-24 15:29:28 +00:00
|
|
|
linux = pkgs.util-linux;
|
2018-05-07 17:44:56 +00:00
|
|
|
darwin = pkgs.darwin.shell_cmds;
|
|
|
|
};
|
|
|
|
wall = {
|
2020-11-24 15:29:28 +00:00
|
|
|
linux = pkgs.util-linux;
|
2018-05-07 17:44:56 +00:00
|
|
|
};
|
2018-07-08 20:09:25 +00: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 17:44:56 +00:00
|
|
|
write = {
|
2020-11-24 15:29:28 +00:00
|
|
|
linux = pkgs.util-linux;
|
2018-05-07 17:44:56 +00:00
|
|
|
darwin = pkgs.darwin.basic_cmds;
|
|
|
|
};
|
2018-07-04 19:24:58 +00:00
|
|
|
xxd = {
|
2023-09-12 14:32:10 +00:00
|
|
|
linux = pkgs.vim.xxd;
|
|
|
|
darwin = pkgs.vim.xxd;
|
2018-07-04 19:24:58 +00:00
|
|
|
};
|
2018-03-27 03:37:49 +00:00
|
|
|
};
|
2018-05-07 17:44:56 +00:00
|
|
|
|
2018-07-08 20:09:47 +00:00
|
|
|
makeCompat = pname: paths:
|
|
|
|
buildEnv {
|
|
|
|
name = "${pname}-${version}";
|
|
|
|
inherit paths;
|
|
|
|
};
|
2018-03-26 04:01:31 +00:00
|
|
|
|
|
|
|
# Compatibility derivations
|
2018-03-27 03:37:49 +00:00
|
|
|
# Provided for old usage of these commands.
|
2024-03-06 01:59:07 +00:00
|
|
|
compat = with bins; mapAttrs makeCompat {
|
2018-07-08 20:09:25 +00:00
|
|
|
procps = [ ps sysctl top watch ];
|
2020-11-24 15:29:28 +00:00
|
|
|
util-linux = [ fsck fdisk getopt hexdump mount
|
2019-01-23 21:35:11 +00:00
|
|
|
script umount whereis write col column ];
|
2018-05-07 17:44:56 +00:00
|
|
|
nettools = [ arp hostname ifconfig netstat route ];
|
2018-03-26 04:01:31 +00:00
|
|
|
};
|
2018-05-07 17:44:56 +00:00
|
|
|
in bins // compat
|