1{ lib, stdenv, fetchurl, pkgconfig, zlib, fetchpatch, shadow
2, ncurses ? null, perl ? null, pam, systemd, minimal ? false }:
3
4let
5 version = lib.concatStringsSep "." ([ majorVersion ]
6 ++ lib.optional (patchVersion != "") patchVersion);
7 majorVersion = "2.31";
8 patchVersion = "1";
9
10in stdenv.mkDerivation rec {
11 name = "util-linux-${version}";
12
13 src = fetchurl {
14 url = "mirror://kernel/linux/utils/util-linux/v${majorVersion}/${name}.tar.xz";
15 sha256 = "04fzrnrr3pvqskvjn9f81y0knh0jvvqx4lmbz5pd4lfdm5pv2l8s";
16 };
17
18 patches = [
19 ./rtcwake-search-PATH-for-shutdown.patch
20 (fetchpatch {
21 name = "CVE-2018-7738.diff";
22 url = "https://github.com/karelzak/util-linux/commit/75f03badd7ed9.diff";
23 sha256 = "0b8x1s7b9bh9p8a99bpdgjbqzqwsvb7l7cf3yy83jip1c38p685w";
24 })
25 ];
26
27 outputs = [ "bin" "dev" "out" "man" ];
28
29 postPatch = ''
30 substituteInPlace include/pathnames.h \
31 --replace "/bin/login" "${shadow}/bin/login"
32 substituteInPlace sys-utils/eject.c \
33 --replace "/bin/umount" "$out/bin/umount"
34 '';
35
36 crossAttrs = {
37 # Work around use of `AC_RUN_IFELSE'.
38 preConfigure = "export scanf_cv_type_modifier=ms";
39 };
40
41 preConfigure = lib.optionalString (systemd != null) ''
42 configureFlags+=" --with-systemd --with-systemdsystemunitdir=$bin/lib/systemd/system/"
43 '';
44
45 # !!! It would be better to obtain the path to the mount helpers
46 # (/sbin/mount.*) through an environment variable, but that's
47 # somewhat risky because we have to consider that mount can setuid
48 # root...
49 configureFlags = [
50 "--enable-write"
51 "--enable-last"
52 "--enable-mesg"
53 "--disable-use-tty-group"
54 "--enable-fs-paths-default=/run/wrappers/bin:/var/run/current-system/sw/bin:/sbin"
55 "--disable-makeinstall-setuid" "--disable-makeinstall-chown"
56 ]
57 ++ lib.optional (ncurses == null) "--without-ncurses";
58
59 makeFlags = "usrbin_execdir=$(bin)/bin usrsbin_execdir=$(bin)/sbin";
60
61 nativeBuildInputs = [ pkgconfig ];
62 buildInputs =
63 [ zlib pam ]
64 ++ lib.filter (p: p != null) [ ncurses systemd perl ];
65
66 postInstall = ''
67 rm "$bin/bin/su" # su should be supplied by the su package (shadow)
68 '' + lib.optionalString minimal ''
69 rm -rf $out/share/{locale,doc,bash-completion}
70 '';
71
72 enableParallelBuilding = true;
73
74 meta = with lib; {
75 homepage = https://www.kernel.org/pub/linux/utils/util-linux/;
76 description = "A set of system utilities for Linux";
77 license = licenses.gpl2; # also contains parts under more permissive licenses
78 platforms = platforms.linux;
79 priority = 6; # lower priority than coreutils ("kill") and shadow ("login" etc.) packages
80 };
81}