1{ lib, stdenv, fetchurl, perl
2# Update the enabled crypt scheme ids in passthru when the enabled hashes change
3, enableHashes ? "strong"
4, nixosTests
5, runCommand
6, python3
7}:
8
9stdenv.mkDerivation (finalAttrs: {
10 pname = "libxcrypt";
11 version = "4.4.36";
12
13 src = fetchurl {
14 url = "https://github.com/besser82/libxcrypt/releases/download/v${finalAttrs.version}/libxcrypt-${finalAttrs.version}.tar.xz";
15 hash = "sha256-5eH0yu4KAd4q7ibjE4gH1tPKK45nKHlm0f79ZeH9iUM=";
16 };
17
18 outputs = [
19 "out"
20 "man"
21 ];
22
23 configureFlags = [
24 "--enable-hashes=${enableHashes}"
25 "--enable-obsolete-api=glibc"
26 "--disable-failure-tokens"
27 # required for musl, android, march=native
28 "--disable-werror"
29 ];
30
31 makeFlags = let
32 lld17Plus = stdenv.cc.bintools.isLLVM
33 && lib.versionAtLeast stdenv.cc.bintools.version "17";
34 in []
35 # fixes: can't build x86_64-w64-mingw32 shared library unless -no-undefined is specified
36 ++ lib.optionals stdenv.hostPlatform.isWindows [ "LDFLAGS+=-no-undefined" ]
37
38 # lld 17 sets `--no-undefined-version` by default and `libxcrypt`'s
39 # version script unconditionally lists legacy compatibility symbols, even
40 # when not exported: https://github.com/besser82/libxcrypt/issues/181
41 ++ lib.optionals lld17Plus [ "LDFLAGS+=-Wl,--undefined-version" ]
42 ;
43
44 nativeBuildInputs = [
45 perl
46 ];
47
48 enableParallelBuilding = true;
49
50 doCheck = true;
51
52 passthru = {
53 tests = {
54 inherit (nixosTests) login shadow;
55
56 passthruMatches = runCommand "libxcrypt-test-passthru-matches" { } ''
57 ${python3.interpreter} "${./check_passthru_matches.py}" ${lib.escapeShellArgs ([ finalAttrs.src enableHashes "--" ] ++ finalAttrs.passthru.enabledCryptSchemeIds)}
58 touch "$out"
59 '';
60 };
61 enabledCryptSchemeIds = [
62 # https://github.com/besser82/libxcrypt/blob/v4.4.35/lib/hashes.conf
63 "y" # yescrypt
64 "gy" # gost_yescrypt
65 "7" # scrypt
66 "2b" # bcrypt
67 "2y" # bcrypt_y
68 "2a" # bcrypt_a
69 "6" # sha512crypt
70 ];
71 };
72
73 meta = with lib; {
74 changelog = "https://github.com/besser82/libxcrypt/blob/v${finalAttrs.version}/NEWS";
75 description = "Extended crypt library for descrypt, md5crypt, bcrypt, and others";
76 homepage = "https://github.com/besser82/libxcrypt/";
77 platforms = platforms.all;
78 maintainers = with maintainers; [ dottedmag hexa ];
79 license = licenses.lgpl21Plus;
80 };
81})