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.30";
8 patchVersion = "";
9
10 fstrimPatch = fetchpatch {
11 url = "https://git.kernel.org/pub/scm/utils/util-linux/util-linux.git/patch/?id=155d48f590a50bb5dc265162ff2f9a971daed543";
12 sha256 = "1wj0fj3iwaimr6p8wxg6l2i1hjyrfgcwcxziyxqz8acxba7k6zxh";
13 };
14in stdenv.mkDerivation rec {
15 name = "util-linux-${version}";
16
17 src = fetchurl {
18 url = "mirror://kernel/linux/utils/util-linux/v${majorVersion}/${name}.tar.xz";
19 sha256 = "13d0ax8bcapga8phj2nclx86w57ddqxbr98ajibpzjq6d7zs8262";
20 };
21
22 patches = [
23 ./rtcwake-search-PATH-for-shutdown.patch
24 fstrimPatch
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}