12 , gmpSupport ? true, gmp
13 , aclSupport ? lib.meta.availableOn stdenv.hostPlatform acl, acl
14 , attrSupport ? lib.meta.availableOn stdenv.hostPlatform attr, attr
15 , selinuxSupport ? false, libselinux, libsepol
16 # No openssl in default version, so openssl-induced rebuilds aren't too big.
17 # It makes *sum functions significantly faster.
19 , withOpenssl ? !minimal, openssl
21 , singleBinary ? "symlinks" # you can also pass "shebangs" or false
24 # Note: this package is used for bootstrapping fetchurl, and thus cannot use
25 # fetchpatch! All mutable patches (generated by GitHub or cgit) that are needed
26 # here should be included directly in Nixpkgs as files.
28 assert aclSupport -> acl != null;
29 assert selinuxSupport -> libselinux != null && libsepol != null;
32 inherit (lib) concatStringsSep isString optional optionalAttrs optionals optionalString;
33 isCross = (stdenv.hostPlatform != stdenv.buildPlatform);
35 stdenv.mkDerivation rec {
36 pname = "coreutils" + (optionalString (!minimal) "-full");
40 url = "mirror://gnu/coreutils/coreutils-${version}.tar.xz";
41 hash = "sha256-zTKO3qyS9qZl3p8yPJO3Eq8YWLwuDYjz9xAEaUcKG4o=";
45 # https://lists.gnu.org/archive/html/bug-coreutils/2024-05/msg00037.html
46 # This is not precisely the patch provided - this is a diff of the Makefile.in
47 # after the patch was applied and autoreconf was run, since adding autoreconf
48 # here causes infinite recursion.
49 ./fix-mix-flags-deps-libintl.patch
50 ] ++ lib.optionals stdenv.hostPlatform.isMusl [
51 # https://lists.gnu.org/archive/html/bug-coreutils/2024-03/msg00089.html
52 ./fix-test-failure-musl.patch
56 # The test tends to fail on btrfs, f2fs and maybe other unusual filesystems.
57 sed '2i echo Skipping dd sparse test && exit 77' -i ./tests/dd/sparse.sh
58 sed '2i echo Skipping du threshold test && exit 77' -i ./tests/du/threshold.sh
59 sed '2i echo Skipping cp reflink-auto test && exit 77' -i ./tests/cp/reflink-auto.sh
60 sed '2i echo Skipping cp sparse test && exit 77' -i ./tests/cp/sparse.sh
61 sed '2i echo Skipping env test && exit 77' -i ./tests/env/env.sh
62 sed '2i echo Skipping rm deep-2 test && exit 77' -i ./tests/rm/deep-2.sh
63 sed '2i echo Skipping du long-from-unreadable test && exit 77' -i ./tests/du/long-from-unreadable.sh
65 # The test tends to fail on cephfs
66 sed '2i echo Skipping df total-verify test && exit 77' -i ./tests/df/total-verify.sh
68 # Some target platforms, especially when building inside a container have
69 # issues with the inotify test.
70 sed '2i echo Skipping tail inotify dir recreate test && exit 77' -i ./tests/tail/inotify-dir-recreate.sh
72 # sandbox does not allow setgid
73 sed '2i echo Skipping chmod setgid test && exit 77' -i ./tests/chmod/setgid.sh
74 substituteInPlace ./tests/install/install-C.sh \
75 --replace 'mode3=2755' 'mode3=1755'
77 # Fails on systems with a rootfs. Looks like a bug in the test, see
78 # https://lists.gnu.org/archive/html/bug-coreutils/2019-12/msg00000.html
79 sed '2i print "Skipping df skip-rootfs test"; exit 77' -i ./tests/df/skip-rootfs.sh
81 # these tests fail in the unprivileged nix sandbox (without nix-daemon) as we break posix assumptions
82 for f in ./tests/chgrp/{basic.sh,recurse.sh,default-no-deref.sh,no-x.sh,posix-H.sh}; do
83 sed '2i echo Skipping chgrp && exit 77' -i "$f"
85 for f in gnulib-tests/{test-chown.c,test-fchownat.c,test-lchown.c}; do
86 echo "int main() { return 77; }" > "$f"
89 # We don't have localtime in the sandbox
90 for f in gnulib-tests/{test-localtime_r.c,test-localtime_r-mt.c}; do
91 echo "int main() { return 77; }" > "$f"
94 # intermittent failures on builders, unknown reason
95 sed '2i echo Skipping du basic test && exit 77' -i ./tests/du/basic.sh
96 '' + (optionalString (stdenv.hostPlatform.libc == "musl") (concatStringsSep "\n" [
98 echo "int main() { return 77; }" > gnulib-tests/test-parse-datetime.c
99 echo "int main() { return 77; }" > gnulib-tests/test-getlogin.c
101 ])) + (optionalString stdenv.hostPlatform.isAarch64 ''
102 # Sometimes fails: https://github.com/NixOS/nixpkgs/pull/143097#issuecomment-954462584
103 sed '2i echo Skipping cut huge range test && exit 77' -i ./tests/cut/cut-huge-range.sh
106 outputs = [ "out" "info" ];
107 separateDebugInfo = true;
109 nativeBuildInputs = [
113 ++ optionals stdenv.hostPlatform.isCygwin [
120 ++ optional aclSupport acl
121 ++ optional attrSupport attr
122 ++ optional gmpSupport gmp
123 ++ optional withOpenssl openssl
124 ++ optionals selinuxSupport [ libselinux libsepol ]
125 # TODO(@Ericson2314): Investigate whether Darwin could benefit too
126 ++ optional (isCross && stdenv.hostPlatform.libc != "glibc") libiconv;
128 hardeningDisable = [ "trivialautovarinit" ];
130 configureFlags = [ "--with-packager=https://nixos.org" ]
131 ++ optional (singleBinary != false)
132 ("--enable-single-binary" + optionalString (isString singleBinary) "=${singleBinary}")
133 ++ optional withOpenssl "--with-openssl"
134 ++ optional stdenv.hostPlatform.isSunOS "ac_cv_func_inotify_init=no"
135 ++ optional withPrefix "--program-prefix=g"
136 # the shipped configure script doesn't enable nls, but using autoreconfHook
137 # does so which breaks the build
138 ++ optional stdenv.hostPlatform.isDarwin "--disable-nls"
139 ++ optionals (isCross && stdenv.hostPlatform.libc == "glibc") [
140 # TODO(19b98110126fde7cbb1127af7e3fe1568eacad3d): Needed for fstatfs() I
141 # don't know why it is not properly detected cross building with glibc.
142 "fu_cv_sys_stat_statfs2_bsize=yes"
144 # /proc/uptime is available on Linux and produces accurate results even if
145 # the boot time is set to the epoch because the system has no RTC. We
146 # explicitly enable it for cases where it can't be detected automatically,
147 # such as when cross-compiling.
148 ++ optional stdenv.hostPlatform.isLinux "gl_cv_have_proc_uptime=yes";
150 # The tests are known broken on Cygwin
151 # (http://article.gmane.org/gmane.comp.gnu.core-utils.bugs/19025),
152 # Darwin (http://article.gmane.org/gmane.comp.gnu.core-utils.bugs/19351),
153 # and {Open,Free}BSD.
154 # With non-standard storeDir: https://github.com/NixOS/nix/issues/512
156 && (stdenv.hostPlatform.libc == "glibc" || stdenv.hostPlatform.libc == "musl")
157 && !stdenv.hostPlatform.isAarch32;
159 # Prevents attempts of running 'help2man' on cross-built binaries.
160 PERL = if isCross then "missing" else null;
162 enableParallelBuilding = true;
164 NIX_LDFLAGS = optionalString selinuxSupport "-lsepol";
165 FORCE_UNSAFE_CONFIGURE = optionalString stdenv.hostPlatform.isSunOS "1";
166 env.NIX_CFLAGS_COMPILE = toString ([]
167 # Work around a bogus warning in conjunction with musl.
168 ++ optional stdenv.hostPlatform.isMusl "-Wno-error"
169 ++ optional stdenv.hostPlatform.isAndroid "-D__USE_FORTIFY_LEVEL=0");
171 # Works around a bug with 8.26:
172 # Makefile:3440: *** Recursive variable 'INSTALL' references itself (eventually). Stop.
173 preInstall = optionalString isCross ''
174 sed -i Makefile -e 's|^INSTALL =.*|INSTALL = ${buildPackages.coreutils}/bin/install -c|'
177 postInstall = optionalString (isCross && !minimal) ''
178 rm $out/share/man/man1/*
179 cp ${buildPackages.coreutils-full}/share/man/man1/* $out/share/man/man1
181 # du: 8.7 M locale + 0.4 M man pages
182 + optionalString minimal ''
186 passthru = {} // optionalAttrs (singleBinary != false) {
187 # everything in the single binary gets the same verdict, so we
188 # override _that case_ with verdicts from separate binaries.
190 # binlore only spots exec in runcon on some platforms (i.e., not
191 # darwin; see comment on inverse case below)
192 binlore.out = binlore.synthesize coreutils ''
193 execer can bin/{chroot,env,install,nice,nohup,runcon,sort,split,stdbuf,timeout}
194 execer cannot bin/{[,b2sum,base32,base64,basename,basenc,cat,chcon,chgrp,chmod,chown,cksum,comm,cp,csplit,cut,date,dd,df,dir,dircolors,dirname,du,echo,expand,expr,factor,false,fmt,fold,groups,head,hostid,id,join,kill,link,ln,logname,ls,md5sum,mkdir,mkfifo,mknod,mktemp,mv,nl,nproc,numfmt,od,paste,pathchk,pinky,pr,printenv,printf,ptx,pwd,readlink,realpath,rm,rmdir,seq,sha1sum,sha224sum,sha256sum,sha384sum,sha512sum,shred,shuf,sleep,stat,stty,sum,sync,tac,tail,tee,test,touch,tr,true,truncate,tsort,tty,uname,unexpand,uniq,unlink,uptime,users,vdir,wc,who,whoami,yes}
196 } // optionalAttrs (singleBinary == false) {
197 # binlore only spots exec in runcon on some platforms (i.e., not
198 # darwin; I have a note that the behavior may need selinux?).
199 # hard-set it so people working on macOS don't miss cases of
200 # runcon until ofBorg fails.
201 binlore.out = binlore.synthesize coreutils ''
202 execer can bin/runcon
207 homepage = "https://www.gnu.org/software/coreutils/";
208 description = "GNU Core Utilities";
210 The GNU Core Utilities are the basic file, shell and text manipulation
211 utilities of the GNU operating system. These are the core utilities which
212 are expected to exist on every operating system.
214 license = licenses.gpl3Plus;
215 maintainers = with maintainers; [ das_j ];
216 platforms = with platforms; unix ++ windows;