nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 stdenv,
4 fetchurl,
5 fetchpatch,
6 perl,
7 # Update the enabled crypt scheme ids in passthru when the enabled hashes change
8 enableHashes ? "strong",
9 nixosTests,
10 runCommand,
11 python3,
12}:
13
14stdenv.mkDerivation (finalAttrs: {
15 pname = "libxcrypt";
16 version = "4.5.2";
17
18 src = fetchurl {
19 url = "https://github.com/besser82/libxcrypt/releases/download/v${finalAttrs.version}/libxcrypt-${finalAttrs.version}.tar.xz";
20 hash = "sha256-cVE6McAaQovM1TZ6Mv2V8RXW2sUPtbYMd51ceUKuwHE=";
21 };
22
23 patches = [
24 # https://github.com/besser82/libxcrypt/pull/221
25 ./fix-symver-on-non-elf.patch
26 ];
27
28 # this could be accomplished by updateAutotoolsGnuConfigScriptsHook, but that causes infinite recursion
29 # necessary for FreeBSD code path in configure
30 postPatch = ''
31 substituteInPlace ./build-aux/m4-autogen/config.guess --replace-fail /usr/bin/uname uname
32 '';
33
34 outputs = [
35 "out"
36 "man"
37 ];
38
39 configureFlags = [
40 "--enable-hashes=${enableHashes}"
41 "--enable-obsolete-api=glibc"
42 "--disable-failure-tokens"
43 # required for musl, android, march=native
44 "--disable-werror"
45 ]
46 ++ lib.optional stdenv.hostPlatform.isCygwin "--disable-symvers";
47
48 makeFlags =
49 let
50 lld17Plus = stdenv.cc.bintools.isLLVM && lib.versionAtLeast stdenv.cc.bintools.version "17";
51 in
52 [ ]
53 # fixes: can't build x86_64-w64-mingw32 shared library unless -no-undefined is specified
54 ++ lib.optionals stdenv.hostPlatform.isPE [ "LDFLAGS+=-no-undefined" ]
55
56 # lld 17 sets `--no-undefined-version` by default and `libxcrypt`'s
57 # version script unconditionally lists legacy compatibility symbols, even
58 # when not exported: https://github.com/besser82/libxcrypt/issues/181
59 ++ lib.optionals lld17Plus [ "LDFLAGS+=-Wl,--undefined-version" ];
60
61 nativeBuildInputs = [
62 perl
63 ];
64
65 enableParallelBuilding = true;
66
67 doCheck = true;
68
69 passthru = {
70 tests = {
71 inherit (nixosTests) login shadow;
72
73 passthruMatches = runCommand "libxcrypt-test-passthru-matches" { } ''
74 ${python3.interpreter} "${./check_passthru_matches.py}" ${
75 lib.escapeShellArgs (
76 [
77 finalAttrs.src
78 enableHashes
79 "--"
80 ]
81 ++ finalAttrs.passthru.enabledCryptSchemeIds
82 )
83 }
84 touch "$out"
85 '';
86 };
87 enabledCryptSchemeIds = [
88 # https://github.com/besser82/libxcrypt/blob/v4.5.0/lib/hashes.conf
89 "y" # yescrypt
90 "gy" # gost_yescrypt
91 "sm3y" # sm3_yescrypt
92 "7" # scrypt
93 "2b" # bcrypt
94 "2y" # bcrypt_y
95 "2a" # bcrypt_a
96 "6" # sha512crypt
97 ];
98 };
99
100 meta = {
101 changelog = "https://github.com/besser82/libxcrypt/blob/v${finalAttrs.version}/NEWS";
102 description = "Extended crypt library for descrypt, md5crypt, bcrypt, and others";
103 homepage = "https://github.com/besser82/libxcrypt/";
104 platforms = lib.platforms.all;
105 maintainers = with lib.maintainers; [
106 dottedmag
107 hexa
108 ];
109 license = lib.licenses.lgpl21Plus;
110 };
111})