|
| 1 | +{ stdenv, lib, buildPackages |
| 2 | +, autoreconfHook, bison, texinfo, fetchurl, perl, xz, libiconv, gmp ? null |
| 3 | +, aclSupport ? stdenv.isLinux, acl ? null |
| 4 | +, attrSupport ? stdenv.isLinux, attr ? null |
| 5 | +, selinuxSupport? false, libselinux ? null, libsepol ? null |
| 6 | +# No openssl in default version, so openssl-induced rebuilds aren't too big. |
| 7 | +# It makes *sum functions significantly faster. |
| 8 | +, minimal ? true, withOpenssl ? !minimal, openssl ? null |
| 9 | +, withPrefix ? false |
| 10 | +, singleBinary ? "symlinks" # you can also pass "shebangs" or false |
| 11 | +}: |
| 12 | + |
| 13 | +# Note: this package is used for bootstrapping fetchurl, and thus |
| 14 | +# cannot use fetchpatch! All mutable patches (generated by GitHub or |
| 15 | +# cgit) that are needed here should be included directly in Nixpkgs as |
| 16 | +# files. |
| 17 | + |
| 18 | +assert aclSupport -> acl != null; |
| 19 | +assert selinuxSupport -> libselinux != null && libsepol != null; |
| 20 | + |
| 21 | +with lib; |
| 22 | + |
| 23 | +stdenv.mkDerivation (rec { |
| 24 | + pname = "coreutils"; |
| 25 | + version = "8.32"; |
| 26 | + |
| 27 | + src = fetchurl { |
| 28 | + url = "mirror://gnu/${pname}/${pname}-${version}.tar.xz"; |
| 29 | + sha256 = "sha256-RFjY3nhJ30TMqxXhaxVIsoUiTbul8I+sBwwcDgvMTPo="; |
| 30 | + }; |
| 31 | + |
| 32 | + patches = [ ./sys-getdents-undeclared.patch ] |
| 33 | + ++ optional stdenv.hostPlatform.isCygwin ./coreutils-8.23-4.cygwin.patch |
| 34 | + # fix gnulib tests on 32-bit ARM. Included on coreutils master. |
| 35 | + # https://lists.gnu.org/r/bug-gnulib/2020-08/msg00225.html |
| 36 | + ++ optional stdenv.hostPlatform.isAarch32 ./fix-gnulib-tests-arm.patch; |
| 37 | + |
| 38 | + postPatch = '' |
| 39 | + # The test tends to fail on btrfs,f2fs and maybe other unusual filesystems. |
| 40 | + sed '2i echo Skipping dd sparse test && exit 77' -i ./tests/dd/sparse.sh |
| 41 | + sed '2i echo Skipping du threshold test && exit 77' -i ./tests/du/threshold.sh |
| 42 | + sed '2i echo Skipping cp sparse test && exit 77' -i ./tests/cp/sparse.sh |
| 43 | + sed '2i echo Skipping rm deep-2 test && exit 77' -i ./tests/rm/deep-2.sh |
| 44 | + sed '2i echo Skipping du long-from-unreadable test && exit 77' -i ./tests/du/long-from-unreadable.sh |
| 45 | +
|
| 46 | + # Depends on the mountpoints |
| 47 | + sed '2i echo Skipping df df-symlink test && exit 77' -i ./tests/df/df-symlink.sh |
| 48 | +
|
| 49 | + # Some target platforms, especially when building inside a container have |
| 50 | + # issues with the inotify test. |
| 51 | + sed '2i echo Skipping tail inotify dir recreate test && exit 77' -i ./tests/tail-2/inotify-dir-recreate.sh |
| 52 | +
|
| 53 | + # sandbox does not allow setgid |
| 54 | + sed '2i echo Skipping chmod setgid test && exit 77' -i ./tests/chmod/setgid.sh |
| 55 | + substituteInPlace ./tests/install/install-C.sh \ |
| 56 | + --replace 'mode3=2755' 'mode3=1755' |
| 57 | +
|
| 58 | + sed '2i print "Skipping env -S test"; exit 77;' -i ./tests/misc/env-S.pl |
| 59 | +
|
| 60 | + # Fails on systems with a rootfs. Looks like a bug in the test, see |
| 61 | + # https://lists.gnu.org/archive/html/bug-coreutils/2019-12/msg00000.html |
| 62 | + sed '2i print "Skipping df skip-rootfs test"; exit 77' -i ./tests/df/skip-rootfs.sh |
| 63 | +
|
| 64 | + # these tests fail in the unprivileged nix sandbox (without nix-daemon) as we break posix assumptions |
| 65 | + for f in ./tests/chgrp/{basic.sh,recurse.sh,default-no-deref.sh,no-x.sh,posix-H.sh}; do |
| 66 | + sed '2i echo Skipping chgrp && exit 77' -i "$f" |
| 67 | + done |
| 68 | + for f in gnulib-tests/{test-chown.c,test-fchownat.c,test-lchown.c}; do |
| 69 | + echo "int main() { return 77; }" > "$f" |
| 70 | + done |
| 71 | +
|
| 72 | + # tests try to access user 1000 which is forbidden in sandbox |
| 73 | + sed '2i print "Skipping id uid test"; exit 77' -i ./tests/id/uid.sh |
| 74 | + sed '2i print "Skipping id zero test"; exit 77' -i ./tests/id/zero.sh |
| 75 | + sed '2i print "Skipping misc help-versiob test"; exit 77' -i ./tests/misc/help-version.sh |
| 76 | + sed '2i print "Skipping chown separator test"; exit 77' -i ./tests/chown/separator.sh |
| 77 | + '' + optionalString (stdenv.hostPlatform.libc == "musl") (lib.concatStringsSep "\n" [ |
| 78 | + '' |
| 79 | + echo "int main() { return 77; }" > gnulib-tests/test-parse-datetime.c |
| 80 | + echo "int main() { return 77; }" > gnulib-tests/test-getlogin.c |
| 81 | + '' |
| 82 | + ]); |
| 83 | + |
| 84 | + outputs = [ "out" "info" ]; |
| 85 | + |
| 86 | + nativeBuildInputs = [ perl xz.bin ] |
| 87 | + ++ optionals stdenv.hostPlatform.isCygwin [ autoreconfHook texinfo ]; # due to patch |
| 88 | + configureFlags = [ "--with-packager=https://NixOS.org" ] |
| 89 | + ++ optional (singleBinary != false) |
| 90 | + ("--enable-single-binary" + optionalString (isString singleBinary) "=${singleBinary}") |
| 91 | + ++ optional withOpenssl "--with-openssl" |
| 92 | + ++ optional stdenv.hostPlatform.isSunOS "ac_cv_func_inotify_init=no" |
| 93 | + ++ optional withPrefix "--program-prefix=g" |
| 94 | + ++ optionals (stdenv.hostPlatform != stdenv.buildPlatform && stdenv.hostPlatform.libc == "glibc") [ |
| 95 | + # TODO(19b98110126fde7cbb1127af7e3fe1568eacad3d): Needed for fstatfs() I |
| 96 | + # don't know why it is not properly detected cross building with glibc. |
| 97 | + "fu_cv_sys_stat_statfs2_bsize=yes" |
| 98 | + ]; |
| 99 | + |
| 100 | + |
| 101 | + buildInputs = [ gmp ] |
| 102 | + ++ optional aclSupport acl |
| 103 | + ++ optional attrSupport attr |
| 104 | + ++ optional withOpenssl openssl |
| 105 | + ++ optionals selinuxSupport [ libselinux libsepol ] |
| 106 | + # TODO(@Ericson2314): Investigate whether Darwin could benefit too |
| 107 | + ++ optional (stdenv.hostPlatform != stdenv.buildPlatform && stdenv.hostPlatform.libc != "glibc") libiconv; |
| 108 | + |
| 109 | + # The tests are known broken on Cygwin |
| 110 | + # (http://article.gmane.org/gmane.comp.gnu.core-utils.bugs/19025), |
| 111 | + # Darwin (http://article.gmane.org/gmane.comp.gnu.core-utils.bugs/19351), |
| 112 | + # and {Open,Free}BSD. |
| 113 | + # With non-standard storeDir: https://github.com/NixOS/nix/issues/512 |
| 114 | + doCheck = stdenv.hostPlatform == stdenv.buildPlatform |
| 115 | + && (stdenv.hostPlatform.libc == "glibc" || stdenv.hostPlatform.isMusl) |
| 116 | + && !stdenv.isAarch32; |
| 117 | + |
| 118 | + # Prevents attempts of running 'help2man' on cross-built binaries. |
| 119 | + PERL = if stdenv.hostPlatform == stdenv.buildPlatform then null else "missing"; |
| 120 | + |
| 121 | + # Saw random failures like ‘help2man: can't get '--help' info from |
| 122 | + # man/sha512sum.td/sha512sum’. |
| 123 | + enableParallelBuilding = false; |
| 124 | + |
| 125 | + NIX_LDFLAGS = optionalString selinuxSupport "-lsepol"; |
| 126 | + FORCE_UNSAFE_CONFIGURE = optionalString stdenv.hostPlatform.isSunOS "1"; |
| 127 | + |
| 128 | + # Works around a bug with 8.26: |
| 129 | + # Makefile:3440: *** Recursive variable 'INSTALL' references itself (eventually). Stop. |
| 130 | + preInstall = optionalString (stdenv.hostPlatform != stdenv.buildPlatform) '' |
| 131 | + sed -i Makefile -e 's|^INSTALL =.*|INSTALL = ${buildPackages.coreutils}/bin/install -c|' |
| 132 | + ''; |
| 133 | + |
| 134 | + postInstall = optionalString (stdenv.hostPlatform != stdenv.buildPlatform && !minimal) '' |
| 135 | + rm $out/share/man/man1/* |
| 136 | + cp ${buildPackages.coreutils-full}/share/man/man1/* $out/share/man/man1 |
| 137 | + '' |
| 138 | + # du: 8.7 M locale + 0.4 M man pages |
| 139 | + + optionalString minimal '' |
| 140 | + rm -r "$out/share" |
| 141 | + ''; |
| 142 | + |
| 143 | + meta = { |
| 144 | + homepage = "https://www.gnu.org/software/coreutils/"; |
| 145 | + description = "The basic file, shell and text manipulation utilities of the GNU operating system"; |
| 146 | + longDescription = '' |
| 147 | + The GNU Core Utilities are the basic file, shell and text |
| 148 | + manipulation utilities of the GNU operating system. These are |
| 149 | + the core utilities which are expected to exist on every |
| 150 | + operating system. |
| 151 | + ''; |
| 152 | + license = licenses.gpl3Plus; |
| 153 | + platforms = platforms.unix ++ platforms.windows; |
| 154 | + priority = 10; |
| 155 | + maintainers = [ maintainers.eelco ]; |
| 156 | + }; |
| 157 | +} // optionalAttrs stdenv.hostPlatform.isMusl { |
| 158 | + # Work around a bogus warning in conjunction with musl. |
| 159 | + NIX_CFLAGS_COMPILE = "-Wno-error"; |
| 160 | +} // lib.optionalAttrs stdenv.hostPlatform.isAndroid { |
| 161 | + NIX_CFLAGS_COMPILE = "-D__USE_FORTIFY_LEVEL=0"; |
| 162 | +}) |
0 commit comments