1{ lib, stdenv, fetchurl, perl, xz, gmp ? null
2, aclSupport ? false, acl ? null
3, selinuxSupport? false, libselinux ? null, libsepol ? null
4, autoconf, automake114x, texinfo
5, withPrefix ? false
6, singleBinary ? "symlinks" # you can also pass "shebangs" or false
7}:
8
9assert aclSupport -> acl != null;
10assert selinuxSupport -> libselinux != null && libsepol != null;
11
12with lib;
13
14let
15 self = stdenv.mkDerivation rec {
16 name = "coreutils-8.25";
17
18 src = fetchurl {
19 url = "mirror://gnu/coreutils/${name}.tar.xz";
20 sha256 = "11yfrnb94xzmvi4lhclkcmkqsbhww64wf234ya1aacjvg82prrii";
21 };
22
23 # FIXME needs gcc 4.9 in bootstrap tools
24 hardeningDisable = [ "stackprotector" ];
25
26 patches = optional stdenv.isCygwin ./coreutils-8.23-4.cygwin.patch;
27
28 # The test tends to fail on btrfs and maybe other unusual filesystems.
29 postPatch = optionalString (!stdenv.isDarwin) ''
30 sed '2i echo Skipping dd sparse test && exit 0' -i ./tests/dd/sparse.sh
31 sed '2i echo Skipping cp sparse test && exit 0' -i ./tests/cp/sparse.sh
32 sed '2i echo Skipping rm deep-2 test && exit 0' -i ./tests/rm/deep-2.sh
33 sed '2i echo Skipping du long-from-unreadable test && exit 0' -i ./tests/du/long-from-unreadable.sh
34 '';
35
36 outputs = [ "out" "info" ];
37
38 nativeBuildInputs = [ perl xz.bin ];
39 configureFlags =
40 optional (singleBinary != false)
41 ("--enable-single-binary" + optionalString (isString singleBinary) "=${singleBinary}")
42 ++ optional stdenv.isSunOS "ac_cv_func_inotify_init=no";
43
44 buildInputs = [ gmp ]
45 ++ optional aclSupport acl
46 ++ optionals stdenv.isCygwin [ autoconf automake114x texinfo ] # due to patch
47 ++ optionals selinuxSupport [ libselinux libsepol ];
48
49 crossAttrs = {
50 buildInputs = [ gmp.crossDrv ]
51 ++ optional aclSupport acl.crossDrv
52 ++ optionals selinuxSupport [ libselinux.crossDrv libsepol.crossDrv ]
53 ++ optional (stdenv.ccCross.libc ? libiconv)
54 stdenv.ccCross.libc.libiconv.crossDrv;
55
56 buildPhase = ''
57 make || (
58 pushd man
59 for a in *.x; do
60 touch `basename $a .x`.1
61 done
62 popd; make )
63 '';
64
65 postInstall = ''
66 rm $out/share/man/man1/*
67 cp ${self}/share/man/man1/* $out/share/man/man1
68 '';
69
70 # Needed for fstatfs()
71 # I don't know why it is not properly detected cross building with glibc.
72 configureFlags = [ "fu_cv_sys_stat_statfs2_bsize=yes" ];
73 doCheck = false;
74 };
75
76 # The tests are known broken on Cygwin
77 # (http://thread.gmane.org/gmane.comp.gnu.core-utils.bugs/19025),
78 # Darwin (http://thread.gmane.org/gmane.comp.gnu.core-utils.bugs/19351),
79 # and {Open,Free}BSD.
80 # With non-standard storeDir: https://github.com/NixOS/nix/issues/512
81 doCheck = stdenv ? glibc && builtins.storeDir == "/nix/store";
82
83 # Saw random failures like ‘help2man: can't get '--help' info from
84 # man/sha512sum.td/sha512sum’.
85 enableParallelBuilding = false;
86
87 NIX_LDFLAGS = optionalString selinuxSupport "-lsepol";
88 FORCE_UNSAFE_CONFIGURE = optionalString stdenv.isSunOS "1";
89
90 makeFlags = optionalString stdenv.isDarwin "CFLAGS=-D_FORTIFY_SOURCE=0";
91
92 # e.g. ls -> gls; grep -> ggrep
93 postFixup = optionalString withPrefix
94 ''
95 (
96 cd "$out/bin"
97 find * -type f -executable -exec mv {} g{} \;
98 )
99 '';
100
101 meta = {
102 homepage = http://www.gnu.org/software/coreutils/;
103 description = "The basic file, shell and text manipulation utilities of the GNU operating system";
104
105 longDescription = ''
106 The GNU Core Utilities are the basic file, shell and text
107 manipulation utilities of the GNU operating system. These are
108 the core utilities which are expected to exist on every
109 operating system.
110 '';
111
112 license = licenses.gpl3Plus;
113
114 platforms = platforms.all;
115
116 maintainers = [ maintainers.eelco ];
117 };
118 };
119in
120 self