2014-04-14 15:26:48 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
2014-03-12 23:32:34 +00:00
|
|
|
|
2014-04-14 15:26:48 +01:00
|
|
|
with lib;
|
2014-03-12 23:32:34 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.services.solr;
|
|
|
|
|
2018-11-03 17:14:13 +00:00
|
|
|
in
|
2014-03-12 23:32:34 +00:00
|
|
|
|
2018-11-03 17:14:13 +00:00
|
|
|
{
|
2014-03-12 23:32:34 +00:00
|
|
|
options = {
|
|
|
|
services.solr = {
|
2019-04-20 02:41:48 +01:00
|
|
|
enable = mkEnableOption "Solr";
|
2014-03-12 23:32:34 +00:00
|
|
|
|
2018-11-03 17:14:13 +00:00
|
|
|
package = mkOption {
|
2014-03-12 23:32:34 +00:00
|
|
|
type = types.package;
|
2020-01-18 13:31:43 +00:00
|
|
|
default = pkgs.solr;
|
2021-10-03 17:06:03 +01:00
|
|
|
defaultText = literalExpression "pkgs.solr";
|
2020-01-18 13:31:43 +00:00
|
|
|
description = "Which Solr package to use.";
|
2014-03-12 23:32:34 +00:00
|
|
|
};
|
|
|
|
|
2018-11-03 17:14:13 +00:00
|
|
|
port = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 8983;
|
|
|
|
description = "Port on which Solr is ran.";
|
2014-04-03 21:46:45 +01:00
|
|
|
};
|
|
|
|
|
2018-11-03 17:14:13 +00:00
|
|
|
stateDir = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
default = "/var/lib/solr";
|
|
|
|
description = "The solr home directory containing config, data, and logging files.";
|
2014-03-12 23:32:34 +00:00
|
|
|
};
|
|
|
|
|
2018-11-03 17:14:13 +00:00
|
|
|
extraJavaOptions = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [];
|
|
|
|
description = "Extra command line options given to the java process running Solr.";
|
2014-03-12 23:32:34 +00:00
|
|
|
};
|
|
|
|
|
2018-11-03 17:14:13 +00:00
|
|
|
user = mkOption {
|
2014-03-12 23:32:34 +00:00
|
|
|
type = types.str;
|
2018-11-03 17:14:13 +00:00
|
|
|
default = "solr";
|
|
|
|
description = "User under which Solr is ran.";
|
2014-03-12 23:32:34 +00:00
|
|
|
};
|
|
|
|
|
2018-11-03 17:14:13 +00:00
|
|
|
group = mkOption {
|
2014-03-12 23:32:34 +00:00
|
|
|
type = types.str;
|
2018-11-03 17:14:13 +00:00
|
|
|
default = "solr";
|
|
|
|
description = "Group under which Solr is ran.";
|
2014-03-12 23:32:34 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
2018-11-03 17:14:13 +00: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-12 23:32:34 +00:00
|
|
|
};
|
|
|
|
|
2019-09-14 18:51:29 +01:00
|
|
|
users.users = optionalAttrs (cfg.user == "solr") {
|
|
|
|
solr = {
|
2018-11-03 17:14:13 +00:00
|
|
|
group = cfg.group;
|
|
|
|
home = cfg.stateDir;
|
|
|
|
createHome = true;
|
|
|
|
uid = config.ids.uids.solr;
|
2019-09-14 18:51:29 +01:00
|
|
|
};
|
|
|
|
};
|
2018-11-03 17:14:13 +00:00
|
|
|
|
2019-09-14 18:51:29 +01:00
|
|
|
users.groups = optionalAttrs (cfg.group == "solr") {
|
|
|
|
solr.gid = config.ids.gids.solr;
|
|
|
|
};
|
2018-11-03 17:14:13 +00:00
|
|
|
|
2014-03-12 23:32:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|