summaryrefslogtreecommitdiffstats
path: root/pkgs/by-name/un/unit/package.nix
blob: a473dee2e1d57cf9f0016c4c5bc1a01641d20d5d (plain)
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
{
  lib,
  stdenv,
  fetchFromGitHub,
  nixosTests,
  which,
  pcre2,
  withPython3 ? true,
  python3,
  ncurses,
  withPHP82 ? true,
  php82,
  withPerl ? true,
  perl,
  withSSL ? true,
  openssl ? null,
  withIPv6 ? true,
  withDebug ? false,
}:

let
  phpConfig = {
    embedSupport = true;
    apxs2Support = false;
    systemdSupport = false;
    phpdbgSupport = false;
    cgiSupport = false;
    fpmSupport = false;
  };

  php82-unit = php82.override phpConfig;

  inherit (lib) optional optionals optionalString;
in
stdenv.mkDerivation (finalAttrs: {
  version = "1.35.0";
  pname = "unit";

  src = fetchFromGitHub {
    owner = "nginx";
    repo = "unit";
    rev = finalAttrs.version;
    sha256 = "sha256-0cMtU7wmy8GFKqxS8fXPIrMljYXBHzoxrUJCOJSzLMA=";
  };

  nativeBuildInputs = [ which ];

  buildInputs = [
    pcre2.dev
  ]
  ++ optionals withPython3 [
    python3
    ncurses
  ]
  ++ optional withPHP82 php82-unit
  ++ optional withPerl perl
  ++ optional withSSL openssl;

  configureFlags = [
    "--control=unix:/run/unit/control.unit.sock"
    "--pid=/run/unit/unit.pid"
    "--user=unit"
    "--group=unit"
  ]
  ++ optional withSSL "--openssl"
  ++ optional (!withIPv6) "--no-ipv6"
  ++ optional withDebug "--debug";

  # Optionally add the PHP derivations used so they can be addressed in the configs
  usedPhp82 = optionals withPHP82 php82-unit;

  postConfigure = ''
    ${optionalString withPython3 "./configure python --module=python3  --config=python3-config  --lib-path=${python3}/lib"}
    ${optionalString withPHP82 "./configure php    --module=php82    --config=${php82-unit.unwrapped.dev}/bin/php-config --lib-path=${php82-unit}/lib"}
    ${optionalString withPerl "./configure perl   --module=perl     --perl=${perl}/bin/perl"}
  '';

  env.NIX_CFLAGS_COMPILE = toString [
    # 'EVP_PKEY_asn1_find_str' is deprecated since OpenSSL 3.6
    "-Wno-error=deprecated-declarations"
  ];

  passthru.tests = {
    unit-perl = nixosTests.unit-perl;
    unit-php = nixosTests.unit-php;
  };

  meta = {
    description = "Dynamic web and application server, designed to run applications in multiple languages";
    mainProgram = "unitd";
    homepage = "https://unit.nginx.org/";
    license = lib.licenses.asl20;
    platforms = lib.platforms.linux;
    maintainers = with lib.maintainers; [ izorkin ];
  };
})