summary refs log tree commit diff
path: root/pkgs/tools/security/rng-tools/default.nix
blob: bd289200fe80157766f685ea56786f70adaf191c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
{ stdenv, fetchFromGitHub, libtool, autoreconfHook, pkgconfig
, sysfsutils
, argp-standalone
  # WARNING: DO NOT USE BEACON GENERATED VALUES AS SECRET CRYPTOGRAPHIC KEYS
  # https://www.nist.gov/programs-projects/nist-randomness-beacon
, curl ? null, libxml2 ? null, openssl ? null, withNistBeacon ? false
  # Systems that support RDRAND but not AES-NI require libgcrypt to use RDRAND as an entropy source
, libgcrypt ? null, withGcrypt ? true
, jitterentropy ? null, withJitterEntropy ? true
, libp11 ? null, opensc ? null, withPkcs11 ? true
}:

with stdenv.lib;

stdenv.mkDerivation rec {
  pname = "rng-tools";
  version = "6.9";

  src = fetchFromGitHub {
    owner = "nhorman";
    repo = "rng-tools";
    rev = "v${version}";
    sha256 = "065jf26s8zkicb95zc9ilksjdq9gqrh5vcx3mhi6mypbnamn6w98";
  };

  postPatch = ''
    ${optionalString withPkcs11 ''
      substituteInPlace rngd.c \
        --replace /usr/lib64/opensc-pkcs11.so ${opensc}/lib/opensc-pkcs11.so
    ''}
  '';

  nativeBuildInputs = [ autoreconfHook libtool pkgconfig ];

  configureFlags = [
    (withFeature   withGcrypt        "libgcrypt")
    (enableFeature withJitterEntropy "jitterentropy")
    (withFeature   withNistBeacon    "nistbeacon")
    (withFeature   withPkcs11        "pkcs11")
  ];

  # argp-standalone is only used when libc lacks argp parsing (musl)
  buildInputs = [ sysfsutils ]
    ++ optionals stdenv.hostPlatform.isx86_64 [ argp-standalone ]
    ++ optionals withGcrypt        [ libgcrypt ]
    ++ optionals withJitterEntropy [ jitterentropy ]
    ++ optionals withNistBeacon    [ curl libxml2 openssl ]
    ++ optionals withPkcs11        [ libp11 openssl ];

  enableParallelBuilding = true;

  # For cross-compilation
  makeFlags = [ "AR:=$(AR)" ];

  doCheck = true;
  preCheck = "patchShebangs tests/*.sh";

  meta = {
    description = "A random number generator daemon";
    homepage = https://github.com/nhorman/rng-tools;
    license = licenses.gpl2Plus;
    platforms = platforms.linux;
    maintainers = with maintainers; [ johnazoidberg c0bw3b ];
  };
}