1{ lib, stdenv, nixosTests, fetchpatch, fetchFromGitHub, autoreconfHook, libxslt
2, libxml2 , docbook_xml_dtd_45, docbook_xsl, itstool, flex, bison, runtimeShell
3, pam ? null, glibcCross ? null
4}:
5
6let
7
8 glibc =
9 if stdenv.hostPlatform != stdenv.buildPlatform
10 then glibcCross
11 else assert stdenv.hostPlatform.libc == "glibc"; stdenv.cc.libc;
12
13 dots_in_usernames = fetchpatch {
14 url = "http://sources.gentoo.org/cgi-bin/viewvc.cgi/gentoo-x86/sys-apps/shadow/files/shadow-4.1.3-dots-in-usernames.patch";
15 sha256 = "1fj3rg6x3jppm5jvi9y7fhd2djbi4nc5pgwisw00xlh4qapgz692";
16 };
17
18in
19
20stdenv.mkDerivation rec {
21 pname = "shadow";
22 version = "4.8.1";
23
24 src = fetchFromGitHub {
25 owner = "shadow-maint";
26 repo = "shadow";
27 rev = version;
28 sha256 = "13407r6qwss00504qy740jghb2dzd561la7dhp47rg8w3g8jarpn";
29 };
30
31 buildInputs = lib.optional (pam != null && stdenv.isLinux) pam;
32 nativeBuildInputs = [autoreconfHook libxslt libxml2
33 docbook_xml_dtd_45 docbook_xsl flex bison itstool
34 ];
35
36 patches =
37 [ ./keep-path.patch
38 # Obtain XML resources from XML catalog (patch adapted from gtk-doc)
39 ./respect-xml-catalog-files-var.patch
40 dots_in_usernames
41 ./runtime-shell.patch
42 ];
43
44 RUNTIME_SHELL = runtimeShell;
45
46 # The nix daemon often forbids even creating set[ug]id files.
47 postPatch =
48 ''sed 's/^\(s[ug]idperms\) = [0-9]755/\1 = 0755/' -i src/Makefile.am
49 '';
50
51 outputs = [ "out" "su" "man" ];
52
53 enableParallelBuilding = true;
54
55 # Assume System V `setpgrp (void)', which is the default on GNU variants
56 # (`AC_FUNC_SETPGRP' is not cross-compilation capable.)
57 preConfigure = ''
58 export ac_cv_func_setpgrp_void=yes
59 export shadow_cv_logdir=/var/log
60 '';
61
62 configureFlags = [
63 "--enable-man"
64 "--with-group-name-max-length=32"
65 ] ++ lib.optional (stdenv.hostPlatform.libc != "glibc") "--disable-nscd";
66
67 preBuild = lib.optionalString (stdenv.hostPlatform.libc == "glibc")
68 ''
69 substituteInPlace lib/nscd.c --replace /usr/sbin/nscd ${glibc.bin}/bin/nscd
70 '';
71
72 postInstall =
73 ''
74 # Don't install ‘groups’, since coreutils already provides it.
75 rm $out/bin/groups
76 rm $man/share/man/man1/groups.*
77
78 # Move the su binary into the su package
79 mkdir -p $su/bin
80 mv $out/bin/su $su/bin
81 '';
82
83 disallowedReferences = lib.optional (stdenv.buildPlatform != stdenv.hostPlatform) stdenv.shellPackage;
84
85 meta = with lib; {
86 homepage = "https://github.com/shadow-maint";
87 description = "Suite containing authentication-related tools such as passwd and su";
88 license = licenses.bsd3;
89 platforms = platforms.linux;
90 };
91
92 passthru = {
93 shellPath = "/bin/nologin";
94 tests = { inherit (nixosTests) shadow; };
95 };
96}