Skip to content

Commit

Permalink
unix-tools: introduce unix-tools.nix
Browse files Browse the repository at this point in the history
unix-tools.nix has a collection of tools that are commonly installed
by default in Unix derivatives. This is intended to provide
compatibility between macOS and Linux users. Three Linux-only
derivations are provided for compatbility:

- procps
- utillinux
- nettools

More tools are also provided.

Also: treewide: use unixtools

Non-comprehensive replace of Linux-only procps and util-linux with
'unixtools'.
  • Loading branch information
matthewbauer committed Mar 26, 2018
1 parent 675dc1b commit ce8ce60
Show file tree
Hide file tree
Showing 11 changed files with 119 additions and 27 deletions.
6 changes: 3 additions & 3 deletions pkgs/applications/version-management/gitlab/default.nix
@@ -1,5 +1,5 @@
{ pkgs, stdenv, lib, bundler, fetchurl, fetchFromGitHub, bundlerEnv, libiconv
, ruby, tzdata, git, procps, dpkg, nettools
, ruby, tzdata, git, ps, dpkg, nettools
}:

/* When updating the Gemfile add `gem "activerecord-nulldb-adapter"`
Expand Down Expand Up @@ -38,7 +38,7 @@ stdenv.mkDerivation rec {
};

buildInputs = [
rubyEnv ruby bundler tzdata git procps dpkg nettools
rubyEnv ruby bundler tzdata git ps dpkg nettools
];

patches = [
Expand All @@ -56,7 +56,7 @@ stdenv.mkDerivation rec {
rm config/initializers/gitlab_shell_secret_token.rb
substituteInPlace app/controllers/admin/background_jobs_controller.rb \
--replace "ps -U" "${procps}/bin/ps -U"
--replace "ps -U" "${ps}/bin/ps -U"
sed -i '/ask_to_continue/d' lib/tasks/gitlab/two_factor.rake
Expand Down
3 changes: 2 additions & 1 deletion pkgs/servers/nosql/cassandra/generic.nix
Expand Up @@ -10,7 +10,8 @@ let
gawk
which
jre
] ++ stdenv.lib.optional stdenv.isLinux procps);
procps
]);
in

stdenv.mkDerivation rec {
Expand Down
7 changes: 3 additions & 4 deletions pkgs/servers/xmpp/biboumi/default.nix
@@ -1,5 +1,5 @@
{ stdenv, fetchurl, fetchgit, cmake, libuuid, expat, sqlite, libidn,
libiconv, botan2, systemd, pkgconfig, udns, pandoc, procps } :
libiconv, botan2, systemd, pkgconfig, udns, pandoc, coreutils } :

stdenv.mkDerivation rec {
name = "biboumi-${version}";
Expand All @@ -20,12 +20,11 @@ stdenv.mkDerivation rec {

nativeBuildInputs = [ cmake pkgconfig pandoc ];
buildInputs = [ libuuid expat sqlite libiconv libidn botan2 systemd
udns procps ];
udns ];

inherit procps;
preConfigure = ''
substituteInPlace CMakeLists.txt --replace /etc/biboumi $out/etc/biboumi
substituteInPlace unit/biboumi.service.cmake --replace /bin/kill $procps/bin/kill
substituteInPlace unit/biboumi.service.cmake --replace /bin/kill ${coreutils}/bin/kill
cp $louiz_catch/single_include/catch.hpp tests/
# echo "policy_directory=$out/etc/biboumi" >> conf/biboumi.cfg
# TODO include conf/biboumi.cfg as example somewhere
Expand Down
3 changes: 2 additions & 1 deletion pkgs/servers/xmpp/ejabberd/default.nix
@@ -1,5 +1,6 @@
{ stdenv, writeScriptBin, lib, fetchurl, git, cacert
, erlang, openssl, expat, libyaml, bash, gnused, gnugrep, coreutils, utillinux, procps, gd
, flock
, withMysql ? false
, withPgsql ? false
, withSqlite ? false, sqlite
Expand Down Expand Up @@ -101,7 +102,7 @@ in stdenv.mkDerivation rec {
postInstall = ''
sed -i \
-e '2iexport PATH=${ctlpath}:$PATH' \
-e 's,\(^ *FLOCK=\).*,\1${utillinux}/bin/flock,' \
-e 's,\(^ *FLOCK=\).*,\1${flock}/bin/flock,' \
-e 's,\(^ *JOT=\).*,\1,' \
-e 's,\(^ *CONNLOCKDIR=\).*,\1/var/lock/ejabberdctl,' \
$out/sbin/ejabberdctl
Expand Down
5 changes: 2 additions & 3 deletions pkgs/tools/misc/keychain/default.nix
@@ -1,6 +1,5 @@
{ stdenv, fetchFromGitHub, makeWrapper, coreutils, openssh, gnupg
, perl, procps, gnugrep, gawk, findutils, gnused
, withProcps ? stdenv.isLinux }:
, perl, procps, gnugrep, gawk, findutils, gnused }:

stdenv.mkDerivation rec {
name = "keychain-${version}";
Expand All @@ -27,7 +26,7 @@ stdenv.mkDerivation rec {
--prefix PATH ":" "${gnused}/bin" \
--prefix PATH ":" "${findutils}/bin" \
--prefix PATH ":" "${gawk}/bin" \
${if withProcps then ("--prefix PATH \":\" ${procps}/bin") else ""}
--prefix PATH ":" "${procps}/bin"
'';

meta = {
Expand Down
2 changes: 1 addition & 1 deletion pkgs/tools/misc/parallel/default.nix
Expand Up @@ -12,7 +12,7 @@ stdenv.mkDerivation rec {

postInstall = ''
wrapProgram $out/bin/parallel \
${if stdenv.isLinux then ("--prefix PATH \":\" ${procps}/bin") else ""} \
--prefix PATH : "${procps}/bin" \
--prefix PATH : "${perl}/bin" \
'';

Expand Down
4 changes: 2 additions & 2 deletions pkgs/tools/networking/i2p/default.nix
@@ -1,4 +1,4 @@
{ stdenv, procps, coreutils, fetchurl, jdk, jre, ant, gettext, which }:
{ stdenv, ps, coreutils, fetchurl, jdk, jre, ant, gettext, which }:

let wrapper = stdenv.mkDerivation rec {
name = "wrapper-${version}";
Expand Down Expand Up @@ -51,7 +51,7 @@ stdenv.mkDerivation rec {
-e "s#uname#${coreutils}/bin/uname#" \
-e "s#which#${which}/bin/which#" \
-e "s#%gettext%#${gettext}/bin/gettext#" \
-e "s#/usr/ucb/ps#${procps}/bin/ps#" \
-e "s#/usr/ucb/ps#${ps}/bin/ps#" \
-e "s#/usr/bin/tr#${coreutils}/bin/tr#" \
-e "s#%INSTALL_PATH#$out#" \
-e 's#%USER_HOME#$HOME#' \
Expand Down
2 changes: 1 addition & 1 deletion pkgs/tools/security/pass/default.nix
Expand Up @@ -74,8 +74,8 @@ in stdenv.mkDerivation rec {
tree
which
qrencode
procps
] ++ optional tombPluginSupport tomb
++ optional stdenv.isLinux procps
++ ifEnable x11Support [ dmenu xclip xdotool ]);

postFixup = ''
Expand Down
4 changes: 2 additions & 2 deletions pkgs/tools/security/sshuttle/default.nix
Expand Up @@ -25,8 +25,8 @@ python3Packages.buildPythonApplication rec {

nativeBuildInputs = [ makeWrapper python3Packages.setuptools_scm ] ++ stdenv.lib.optional (stdenv.system != "i686-linux") pandoc;
buildInputs =
[ coreutils openssh ] ++
stdenv.lib.optionals stdenv.isLinux [ iptables nettools procps ];
[ coreutils openssh procps nettools ]
++ stdenv.lib.optionals stdenv.isLinux [ iptables ];

checkInputs = with python3Packages; [ mock pytest pytestrunner ];

Expand Down
21 changes: 12 additions & 9 deletions pkgs/top-level/all-packages.nix
Expand Up @@ -12380,12 +12380,7 @@ with pkgs;
jetty = callPackage ../servers/http/jetty { };

knot-dns = callPackage ../servers/dns/knot-dns { };
knot-resolver = callPackage ../servers/dns/knot-resolver {
# TODO: vimNox after it gets fixed on Darwin or something lighter
hexdump = if stdenv.isLinux then utillinux.bin
else if stdenv.isDarwin then darwin.shell_cmds
else vim/*xxd*/;
};
knot-resolver = callPackage ../servers/dns/knot-resolver { };

rdkafka = callPackage ../development/libraries/rdkafka { };

Expand Down Expand Up @@ -13694,7 +13689,8 @@ with pkgs;
if hostPlatform.isMusl then musl-getconf
else lib.getBin stdenv.cc.libc;

nettools = callPackage ../os-specific/linux/net-tools { };
nettools = if stdenv.isLinux then callPackage ../os-specific/linux/net-tools { }
else unixtools.nettools;

nftables = callPackage ../os-specific/linux/nftables { };

Expand Down Expand Up @@ -13817,7 +13813,8 @@ with pkgs;

procps = procps-ng;

procps-ng = callPackage ../os-specific/linux/procps-ng { };
procps-ng = if stdenv.isLinux then callPackage ../os-specific/linux/procps-ng { }
else unixtools.procps;

watch = callPackage ../os-specific/linux/procps/watch.nix { };

Expand Down Expand Up @@ -14010,7 +14007,9 @@ with pkgs;

usermount = callPackage ../os-specific/linux/usermount { };

utillinux = callPackage ../os-specific/linux/util-linux { };
utillinux = if stdenv.isLinux then callPackage ../os-specific/linux/util-linux { }
else unixtools.utillinux;

utillinuxCurses = utillinux;

utillinuxMinimal = appendToName "minimal" (utillinux.override {
Expand Down Expand Up @@ -21140,4 +21139,8 @@ with pkgs;
xml2rfc = callPackage ../tools/typesetting/xml2rfc { };

mmark = callPackage ../tools/typesetting/mmark { };

# Unix tools
unixtools = recurseIntoAttrs (callPackages ./unix-tools.nix { });
inherit (unixtools) hexdump ps;
}
89 changes: 89 additions & 0 deletions pkgs/top-level/unix-tools.nix
@@ -0,0 +1,89 @@
{ pkgs, buildEnv, runCommand, hostPlatform }:

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 {
arp = singleBinary "arp" {
linux = pkgs.nettools;
darwin = pkgs.darwin.network_cmds;
};
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;
};
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;
darwin = pkgs.darwin.adv_cmds;
};
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;
};
whereis = singleBinary "whereis" {
linux = pkgs.utillinux;
darwin = pkgs.darwin.shell_cmds;
};
write = singleBinary "write" {
linux = pkgs.utillinux;
darwin = pkgs.darwin.basic_cmds;
};

# Compatibility derivations

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 ];
};
}

0 comments on commit ce8ce60

Please sign in to comment.