1{ config, lib, pkgs, ... }:
2
3with lib;
4let
5 cfg = config.services.mantisbt;
6
7 freshInstall = cfg.extraConfig == "";
8
9 # combined code+config directory
10 mantisbt = let
11 config_inc = pkgs.writeText "config_inc.php" ("<?php\n" + cfg.extraConfig);
12 src = pkgs.fetchurl {
13 url = "mirror://sourceforge/mantisbt/${name}.tar.gz";
14 sha256 = "1pl6xn793p3mxc6ibpr2bhg85vkdlcf57yk7pfc399g47l8x4508";
15 };
16 name = "mantisbt-1.2.19";
17 in
18 # We have to copy every time; otherwise config won't be found.
19 pkgs.runCommand name
20 { preferLocalBuild = true; allowSubstitutes = false; }
21 (''
22 mkdir -p "$out"
23 cd "$out"
24 tar -xf '${src}' --strip-components=1
25 ln -s '${config_inc}' config_inc.php
26 ''
27 + lib.optionalString (!freshInstall) "rm -r admin/"
28 );
29in
30{
31 options.services.mantisbt = {
32 enable = mkOption {
33 type = types.bool;
34 default = false;
35 description = ''
36 Enable the mantisbt web service.
37 This switches on httpd with PHP and database.
38 '';
39 };
40 urlPrefix = mkOption {
41 type = types.string;
42 default = "/mantisbt";
43 description = "The URL prefix under which the mantisbt service appears.";
44 };
45 extraConfig = mkOption {
46 type = types.lines;
47 default = "";
48 description = ''
49 The contents of config_inc.php, without leading <?php.
50 If left empty, the admin directory will be accessible.
51 '';
52 };
53 };
54
55
56 config = mkIf cfg.enable {
57 services.mysql.enable = true;
58 services.httpd.enable = true;
59 services.httpd.enablePHP = true;
60 # The httpd sub-service showing mantisbt.
61 services.httpd.extraSubservices = [ { function = { ... }: {
62 extraConfig =
63 ''
64 Alias ${cfg.urlPrefix} "${mantisbt}"
65 '';
66 };}];
67 };
68}