10 , gmpSupport ? true, gmp
11 , aclSupport ? stdenv.isLinux, acl
12 , attrSupport ? stdenv.isLinux, attr
13 , selinuxSupport ? false, libselinux, libsepol
14 # No openssl in default version, so openssl-induced rebuilds aren't too big.
15 # It makes *sum functions significantly faster.
17 , withOpenssl ? !minimal, openssl
19 , singleBinary ? "symlinks" # you can also pass "shebangs" or false
22 # Note: this package is used for bootstrapping fetchurl, and thus cannot use
23 # fetchpatch! All mutable patches (generated by GitHub or cgit) that are needed
24 # here should be included directly in Nixpkgs as files.
26 assert aclSupport -> acl != null;
27 assert selinuxSupport -> libselinux != null && libsepol != null;
30 inherit (lib) concatStringsSep isString optional optionals optionalString;
31 isCross = (stdenv.hostPlatform != stdenv.buildPlatform);
33 stdenv.mkDerivation rec {
34 pname = "coreutils" + (optionalString (!minimal) "-full");
38 url = "mirror://gnu/coreutils/coreutils-${version}.tar.xz";
39 sha256 = "sha256-YaH0ENeLp+fzelpPUObRMgrKMzdUhKMlXt3xejhYBCM=";
42 patches = lib.optionals (stdenv.isDarwin && stdenv.isx86_64) [
43 # Workaround for https://debbugs.gnu.org/cgi/bugreport.cgi?bug=51433
44 ./disable-seek-hole.patch
48 # The test tends to fail on btrfs, f2fs and maybe other unusual filesystems.
49 sed '2i echo Skipping dd sparse test && exit 77' -i ./tests/dd/sparse.sh
50 sed '2i echo Skipping du threshold test && exit 77' -i ./tests/du/threshold.sh
51 sed '2i echo Skipping cp reflink-auto test && exit 77' -i ./tests/cp/reflink-auto.sh
52 sed '2i echo Skipping cp sparse test && exit 77' -i ./tests/cp/sparse.sh
53 sed '2i echo Skipping rm deep-2 test && exit 77' -i ./tests/rm/deep-2.sh
54 sed '2i echo Skipping du long-from-unreadable test && exit 77' -i ./tests/du/long-from-unreadable.sh
56 # Some target platforms, especially when building inside a container have
57 # issues with the inotify test.
58 sed '2i echo Skipping tail inotify dir recreate test && exit 77' -i ./tests/tail-2/inotify-dir-recreate.sh
60 # sandbox does not allow setgid
61 sed '2i echo Skipping chmod setgid test && exit 77' -i ./tests/chmod/setgid.sh
62 substituteInPlace ./tests/install/install-C.sh \
63 --replace 'mode3=2755' 'mode3=1755'
65 # Fails on systems with a rootfs. Looks like a bug in the test, see
66 # https://lists.gnu.org/archive/html/bug-coreutils/2019-12/msg00000.html
67 sed '2i print "Skipping df skip-rootfs test"; exit 77' -i ./tests/df/skip-rootfs.sh
69 # these tests fail in the unprivileged nix sandbox (without nix-daemon) as we break posix assumptions
70 for f in ./tests/chgrp/{basic.sh,recurse.sh,default-no-deref.sh,no-x.sh,posix-H.sh}; do
71 sed '2i echo Skipping chgrp && exit 77' -i "$f"
73 for f in gnulib-tests/{test-chown.c,test-fchownat.c,test-lchown.c}; do
74 echo "int main() { return 77; }" > "$f"
77 # intermittent failures on builders, unknown reason
78 sed '2i echo Skipping du basic test && exit 77' -i ./tests/du/basic.sh
79 '' + (optionalString (stdenv.hostPlatform.libc == "musl") (concatStringsSep "\n" [
81 echo "int main() { return 77; }" > gnulib-tests/test-parse-datetime.c
82 echo "int main() { return 77; }" > gnulib-tests/test-getlogin.c
84 ])) + (optionalString stdenv.isAarch64 ''
85 sed '2i print "Skipping tail assert test"; exit 77' -i ./tests/tail-2/assert.sh
87 # Sometimes fails: https://github.com/NixOS/nixpkgs/pull/143097#issuecomment-954462584
88 sed '2i echo Skipping cut huge range test && exit 77' -i ./tests/misc/cut-huge-range.sh
91 outputs = [ "out" "info" ];
92 separateDebugInfo = true;
95 # autoreconfHook is due to patch, normally only needed for cygwin
100 ++ optionals stdenv.hostPlatform.isCygwin [
106 ++ optional aclSupport acl
107 ++ optional attrSupport attr
108 ++ optional gmpSupport gmp
109 ++ optional withOpenssl openssl
110 ++ optionals selinuxSupport [ libselinux libsepol ]
111 # TODO(@Ericson2314): Investigate whether Darwin could benefit too
112 ++ optional (isCross && stdenv.hostPlatform.libc != "glibc") libiconv;
114 configureFlags = [ "--with-packager=https://nixos.org" ]
115 ++ optional (singleBinary != false)
116 ("--enable-single-binary" + optionalString (isString singleBinary) "=${singleBinary}")
117 ++ optional withOpenssl "--with-openssl"
118 ++ optional stdenv.hostPlatform.isSunOS "ac_cv_func_inotify_init=no"
119 ++ optional withPrefix "--program-prefix=g"
120 # the shipped configure script doesn't enable nls, but using autoreconfHook
121 # does so which breaks the build
122 ++ optional stdenv.isDarwin "--disable-nls"
123 ++ optionals (isCross && stdenv.hostPlatform.libc == "glibc") [
124 # TODO(19b98110126fde7cbb1127af7e3fe1568eacad3d): Needed for fstatfs() I
125 # don't know why it is not properly detected cross building with glibc.
126 "fu_cv_sys_stat_statfs2_bsize=yes"
128 # /proc/uptime is available on Linux and produces accurate results even if
129 # the boot time is set to the epoch because the system has no RTC. We
130 # explicitly enable it for cases where it can't be detected automatically,
131 # such as when cross-compiling.
132 ++ optional stdenv.hostPlatform.isLinux "gl_cv_have_proc_uptime=yes";
134 # The tests are known broken on Cygwin
135 # (http://article.gmane.org/gmane.comp.gnu.core-utils.bugs/19025),
136 # Darwin (http://article.gmane.org/gmane.comp.gnu.core-utils.bugs/19351),
137 # and {Open,Free}BSD.
138 # With non-standard storeDir: https://github.com/NixOS/nix/issues/512
139 # On aarch64+musl, test-init.sh fails due to a segfault in diff.
141 && (stdenv.hostPlatform.libc == "glibc" || stdenv.hostPlatform.libc == "musl")
142 && !(stdenv.hostPlatform.libc == "musl" && stdenv.hostPlatform.isAarch64)
143 && !stdenv.isAarch32;
145 # Prevents attempts of running 'help2man' on cross-built binaries.
146 PERL = if isCross then "missing" else null;
148 enableParallelBuilding = true;
150 NIX_LDFLAGS = optionalString selinuxSupport "-lsepol";
151 FORCE_UNSAFE_CONFIGURE = optionalString stdenv.hostPlatform.isSunOS "1";
152 NIX_CFLAGS_COMPILE = []
153 # Work around a bogus warning in conjunction with musl.
154 ++ optional stdenv.hostPlatform.isMusl "-Wno-error"
155 ++ optional stdenv.hostPlatform.isAndroid "-D__USE_FORTIFY_LEVEL=0";
157 # Works around a bug with 8.26:
158 # Makefile:3440: *** Recursive variable 'INSTALL' references itself (eventually). Stop.
159 preInstall = optionalString isCross ''
160 sed -i Makefile -e 's|^INSTALL =.*|INSTALL = ${buildPackages.coreutils}/bin/install -c|'
163 postInstall = optionalString (isCross && !minimal) ''
164 rm $out/share/man/man1/*
165 cp ${buildPackages.coreutils-full}/share/man/man1/* $out/share/man/man1
167 # du: 8.7 M locale + 0.4 M man pages
168 + optionalString minimal ''
173 homepage = "https://www.gnu.org/software/coreutils/";
174 description = "The GNU Core Utilities";
176 The GNU Core Utilities are the basic file, shell and text manipulation
177 utilities of the GNU operating system. These are the core utilities which
178 are expected to exist on every operating system.
180 license = licenses.gpl3Plus;
181 maintainers = with maintainers; [ das_j ];
182 platforms = with platforms; unix ++ windows;