2024-06-30 08:12:46 +00:00
|
|
|
{
|
|
|
|
pkgs,
|
|
|
|
buildEnv,
|
|
|
|
runCommand,
|
|
|
|
lib,
|
|
|
|
stdenv,
|
|
|
|
path,
|
|
|
|
}:
|
2024-05-02 00:46:19 +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.
|
|
|
|
|
|
|
|
let
|
|
|
|
inherit (lib)
|
|
|
|
getBin
|
|
|
|
getOutput
|
|
|
|
mapAttrs
|
|
|
|
platforms
|
|
|
|
;
|
|
|
|
|
|
|
|
version = "1003.1-2008";
|
|
|
|
|
2024-06-30 08:12:46 +00:00
|
|
|
singleBinary =
|
|
|
|
cmd: providers:
|
|
|
|
let
|
2024-05-02 00:46:19 +00:00
|
|
|
provider = providers.${stdenv.hostPlatform.parsed.kernel.name} or providers.linux;
|
|
|
|
bin = "${getBin provider}/bin/${cmd}";
|
|
|
|
manpage = "${getOutput "man" provider}/share/man/man1/${cmd}.1.gz";
|
2024-06-30 08:12:46 +00:00
|
|
|
in
|
|
|
|
runCommand "${cmd}-${provider.name}"
|
|
|
|
{
|
|
|
|
meta = {
|
|
|
|
mainProgram = cmd;
|
|
|
|
priority = 10;
|
|
|
|
platforms = platforms.${stdenv.hostPlatform.parsed.kernel.name} or platforms.all;
|
|
|
|
};
|
|
|
|
passthru = {
|
|
|
|
inherit provider;
|
|
|
|
};
|
|
|
|
preferLocalBuild = true;
|
|
|
|
}
|
|
|
|
''
|
|
|
|
if ! [ -x ${bin} ]; then
|
|
|
|
echo Cannot find command ${cmd}
|
|
|
|
exit 1
|
|
|
|
fi
|
2024-05-02 00:46:19 +00:00
|
|
|
|
2024-06-30 08:12:46 +00:00
|
|
|
mkdir -p $out/bin
|
|
|
|
ln -s ${bin} $out/bin/${cmd}
|
2024-05-02 00:46:19 +00:00
|
|
|
|
2024-06-30 08:12:46 +00:00
|
|
|
if [ -f ${manpage} ]; then
|
|
|
|
mkdir -p $out/share/man/man1
|
|
|
|
ln -s ${manpage} $out/share/man/man1/${cmd}.1.gz
|
|
|
|
fi
|
|
|
|
'';
|
2024-05-02 00:46:19 +00:00
|
|
|
|
|
|
|
# more is unavailable in darwin
|
|
|
|
# so we just use less
|
2024-06-30 08:12:46 +00:00
|
|
|
more_compat = runCommand "more-${pkgs.less.name}" { } ''
|
2024-05-02 00:46:19 +00:00
|
|
|
mkdir -p $out/bin
|
|
|
|
ln -s ${pkgs.less}/bin/less $out/bin/more
|
|
|
|
'';
|
|
|
|
|
|
|
|
bins = mapAttrs singleBinary {
|
|
|
|
# singular binaries
|
|
|
|
arp = {
|
|
|
|
linux = pkgs.nettools;
|
|
|
|
darwin = pkgs.darwin.network_cmds;
|
|
|
|
};
|
|
|
|
col = {
|
|
|
|
linux = pkgs.util-linux;
|
|
|
|
darwin = pkgs.darwin.text_cmds;
|
|
|
|
};
|
|
|
|
column = {
|
|
|
|
linux = pkgs.util-linux;
|
|
|
|
darwin = pkgs.darwin.text_cmds;
|
|
|
|
};
|
|
|
|
eject = {
|
|
|
|
linux = pkgs.util-linux;
|
|
|
|
};
|
|
|
|
getconf = {
|
2024-06-30 08:12:46 +00:00
|
|
|
linux = if stdenv.hostPlatform.libc == "glibc" then pkgs.stdenv.cc.libc else pkgs.netbsd.getconf;
|
2024-05-02 00:46:19 +00:00
|
|
|
darwin = pkgs.darwin.system_cmds;
|
|
|
|
};
|
|
|
|
getent = {
|
2024-06-30 08:12:46 +00:00
|
|
|
linux =
|
|
|
|
if stdenv.hostPlatform.libc == "glibc" then pkgs.stdenv.cc.libc.getent else pkgs.netbsd.getent;
|
2024-05-02 00:46:19 +00:00
|
|
|
darwin = pkgs.netbsd.getent;
|
|
|
|
};
|
|
|
|
getopt = {
|
|
|
|
linux = pkgs.util-linux;
|
|
|
|
darwin = pkgs.getopt;
|
|
|
|
};
|
|
|
|
fdisk = {
|
|
|
|
linux = pkgs.util-linux;
|
|
|
|
darwin = pkgs.darwin.diskdev_cmds;
|
|
|
|
};
|
|
|
|
fsck = {
|
|
|
|
linux = pkgs.util-linux;
|
|
|
|
darwin = pkgs.darwin.diskdev_cmds;
|
|
|
|
};
|
|
|
|
hexdump = {
|
|
|
|
linux = pkgs.util-linux;
|
|
|
|
darwin = pkgs.darwin.shell_cmds;
|
|
|
|
};
|
|
|
|
hostname = {
|
|
|
|
linux = pkgs.nettools;
|
|
|
|
darwin = pkgs.darwin.shell_cmds;
|
|
|
|
};
|
|
|
|
ifconfig = {
|
|
|
|
linux = pkgs.nettools;
|
|
|
|
darwin = pkgs.darwin.network_cmds;
|
|
|
|
};
|
|
|
|
killall = {
|
|
|
|
linux = pkgs.psmisc;
|
|
|
|
darwin = pkgs.darwin.shell_cmds;
|
|
|
|
};
|
|
|
|
locale = {
|
|
|
|
linux = pkgs.glibc;
|
|
|
|
darwin = pkgs.darwin.adv_cmds;
|
|
|
|
};
|
|
|
|
logger = {
|
|
|
|
linux = pkgs.util-linux;
|
|
|
|
};
|
|
|
|
more = {
|
|
|
|
linux = pkgs.util-linux;
|
|
|
|
darwin = more_compat;
|
|
|
|
};
|
|
|
|
mount = {
|
|
|
|
linux = pkgs.util-linux;
|
|
|
|
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.util-linux;
|
|
|
|
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.util-linux;
|
|
|
|
darwin = pkgs.darwin.diskdev_cmds;
|
|
|
|
};
|
|
|
|
whereis = {
|
|
|
|
linux = pkgs.util-linux;
|
|
|
|
darwin = pkgs.darwin.shell_cmds;
|
|
|
|
};
|
|
|
|
wall = {
|
|
|
|
linux = pkgs.util-linux;
|
|
|
|
};
|
|
|
|
watch = {
|
|
|
|
linux = pkgs.procps;
|
|
|
|
|
|
|
|
# watch is the only command from procps that builds currently on
|
|
|
|
# Darwin. Unfortunately no other implementations exist currently!
|
2024-06-30 08:12:46 +00:00
|
|
|
darwin = pkgs.callPackage (path + "/pkgs/by-name/pr/procps-ng") { };
|
2024-05-02 00:46:19 +00:00
|
|
|
};
|
|
|
|
write = {
|
|
|
|
linux = pkgs.util-linux;
|
|
|
|
darwin = pkgs.darwin.basic_cmds;
|
|
|
|
};
|
|
|
|
xxd = {
|
|
|
|
linux = pkgs.vim.xxd;
|
|
|
|
darwin = pkgs.vim.xxd;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-06-30 08:12:46 +00:00
|
|
|
makeCompat =
|
|
|
|
pname: paths:
|
2024-05-02 00:46:19 +00:00
|
|
|
buildEnv {
|
|
|
|
name = "${pname}-${version}";
|
|
|
|
inherit paths;
|
|
|
|
};
|
|
|
|
|
|
|
|
# Compatibility derivations
|
|
|
|
# Provided for old usage of these commands.
|
2024-06-30 08:12:46 +00:00
|
|
|
compat =
|
|
|
|
with bins;
|
|
|
|
mapAttrs makeCompat {
|
|
|
|
procps = [
|
|
|
|
ps
|
|
|
|
sysctl
|
|
|
|
top
|
|
|
|
watch
|
|
|
|
];
|
|
|
|
util-linux = [
|
|
|
|
fsck
|
|
|
|
fdisk
|
|
|
|
getopt
|
|
|
|
hexdump
|
|
|
|
mount
|
|
|
|
script
|
|
|
|
umount
|
|
|
|
whereis
|
|
|
|
write
|
|
|
|
col
|
|
|
|
column
|
|
|
|
];
|
|
|
|
nettools = [
|
|
|
|
arp
|
|
|
|
hostname
|
|
|
|
ifconfig
|
|
|
|
netstat
|
|
|
|
route
|
|
|
|
];
|
|
|
|
};
|
|
|
|
in
|
|
|
|
bins // compat
|