nixpkgs/pkgs/top-level/unixtools.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

248 lines
6.9 KiB
Nix
Raw Normal View History

{ pkgs, buildEnv, runCommand, lib, stdenv, freebsd, binlore }:
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.
let
inherit (lib)
getBin
getOutput
mapAttrs
platforms
;
version = "1003.1-2008";
2018-03-28 00:26:10 +00:00
singleBinary = cmd: providers: let
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";
in runCommand "${cmd}-${provider.name}" {
2019-02-19 02:09:47 +00:00
meta = {
mainProgram = cmd;
2019-02-19 02:09:47 +00:00
priority = 10;
platforms = platforms.${stdenv.hostPlatform.parsed.kernel.name} or platforms.all;
2019-02-19 02:09:47 +00:00
};
passthru = { inherit provider; } // lib.optionalAttrs (builtins.hasAttr "binlore" providers) {
binlore.out = (binlore.synthesize (getBin bins.${cmd}) providers.binlore);
};
preferLocalBuild = true;
2018-03-28 00:26:10 +00:00
} ''
if ! [ -x ${bin} ]; then
echo Cannot find command ${cmd}
2018-03-28 00:26:10 +00:00
exit 1
fi
mkdir -p $out/bin
ln -s ${bin} $out/bin/${cmd}
if [ -f ${manpage} ]; then
mkdir -p $out/share/man/man1
ln -s ${manpage} $out/share/man/man1/${cmd}.1.gz
fi
2018-03-28 00:26:10 +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
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 {
# singular binaries
arp = {
linux = pkgs.nettools;
darwin = pkgs.darwin.network_cmds;
2024-05-17 23:39:13 +00:00
freebsd = pkgs.freebsd.arp;
};
col = {
2020-11-24 15:29:28 +00:00
linux = pkgs.util-linux;
darwin = pkgs.darwin.text_cmds;
};
column = {
2020-11-24 15:29:28 +00:00
linux = pkgs.util-linux;
darwin = pkgs.darwin.text_cmds;
};
eject = {
2020-11-24 15:29:28 +00:00
linux = pkgs.util-linux;
};
getconf = {
linux = if stdenv.hostPlatform.libc == "glibc" then pkgs.stdenv.cc.libc
2018-05-31 16:33:36 +00:00
else pkgs.netbsd.getconf;
darwin = pkgs.darwin.system_cmds;
# I don't see any obvious arg exec in the doc/manpage
binlore = ''
execer cannot bin/getconf
'';
};
getent = {
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;
2024-05-17 23:39:13 +00:00
freebsd = pkgs.freebsd.getent;
};
getopt = {
2020-11-24 15:29:28 +00:00
linux = pkgs.util-linux;
darwin = pkgs.getopt;
};
fdisk = {
2020-11-24 15:29:28 +00:00
linux = pkgs.util-linux;
darwin = pkgs.darwin.diskdev_cmds;
2024-05-17 23:39:13 +00:00
freebsd = pkgs.freebsd.fdisk;
};
fsck = {
2020-11-24 15:29:28 +00:00
linux = pkgs.util-linux;
darwin = pkgs.darwin.diskdev_cmds;
};
hexdump = {
2020-11-24 15:29:28 +00:00
linux = pkgs.util-linux;
darwin = pkgs.darwin.shell_cmds;
};
hostname = {
linux = pkgs.nettools;
darwin = pkgs.darwin.shell_cmds;
2024-05-17 23:39:13 +00:00
freebsd = pkgs.freebsd.bin;
};
ifconfig = {
linux = pkgs.nettools;
darwin = pkgs.darwin.network_cmds;
2024-05-17 23:39:13 +00:00
freebsd = pkgs.freebsd.ifconfig;
};
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;
darwin = pkgs.darwin.adv_cmds;
2024-05-17 23:39:13 +00:00
freebsd = pkgs.freebsd.locale;
# technically just targeting glibc version
# no obvious exec in manpage
binlore = ''
execer cannot bin/locale
'';
2018-06-11 15:19:31 +00:00
};
logger = {
2020-11-24 15:29:28 +00:00
linux = pkgs.util-linux;
};
more = {
2020-11-24 15:29:28 +00:00
linux = pkgs.util-linux;
darwin = more_compat;
};
mount = {
2020-11-24 15:29:28 +00:00
linux = pkgs.util-linux;
darwin = pkgs.darwin.diskdev_cmds;
2024-05-17 23:39:13 +00:00
freebsd = freebsd.mount;
# technically just targeting the darwin version; binlore already
# ids the util-linux copy as 'cannot'
# no obvious exec in manpage args; I think binlore flags 'can'
# on the code to run `mount_<filesystem>` variants
binlore = ''
execer cannot bin/mount
'';
};
netstat = {
linux = pkgs.nettools;
darwin = pkgs.darwin.network_cmds;
2024-05-17 23:39:13 +00:00
freebsd = pkgs.freebsd.netstat;
};
ping = {
linux = pkgs.iputils;
darwin = pkgs.darwin.network_cmds;
2024-05-17 23:39:13 +00:00
freebsd = freebsd.ping;
};
ps = {
linux = pkgs.procps;
darwin = pkgs.darwin.ps;
2024-05-17 23:39:13 +00:00
freebsd = pkgs.freebsd.bin;
# technically just targeting procps ps (which ids as can)
# but I don't see obvious exec in args; have yet to look
# for underlying cause in source
binlore = ''
execer cannot bin/ps
'';
};
quota = {
linux = pkgs.linuxquota;
darwin = pkgs.darwin.diskdev_cmds;
};
route = {
linux = pkgs.nettools;
darwin = pkgs.darwin.network_cmds;
2024-05-17 23:39:13 +00:00
freebsd = pkgs.freebsd.route;
};
script = {
2020-11-24 15:29:28 +00:00
linux = pkgs.util-linux;
darwin = pkgs.darwin.shell_cmds;
};
sysctl = {
linux = pkgs.procps;
darwin = pkgs.darwin.system_cmds;
2024-05-17 23:39:13 +00:00
freebsd = pkgs.freebsd.sysctl;
};
top = {
linux = pkgs.procps;
darwin = pkgs.darwin.top;
2024-05-17 23:39:13 +00:00
freebsd = pkgs.freebsd.top;
# technically just targeting procps top; haven't needed this in
# any scripts so far, but overriding it for consistency with ps
# override above and in procps. (procps also overrides 'free',
# but it isn't included here.)
binlore = ''
execer cannot bin/top
'';
};
umount = {
2020-11-24 15:29:28 +00:00
linux = pkgs.util-linux;
darwin = pkgs.darwin.diskdev_cmds;
};
whereis = {
2020-11-24 15:29:28 +00:00
linux = pkgs.util-linux;
darwin = pkgs.darwin.shell_cmds;
};
wall = {
2020-11-24 15:29:28 +00:00
linux = pkgs.util-linux;
};
2018-07-08 20:09:25 +00:00
watch = {
linux = pkgs.procps;
# watch is the only command from procps that builds currently on
2024-05-17 23:39:13 +00:00
# Darwin/FreeBSD. Unfortunately no other implementations exist currently!
2018-07-08 20:09:25 +00:00
darwin = pkgs.callPackage ../os-specific/linux/procps-ng {};
2024-05-17 23:39:13 +00:00
freebsd = pkgs.callPackage ../os-specific/linux/procps-ng {};
2018-07-08 20:09:25 +00:00
};
write = {
2020-11-24 15:29:28 +00:00
linux = pkgs.util-linux;
darwin = pkgs.darwin.basic_cmds;
};
xxd = {
linux = pkgs.vim.xxd;
darwin = pkgs.vim.xxd;
2024-05-17 23:39:13 +00:00
freebsd = pkgs.vim.xxd;
};
2018-03-27 03:37:49 +00:00
};
2018-07-08 20:09:47 +00:00
makeCompat = pname: paths:
buildEnv {
name = "${pname}-${version}";
inherit paths;
};
# Compatibility derivations
2018-03-27 03:37:49 +00:00
# Provided for old usage of these commands.
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
script umount whereis write col column ];
nettools = [ arp hostname ifconfig netstat route ];
};
in bins // compat