summary refs log tree commit diff
path: root/nixos/modules/services/search/solr.nix
blob: 90140a337ed8c509da9472f05cfc382327413a29 (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
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
{ config, lib, pkgs, ... }:

with lib;

let

  cfg = config.services.solr;

  # Assemble all jars needed for solr
  solrJars = pkgs.stdenv.mkDerivation {
    name = "solr-jars";

    src = pkgs.fetchurl {
      url = http://archive.apache.org/dist/tomcat/tomcat-5/v5.5.36/bin/apache-tomcat-5.5.36.tar.gz;
      sha256 = "01mzvh53wrs1p2ym765jwd00gl6kn8f9k3nhdrnhdqr8dhimfb2p";
    };

    installPhase = ''
      mkdir -p $out/lib
      cp common/lib/*.jar $out/lib/
      ln -s ${pkgs.ant}/lib/ant/lib/ant.jar $out/lib/
      ln -s ${cfg.solrPackage}/lib/ext/* $out/lib/
      ln -s ${pkgs.jdk.home}/lib/tools.jar $out/lib/
    '' + optionalString (cfg.extraJars != []) ''
      for f in ${concatStringsSep " " cfg.extraJars}; do
         cp $f $out/lib
      done
    '';
  };

in {

  options = {
    services.solr = {
      enable = mkOption {
        type = types.bool;
        default = false;
        description = ''
          Enables the solr service.
        '';
      };

      javaPackage = mkOption {
        type = types.package;
        default = pkgs.jre;
        defaultText = "pkgs.jre";
        description = ''
          Which Java derivation to use for running solr.
        '';
      };

      solrPackage = mkOption {
        type = types.package;
        default = pkgs.solr;
        defaultText = "pkgs.solr";
        description = ''
          Which solr derivation to use for running solr.
        '';
      };

      extraJars = mkOption {
        type = types.listOf types.path;
        default = [];
        description = ''
          List of paths pointing to jars. Jars are copied to commonLibFolder to be available to java/solr.
        '';
      };

      log4jConfiguration = mkOption {
        type = types.lines;
        default = ''
          log4j.rootLogger=INFO, stdout
          log4j.appender.stdout=org.apache.log4j.ConsoleAppender
          log4j.appender.stdout.Target=System.out
          log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
          log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
        '';
        description = ''
          Contents of the <literal>log4j.properties</literal> used. By default,
          everything is logged to stdout (picked up by systemd) with level INFO.
        '';
      };

      user = mkOption {
        type = types.str;
        description = ''
          The user that should run the solr process and.
          the working directories.
        '';
      };

      group = mkOption {
        type = types.str;
        description = ''
          The group that will own the working directory.
        '';
      };

      solrHome = mkOption {
        type = types.str;
        description = ''
          The solr home directory. It is your own responsibility to
          make sure this directory contains a working solr configuration,
          and is writeable by the the user running the solr service.
          Failing to do so, the solr will not start properly.
        '';
      };

      extraJavaOptions = mkOption {
        type = types.listOf types.str;
        default = [];
        description = ''
          Extra command line options given to the java process running
          solr.
        '';
      };

      extraWinstoneOptions = mkOption {
        type = types.listOf types.str;
        default = [];
        description = ''
          Extra command line options given to the Winstone, which is
          the servlet container hosting solr.
        '';
      };
    };
  };

  config = mkIf cfg.enable {

    services.winstone.solr = {
      serviceName = "solr";
      inherit (cfg) user group javaPackage;
      warFile = "${cfg.solrPackage}/lib/solr.war";
      extraOptions = [
        "--commonLibFolder=${solrJars}/lib"
        "--useJasper"
      ] ++ cfg.extraWinstoneOptions;
      extraJavaOptions = [
        "-Dsolr.solr.home=${cfg.solrHome}"
        "-Dlog4j.configuration=file://${pkgs.writeText "log4j.properties" cfg.log4jConfiguration}"
      ] ++ cfg.extraJavaOptions;
    };

  };

}