diff --git a/pkgs/os-specific/linux/busybox/default.nix b/pkgs/os-specific/linux/busybox/default.nix index e3e313e175ef..d155c1064676 100644 --- a/pkgs/os-specific/linux/busybox/default.nix +++ b/pkgs/os-specific/linux/busybox/default.nix @@ -13,6 +13,13 @@ useMusl ? stdenv.hostPlatform.libc == "musl", musl, extraConfig ? "", + + # For tests + hostname, + coreutils, + zip, + which, + simple-http-server, }: assert stdenv.hostPlatform.libc == "musl" -> useMusl; @@ -50,11 +57,13 @@ let }; debianDispatcherScript = "${debianSource}/debian/tree/udhcpc/etc/udhcpc/default.script"; outDispatchPath = "$out/default.script"; -in -stdenv.mkDerivation rec { pname = "busybox"; version = "1.37.0"; +in + +stdenv.mkDerivation (finalAttrs: { + inherit pname version; # Note to whoever is updating busybox: please verify that: # nix-build pkgs/stdenv/linux/make-bootstrap-tools.nix -A test @@ -193,9 +202,77 @@ stdenv.mkDerivation rec { enableParallelBuilding = true; - doCheck = false; # tries to access the net + doCheck = false; # Takes a while, requires extra dependencies + passthru = { + shellPath = "/bin/ash"; - passthru.shellPath = "/bin/ash"; + tests.withCheck = finalAttrs.finalPackage.overrideAttrs (_: { + doCheck = true; + + nativeCheckInputs = [ + hostname + zip + which + simple-http-server + ]; + + preCheck = '' + # Replace hard-coded dependencies on /bin + sed -i 's|/bin/date|${lib.getExe' coreutils "date"}|' testsuite/date/date-works-1 + + # wget tests rely on network access, use simple-http-server instead + simple-http-server --index & + sed -i 's|http://www.google.com|http://127.0.0.1:8000|' testsuite/wget/* + + skip-files() { + for file in "$@"; do + echo "echo SKIPPED $file; exit 0" > $file + done + } + + skip-testcase() { + sed -i "s@testing \"$2\"@echo SKIPPED $2 || testing \"$2\"@" "$1" + } + + # Skip known-broken tests + export SKIP_KNOWN_BUGS=y + + # There are some semi-expected locale-related issues, disable tests that rely on it + export CONFIG_UNICODE_USING_LOCALE=y + + # DISABLE SOME TESTS + # TODO(balsoft): fix the tests instead of skipping + + pushd testsuite + + # Weird failures, may or may not be related to locales + skip-files du/du-{h,k,l}-works + + # Relies on a default PATH (/bin/ls in particular) + skip-files which/which-uses-default-path + + # Hangs indefinitely if run from sandbox + skip-files md5sum.tests + + # Doesn't work with coreutils's "false" + skip-testcase start-stop-daemon.tests "start-stop-daemon with both -x and -a" + + # Relies on /usr/bin + skip-testcase cpio.tests "cpio -p with absolute paths" + + # Relies on suid/guid bits + skip-testcase cpio.tests "cpio restores suid/sgid bits" + + # Weird failures, looks related to our sandbox + skip-testcase tar.tests "tar does not extract into symlinks" + skip-testcase tar.tests "tar -k does not extract into symlinks" + skip-testcase tar.tests "tar Symlink attack: create symlink and then write through it" + skip-testcase tar.tests "tar Symlinks and hardlinks coexist" + + popd + ''; + }); + }; meta = { description = "Tiny versions of common UNIX utilities in a single small executable"; @@ -211,4 +288,4 @@ stdenv.mkDerivation rec { priority = 15; # below systemd (halt, init, poweroff, reboot) and coreutils identifiers.cpeParts = lib.meta.cpeFullVersionWithVendor "busybox" version; }; -} +})