2014-04-14 16:26:48 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
2011-04-15 18:10:13 +02:00
|
|
|
let
|
|
|
|
cfg = config.services.fourStore;
|
|
|
|
stateDir = "/var/lib/4store";
|
|
|
|
fourStoreUser = "fourstore";
|
|
|
|
run = "${pkgs.su}/bin/su -s ${pkgs.stdenv.shell} ${fourStoreUser}";
|
|
|
|
in
|
2014-04-14 16:26:48 +02:00
|
|
|
with lib;
|
2011-04-15 18:10:13 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2011-04-15 18:10:13 +02:00
|
|
|
services.fourStore = {
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2011-04-15 18:10:13 +02:00
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = "Whether to enable 4Store RDF database server.";
|
|
|
|
};
|
|
|
|
|
|
|
|
database = mkOption {
|
|
|
|
default = "";
|
|
|
|
description = "RDF database name. If it doesn't exist, it will be created. Databases are stored in ${stateDir}.";
|
|
|
|
};
|
|
|
|
|
|
|
|
options = mkOption {
|
|
|
|
default = "";
|
|
|
|
description = "Extra CLI options to pass to 4Store.";
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
2013-10-30 18:30:23 +01:00
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
|
|
|
assertions = singleton
|
|
|
|
{ assertion = cfg.enable -> cfg.database != "";
|
|
|
|
message = "Must specify 4Store database name.";
|
|
|
|
};
|
2011-04-15 18:10:13 +02:00
|
|
|
|
|
|
|
users.extraUsers = singleton
|
|
|
|
{ name = fourStoreUser;
|
2014-04-29 10:51:42 +02:00
|
|
|
uid = config.ids.uids.fourstore;
|
2011-04-15 18:10:13 +02:00
|
|
|
description = "4Store database user";
|
|
|
|
home = stateDir;
|
|
|
|
};
|
|
|
|
|
|
|
|
services.avahi.enable = true;
|
|
|
|
|
|
|
|
jobs.fourStore = {
|
|
|
|
name = "4store";
|
2014-11-16 16:04:31 +01:00
|
|
|
startOn = "ip-up";
|
2011-04-15 18:10:13 +02:00
|
|
|
|
|
|
|
preStart = ''
|
|
|
|
mkdir -p ${stateDir}/
|
|
|
|
chown ${fourStoreUser} ${stateDir}
|
2013-10-30 18:30:23 +01:00
|
|
|
if ! test -e "${stateDir}/${cfg.database}"; then
|
|
|
|
${run} -c '${pkgs.rdf4store}/bin/4s-backend-setup ${cfg.database}'
|
2011-04-15 18:10:13 +02:00
|
|
|
fi
|
|
|
|
'';
|
|
|
|
|
|
|
|
exec = ''
|
2013-10-30 18:30:23 +01:00
|
|
|
${run} -c '${pkgs.rdf4store}/bin/4s-backend -D ${cfg.options} ${cfg.database}'
|
2011-04-15 18:10:13 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2013-10-30 18:30:23 +01:00
|
|
|
};
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2011-04-15 18:10:13 +02:00
|
|
|
}
|