2014-04-14 16:26:48 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
2014-03-13 00:32:34 +01:00
|
|
|
|
2014-04-14 16:26:48 +02:00
|
|
|
with lib;
|
2014-03-13 00:32:34 +01:00
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.services.solr;
|
|
|
|
|
2018-11-03 18:14:13 +01:00
|
|
|
in
|
2014-03-13 00:32:34 +01:00
|
|
|
|
2018-11-03 18:14:13 +01:00
|
|
|
{
|
2014-03-13 00:32:34 +01:00
|
|
|
options = {
|
|
|
|
services.solr = {
|
2019-04-20 03:41:48 +02:00
|
|
|
enable = mkEnableOption "Solr";
|
2014-03-13 00:32:34 +01:00
|
|
|
|
2018-11-03 18:14:13 +01:00
|
|
|
package = mkOption {
|
2014-03-13 00:32:34 +01:00
|
|
|
type = types.package;
|
2020-01-18 14:31:43 +01:00
|
|
|
default = pkgs.solr;
|
2021-10-03 18:06:03 +02:00
|
|
|
defaultText = literalExpression "pkgs.solr";
|
2020-01-18 14:31:43 +01:00
|
|
|
description = "Which Solr package to use.";
|
2014-03-13 00:32:34 +01:00
|
|
|
};
|
|
|
|
|
2018-11-03 18:14:13 +01:00
|
|
|
port = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 8983;
|
|
|
|
description = "Port on which Solr is ran.";
|
2014-04-03 22:46:45 +02:00
|
|
|
};
|
|
|
|
|
2018-11-03 18:14:13 +01:00
|
|
|
stateDir = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
default = "/var/lib/solr";
|
|
|
|
description = "The solr home directory containing config, data, and logging files.";
|
2014-03-13 00:32:34 +01:00
|
|
|
};
|
|
|
|
|
2018-11-03 18:14:13 +01:00
|
|
|
extraJavaOptions = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [];
|
|
|
|
description = "Extra command line options given to the java process running Solr.";
|
2014-03-13 00:32:34 +01:00
|
|
|
};
|
|
|
|
|
2018-11-03 18:14:13 +01:00
|
|
|
user = mkOption {
|
2014-03-13 00:32:34 +01:00
|
|
|
type = types.str;
|
2018-11-03 18:14:13 +01:00
|
|
|
default = "solr";
|
|
|
|
description = "User under which Solr is ran.";
|
2014-03-13 00:32:34 +01:00
|
|
|
};
|
|
|
|
|
2018-11-03 18:14:13 +01:00
|
|
|
group = mkOption {
|
2014-03-13 00:32:34 +01:00
|
|
|
type = types.str;
|
2018-11-03 18:14:13 +01:00
|
|
|
default = "solr";
|
|
|
|
description = "Group under which Solr is ran.";
|
2014-03-13 00:32:34 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
2018-11-03 18:14:13 +01:00
|
|
|
environment.systemPackages = [ cfg.package ];
|
|
|
|
|
|
|
|
systemd.services.solr = {
|
|
|
|
after = [ "network.target" "remote-fs.target" "nss-lookup.target" "systemd-journald-dev-log.socket" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
|
|
|
environment = {
|
|
|
|
SOLR_HOME = "${cfg.stateDir}/data";
|
|
|
|
LOG4J_PROPS = "${cfg.stateDir}/log4j2.xml";
|
|
|
|
SOLR_LOGS_DIR = "${cfg.stateDir}/logs";
|
|
|
|
SOLR_PORT = "${toString cfg.port}";
|
|
|
|
};
|
|
|
|
path = with pkgs; [
|
|
|
|
gawk
|
|
|
|
procps
|
|
|
|
];
|
|
|
|
preStart = ''
|
|
|
|
mkdir -p "${cfg.stateDir}/data";
|
|
|
|
mkdir -p "${cfg.stateDir}/logs";
|
|
|
|
|
|
|
|
if ! test -e "${cfg.stateDir}/data/solr.xml"; then
|
|
|
|
install -D -m0640 ${cfg.package}/server/solr/solr.xml "${cfg.stateDir}/data/solr.xml"
|
|
|
|
install -D -m0640 ${cfg.package}/server/solr/zoo.cfg "${cfg.stateDir}/data/zoo.cfg"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ! test -e "${cfg.stateDir}/log4j2.xml"; then
|
|
|
|
install -D -m0640 ${cfg.package}/server/resources/log4j2.xml "${cfg.stateDir}/log4j2.xml"
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
User = cfg.user;
|
|
|
|
Group = cfg.group;
|
|
|
|
ExecStart="${cfg.package}/bin/solr start -f -a \"${concatStringsSep " " cfg.extraJavaOptions}\"";
|
|
|
|
ExecStop="${cfg.package}/bin/solr stop";
|
|
|
|
};
|
2014-03-13 00:32:34 +01:00
|
|
|
};
|
|
|
|
|
2019-09-14 19:51:29 +02:00
|
|
|
users.users = optionalAttrs (cfg.user == "solr") {
|
|
|
|
solr = {
|
2018-11-03 18:14:13 +01:00
|
|
|
group = cfg.group;
|
|
|
|
home = cfg.stateDir;
|
|
|
|
createHome = true;
|
|
|
|
uid = config.ids.uids.solr;
|
2019-09-14 19:51:29 +02:00
|
|
|
};
|
|
|
|
};
|
2018-11-03 18:14:13 +01:00
|
|
|
|
2019-09-14 19:51:29 +02:00
|
|
|
users.groups = optionalAttrs (cfg.group == "solr") {
|
|
|
|
solr.gid = config.ids.gids.solr;
|
|
|
|
};
|
2018-11-03 18:14:13 +01:00
|
|
|
|
2014-03-13 00:32:34 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|