From 7e4ce2cfcbb217bb66e068803b549a4d1fa98673 Mon Sep 17 00:00:00 2001 From: Matthew Bauer Date: Sun, 8 Jul 2018 16:09:47 -0400 Subject: unixtools: refactor --- pkgs/top-level/unix-tools.nix | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/pkgs/top-level/unix-tools.nix b/pkgs/top-level/unix-tools.nix index f92e90fed77..3f8fdf7d888 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,21 +10,25 @@ # 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; }; } '' - if ! [ -x "${provider}" ]; then + if ! [ -x "${bin}" ]; then echo "Cannot find command ${cmd}" exit 1 fi - install -D "${provider}" "$out/bin/${cmd}" + install -D "${bin}" "$out/bin/${cmd}" if [ -f "${manpage}" ]; then install -D "${manpage}" $out/share/man/man1/${cmd}.1.gz @@ -33,13 +36,13 @@ let ''; # 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 +56,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; }; @@ -165,10 +168,11 @@ 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. -- cgit 1.4.1