summary refs log tree commit diff
path: root/pkgs/top-level/unix-tools.nix
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/top-level/unix-tools.nix')
-rw-r--r--pkgs/top-level/unix-tools.nix52
1 files changed, 33 insertions, 19 deletions
diff --git a/pkgs/top-level/unix-tools.nix b/pkgs/top-level/unix-tools.nix
index cc6a8e0592a8..52c3de3166ff 100644
--- a/pkgs/top-level/unix-tools.nix
+++ b/pkgs/top-level/unix-tools.nix
@@ -1,5 +1,4 @@
-{ pkgs, buildEnv, runCommand, hostPlatform, lib
-, stdenv }:
+{ pkgs, buildEnv, runCommand, hostPlatform, lib, stdenv }:
 
 # These are some unix tools that are commonly included in the /usr/bin
 # and /usr/sbin directory under more normal distributions. Along with
@@ -11,35 +10,42 @@
 # instance, if your program needs to use "ps", just list it as a build
 # input, not "procps" which requires Linux.
 
+with lib;
+
 let
   version = "1003.1-2008";
 
   singleBinary = cmd: providers: let
-      provider = "${lib.getBin providers.${hostPlatform.parsed.kernel.name}}/bin/${cmd}";
-      manpage = "${lib.getOutput "man" providers.${hostPlatform.parsed.kernel.name}}/share/man/man1/${cmd}.1.gz";
+      provider = providers.${hostPlatform.parsed.kernel.name};
+      bin = "${getBin provider}/bin/${cmd}";
+      manpage = "${getOutput "man" provider}/share/man/man1/${cmd}.1.gz";
     in runCommand "${cmd}-${version}" {
-      meta.platforms = map (n: { kernel.name = n; }) (pkgs.lib.attrNames providers);
+      meta.platforms = map (n: { kernel.name = n; }) (attrNames providers);
+      passthru = { inherit provider; };
+      preferLocalBuild = true;
     } ''
-      if ! [ -x "${provider}" ]; then
-        echo "Cannot find command ${cmd}"
+      if ! [ -x ${bin} ]; then
+        echo Cannot find command ${cmd}
         exit 1
       fi
 
-      install -D "${provider}" "$out/bin/${cmd}"
+      mkdir -p $out/bin
+      ln -s ${bin} $out/bin/${cmd}
 
-      if [ -f "${manpage}" ]; then
-        install -D "${manpage}" $out/share/man/man1/${cmd}.1.gz
+      if [ -f ${manpage} ]; then
+        mkdir -p $out/share/man/man1
+        ln -s ${manpage} $out/share/man/man1/${cmd}.1.gz
       fi
     '';
 
   # more is unavailable in darwin
-  # just use less
+  # so we just use less
   more_compat = runCommand "more-${version}" {} ''
     mkdir -p $out/bin
     ln -s ${pkgs.less}/bin/less $out/bin/more
   '';
 
-  bins = lib.mapAttrs singleBinary {
+  bins = mapAttrs singleBinary {
     # singular binaries
     arp = {
       linux = pkgs.nettools;
@@ -53,12 +59,12 @@ let
       linux = pkgs.utillinux;
     };
     getconf = {
-      linux = if hostPlatform.libc == "glibc" then lib.getBin pkgs.glibc
+      linux = if hostPlatform.libc == "glibc" then pkgs.glibc
               else pkgs.netbsd.getconf;
       darwin = pkgs.darwin.system_cmds;
     };
     getent = {
-      linux = if hostPlatform.libc == "glibc" then lib.getBin pkgs.glibc
+      linux = if hostPlatform.libc == "glibc" then pkgs.glibc
               else pkgs.netbsd.getent;
       darwin = pkgs.netbsd.getent;
     };
@@ -148,6 +154,13 @@ let
     wall = {
       linux = pkgs.utillinux;
     };
+    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 {};
+    };
     write = {
       linux = pkgs.utillinux;
       darwin = pkgs.darwin.basic_cmds;
@@ -158,15 +171,16 @@ let
     };
   };
 
-  makeCompat = name': value: buildEnv {
-    name = name' + "-compat-${version}";
-    paths = value;
-  };
+  makeCompat = pname: paths:
+    buildEnv {
+      name = "${pname}-${version}";
+      inherit paths;
+    };
 
   # Compatibility derivations
   # Provided for old usage of these commands.
   compat = with bins; lib.mapAttrs makeCompat {
-    procps = [ ps sysctl top ];
+    procps = [ ps sysctl top watch ];
     utillinux = [ fsck fdisk getopt hexdump mount
                   script umount whereis write col ];
     nettools = [ arp hostname ifconfig netstat route ];