1{ lib
2, stdenv
3, fetchurl
4, autoreconfHook
5, buildPackages
6, libiconv
7, perl
8, texinfo
9, xz
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.
16, minimal ? true
17, withOpenssl ? !minimal, openssl
18, withPrefix ? false
19, singleBinary ? "symlinks" # you can also pass "shebangs" or false
20}:
21
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.
25
26assert aclSupport -> acl != null;
27assert selinuxSupport -> libselinux != null && libsepol != null;
28
29let
30 inherit (lib) concatStringsSep isString optional optionals optionalString;
31 isCross = (stdenv.hostPlatform != stdenv.buildPlatform);
32in
33stdenv.mkDerivation rec {
34 pname = "coreutils" + (optionalString (!minimal) "-full");
35 version = "9.1";
36
37 src = fetchurl {
38 url = "mirror://gnu/coreutils/coreutils-${version}.tar.xz";
39 sha256 = "sha256-YaH0ENeLp+fzelpPUObRMgrKMzdUhKMlXt3xejhYBCM=";
40 };
41
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
45 ];
46
47 postPatch = ''
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
55
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
59
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'
64
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
68
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"
72 done
73 for f in gnulib-tests/{test-chown.c,test-fchownat.c,test-lchown.c}; do
74 echo "int main() { return 77; }" > "$f"
75 done
76
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" [
80 ''
81 echo "int main() { return 77; }" > gnulib-tests/test-parse-datetime.c
82 echo "int main() { return 77; }" > gnulib-tests/test-getlogin.c
83 ''
84 ])) + (optionalString stdenv.isAarch64 ''
85 sed '2i print "Skipping tail assert test"; exit 77' -i ./tests/tail-2/assert.sh
86
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
89 '');
90
91 outputs = [ "out" "info" ];
92 separateDebugInfo = true;
93
94 nativeBuildInputs = [
95 # autoreconfHook is due to patch, normally only needed for cygwin
96 autoreconfHook
97 perl
98 xz.bin
99 ]
100 ++ optionals stdenv.hostPlatform.isCygwin [
101 # due to patch
102 texinfo
103 ];
104
105 buildInputs = [ ]
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;
113
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"
127 ]
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";
133
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.
140 doCheck = (!isCross)
141 && (stdenv.hostPlatform.libc == "glibc" || stdenv.hostPlatform.libc == "musl")
142 && !(stdenv.hostPlatform.libc == "musl" && stdenv.hostPlatform.isAarch64)
143 && !stdenv.isAarch32;
144
145 # Prevents attempts of running 'help2man' on cross-built binaries.
146 PERL = if isCross then "missing" else null;
147
148 enableParallelBuilding = true;
149
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";
156
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|'
161 '';
162
163 postInstall = optionalString (isCross && !minimal) ''
164 rm $out/share/man/man1/*
165 cp ${buildPackages.coreutils-full}/share/man/man1/* $out/share/man/man1
166 ''
167 # du: 8.7 M locale + 0.4 M man pages
168 + optionalString minimal ''
169 rm -r "$out/share"
170 '';
171
172 meta = with lib; {
173 homepage = "https://www.gnu.org/software/coreutils/";
174 description = "The GNU Core Utilities";
175 longDescription = ''
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.
179 '';
180 license = licenses.gpl3Plus;
181 maintainers = with maintainers; [ das_j ];
182 platforms = with platforms; unix ++ windows;
183 priority = 10;
184 };
185}