1{
2 stdenv,
3 lib,
4 fetchFromGitHub,
5 fetchpatch,
6 autoreconfHook,
7 perl,
8 cracklib,
9 enablePAM ? stdenv.hostPlatform.isLinux,
10 pam,
11 enablePython ? false,
12 python3,
13}:
14
15# python binding generates a shared library which are unavailable with musl build
16assert enablePython -> !stdenv.hostPlatform.isStatic;
17
18stdenv.mkDerivation rec {
19 pname = "libpwquality";
20 version = "1.4.5";
21
22 outputs = [
23 "out"
24 "dev"
25 "lib"
26 "man"
27 ] ++ lib.optionals enablePython [ "py" ];
28
29 src = fetchFromGitHub {
30 owner = "libpwquality";
31 repo = "libpwquality";
32 rev = "${pname}-${version}";
33 sha256 = "sha256-YjvHzd4iEBvg+qHOVJ7/y9HqyeT+QDalNE/jdNM9BNs=";
34 };
35
36 patches =
37 lib.optionals (!enablePython) [
38 # this patch isn't useful but keeping it to avoid rebuilds on !enablePython
39 # before 24.11 fully lands
40 ./python-binding-prefix.patch
41 ]
42 ++ [
43 # remove next release
44 (fetchpatch {
45 name = "musl.patch";
46 url = "https://github.com/libpwquality/libpwquality/commit/b0fcd96954be89e8c318e5328dd27c40b401de96.patch";
47 hash = "sha256-ykN1hcRKyX3QAqWTH54kUjOxN6+IwRpqQVsujTd9XWs=";
48 })
49 ]
50 ++ lib.optionals enablePython [
51 # remove next release
52 (fetchpatch {
53 name = "pr-74-use-setuptools-instead-of-distutils.patch";
54 url = "https://github.com/libpwquality/libpwquality/commit/509b0a744adf533b524daaa65f25dda144a6ff40.patch";
55 hash = "sha256-AxiynPVxv/gONujyj8y6b1XlsNkKszzW5TT9oINR/oo=";
56 })
57 # remove next release
58 (fetchpatch {
59 name = "pr-80-respect-pythonsitedir.patch";
60 url = "https://github.com/libpwquality/libpwquality/commit/f92351b3998542e33d2b243fc446a4dd852dc972.patch";
61 hash = "sha256-1lmigZX/UiEFe9b0JXmlfw/371UYT4PF7Ev2Hv66v74=";
62 })
63 # ensure python site-packages goes in $py output
64 ./python-binding-root.patch
65 ];
66
67 nativeBuildInputs = [
68 autoreconfHook
69 perl
70 ] ++ lib.optionals enablePython [ (python3.withPackages (ps: with ps; [ setuptools ])) ];
71 buildInputs = [ cracklib ] ++ lib.optionals enablePAM [ pam ];
72
73 configureFlags =
74 if enablePython then
75 [
76 "--enable-python-bindings=yes"
77 "--with-pythonsitedir=\"${python3.sitePackages}\""
78 ]
79 else
80 # change to `--enable-python-bindings=no` in the future
81 # leave for now to avoid rebuilds on !enablePython before 24.11 fully lands
82 [ "--disable-python-bindings" ];
83
84 meta = with lib; {
85 homepage = "https://github.com/libpwquality/libpwquality";
86 description = "Password quality checking and random password generation library";
87 longDescription = ''
88 The libpwquality library purpose is to provide common functions for
89 password quality checking and also scoring them based on their apparent
90 randomness. The library also provides a function for generating random
91 passwords with good pronounceability. The library supports reading and
92 parsing of a configuration file.
93
94 In the package there are also very simple utilities that use the library
95 function and PAM module that can be used instead of pam_cracklib. The
96 module supports all the options of pam_cracklib.
97 '';
98 license = with licenses; [
99 bsd3
100 # or
101 gpl2Plus
102 ];
103 maintainers = with maintainers; [ jk ];
104 platforms = platforms.unix;
105 };
106}