lol
at 24.05-pre 196 lines 5.2 kB view raw
1{ pkgs, buildEnv, runCommand, lib, stdenv }: 2 3# These are some unix tools that are commonly included in the /usr/bin 4# and /usr/sbin directory under more normal distributions. Along with 5# coreutils, these are commonly assumed to be available by build 6# systems, but we can't assume they are available. In Nix, we list 7# each program by name directly through this unixtools attribute. 8 9# You should always try to use single binaries when available. For 10# instance, if your program needs to use "ps", just list it as a build 11# input, not "procps" which requires Linux. 12 13with lib; 14 15let 16 version = "1003.1-2008"; 17 18 singleBinary = cmd: providers: let 19 provider = providers.${stdenv.hostPlatform.parsed.kernel.name} or providers.linux; 20 bin = "${getBin provider}/bin/${cmd}"; 21 manpage = "${getOutput "man" provider}/share/man/man1/${cmd}.1.gz"; 22 in runCommand "${cmd}-${provider.name}" { 23 meta = { 24 mainProgram = cmd; 25 priority = 10; 26 platforms = lib.platforms.${stdenv.hostPlatform.parsed.kernel.name} or lib.platforms.all; 27 }; 28 passthru = { inherit provider; }; 29 preferLocalBuild = true; 30 } '' 31 if ! [ -x ${bin} ]; then 32 echo Cannot find command ${cmd} 33 exit 1 34 fi 35 36 mkdir -p $out/bin 37 ln -s ${bin} $out/bin/${cmd} 38 39 if [ -f ${manpage} ]; then 40 mkdir -p $out/share/man/man1 41 ln -s ${manpage} $out/share/man/man1/${cmd}.1.gz 42 fi 43 ''; 44 45 # more is unavailable in darwin 46 # so we just use less 47 more_compat = runCommand "more-${pkgs.less.name}" {} '' 48 mkdir -p $out/bin 49 ln -s ${pkgs.less}/bin/less $out/bin/more 50 ''; 51 52 bins = mapAttrs singleBinary { 53 # singular binaries 54 arp = { 55 linux = pkgs.nettools; 56 darwin = pkgs.darwin.network_cmds; 57 }; 58 col = { 59 linux = pkgs.util-linux; 60 darwin = pkgs.darwin.text_cmds; 61 }; 62 column = { 63 linux = pkgs.util-linux; 64 darwin = pkgs.darwin.text_cmds; 65 }; 66 eject = { 67 linux = pkgs.util-linux; 68 }; 69 getconf = { 70 linux = if stdenv.hostPlatform.libc == "glibc" then pkgs.stdenv.cc.libc 71 else pkgs.netbsd.getconf; 72 darwin = pkgs.darwin.system_cmds; 73 }; 74 getent = { 75 linux = if stdenv.hostPlatform.libc == "glibc" then pkgs.stdenv.cc.libc.getent 76 else pkgs.netbsd.getent; 77 darwin = pkgs.netbsd.getent; 78 }; 79 getopt = { 80 linux = pkgs.util-linux; 81 darwin = pkgs.getopt; 82 }; 83 fdisk = { 84 linux = pkgs.util-linux; 85 darwin = pkgs.darwin.diskdev_cmds; 86 }; 87 fsck = { 88 linux = pkgs.util-linux; 89 darwin = pkgs.darwin.diskdev_cmds; 90 }; 91 hexdump = { 92 linux = pkgs.util-linux; 93 darwin = pkgs.darwin.shell_cmds; 94 }; 95 hostname = { 96 linux = pkgs.nettools; 97 darwin = pkgs.darwin.shell_cmds; 98 }; 99 ifconfig = { 100 linux = pkgs.nettools; 101 darwin = pkgs.darwin.network_cmds; 102 }; 103 killall = { 104 linux = pkgs.psmisc; 105 darwin = pkgs.darwin.shell_cmds; 106 }; 107 locale = { 108 linux = pkgs.glibc; 109 darwin = pkgs.darwin.adv_cmds; 110 }; 111 logger = { 112 linux = pkgs.util-linux; 113 }; 114 more = { 115 linux = pkgs.util-linux; 116 darwin = more_compat; 117 }; 118 mount = { 119 linux = pkgs.util-linux; 120 darwin = pkgs.darwin.diskdev_cmds; 121 }; 122 netstat = { 123 linux = pkgs.nettools; 124 darwin = pkgs.darwin.network_cmds; 125 }; 126 ping = { 127 linux = pkgs.iputils; 128 darwin = pkgs.darwin.network_cmds; 129 }; 130 ps = { 131 linux = pkgs.procps; 132 darwin = pkgs.darwin.ps; 133 }; 134 quota = { 135 linux = pkgs.linuxquota; 136 darwin = pkgs.darwin.diskdev_cmds; 137 }; 138 route = { 139 linux = pkgs.nettools; 140 darwin = pkgs.darwin.network_cmds; 141 }; 142 script = { 143 linux = pkgs.util-linux; 144 darwin = pkgs.darwin.shell_cmds; 145 }; 146 sysctl = { 147 linux = pkgs.procps; 148 darwin = pkgs.darwin.system_cmds; 149 }; 150 top = { 151 linux = pkgs.procps; 152 darwin = pkgs.darwin.top; 153 }; 154 umount = { 155 linux = pkgs.util-linux; 156 darwin = pkgs.darwin.diskdev_cmds; 157 }; 158 whereis = { 159 linux = pkgs.util-linux; 160 darwin = pkgs.darwin.shell_cmds; 161 }; 162 wall = { 163 linux = pkgs.util-linux; 164 }; 165 watch = { 166 linux = pkgs.procps; 167 168 # watch is the only command from procps that builds currently on 169 # Darwin. Unfortunately no other implementations exist currently! 170 darwin = pkgs.callPackage ../os-specific/linux/procps-ng {}; 171 }; 172 write = { 173 linux = pkgs.util-linux; 174 darwin = pkgs.darwin.basic_cmds; 175 }; 176 xxd = { 177 linux = pkgs.vim; 178 darwin = pkgs.vim; 179 }; 180 }; 181 182 makeCompat = pname: paths: 183 buildEnv { 184 name = "${pname}-${version}"; 185 inherit paths; 186 }; 187 188 # Compatibility derivations 189 # Provided for old usage of these commands. 190 compat = with bins; lib.mapAttrs makeCompat { 191 procps = [ ps sysctl top watch ]; 192 util-linux = [ fsck fdisk getopt hexdump mount 193 script umount whereis write col column ]; 194 nettools = [ arp hostname ifconfig netstat route ]; 195 }; 196in bins // compat