1{ lib, stdenv, fetchurl, libxcrypt, withoutInitTools ? false }:
2
3stdenv.mkDerivation rec {
4 pname = if withoutInitTools then "sysvtools" else "sysvinit";
5 version = "3.04";
6
7 src = fetchurl {
8 url = "mirror://savannah/sysvinit/sysvinit-${version}.tar.xz";
9 sha256 = "sha256-KmIf5uRSi8kTCLdIZ92q6733dT8COVwMW66Be9K346U=";
10 };
11
12 prePatch = ''
13 # Patch some minimal hard references, so halt/shutdown work
14 sed -i -e "s,/sbin/,$out/sbin/," src/halt.c src/init.c src/paths.h
15 '';
16
17 buildInputs = [ libxcrypt ];
18
19 makeFlags = [ "SULOGINLIBS=-lcrypt" "ROOT=$(out)" "MANDIR=/share/man" ];
20
21 preInstall =
22 ''
23 substituteInPlace src/Makefile --replace /usr /
24 '';
25
26 postInstall = ''
27 mv $out/sbin/killall5 $out/bin
28 ln -sf killall5 $out/bin/pidof
29 ''
30 + lib.optionalString withoutInitTools
31 ''
32 shopt -s extglob
33 rm -rf $out/sbin/!(sulogin)
34 rm -rf $out/include
35 rm -rf $out/share/man/man5
36 rm $(for i in $out/share/man/man8/*; do echo $i; done | grep -v 'pidof\|killall5')
37 rm $out/bin/wall $out/share/man/man1/wall.1
38 '';
39
40 meta = {
41 homepage = "https://www.nongnu.org/sysvinit/";
42 description = "Utilities related to booting and shutdown";
43 platforms = lib.platforms.linux;
44 license = lib.licenses.gpl2Plus;
45 };
46}