2014-04-14 15:26:48 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
2011-04-15 17:10:13 +01: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 15:26:48 +01:00
|
|
|
with lib;
|
2011-04-15 17:10:13 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2011-04-15 17:10:13 +01:00
|
|
|
services.fourStore = {
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2011-04-15 17:10:13 +01: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 17:30:23 +00:00
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
|
|
|
assertions = singleton
|
|
|
|
{ assertion = cfg.enable -> cfg.database != "";
|
|
|
|
message = "Must specify 4Store database name.";
|
|
|
|
};
|
2011-04-15 17:10:13 +01:00
|
|
|
|
|
|
|
users.extraUsers = singleton
|
|
|
|
{ name = fourStoreUser;
|
2014-04-29 09:51:42 +01:00
|
|
|
uid = config.ids.uids.fourstore;
|
2011-04-15 17:10:13 +01:00
|
|
|
description = "4Store database user";
|
|
|
|
home = stateDir;
|
|
|
|
};
|
|
|
|
|
|
|
|
services.avahi.enable = true;
|
|
|
|
|
|
|
|
jobs.fourStore = {
|
|
|
|
name = "4store";
|
2014-11-16 15:04:31 +00:00
|
|
|
startOn = "ip-up";
|
2011-04-15 17:10:13 +01:00
|
|
|
|
|
|
|
preStart = ''
|
|
|
|
mkdir -p ${stateDir}/
|
|
|
|
chown ${fourStoreUser} ${stateDir}
|
2013-10-30 17:30:23 +00:00
|
|
|
if ! test -e "${stateDir}/${cfg.database}"; then
|
|
|
|
${run} -c '${pkgs.rdf4store}/bin/4s-backend-setup ${cfg.database}'
|
2011-04-15 17:10:13 +01:00
|
|
|
fi
|
|
|
|
'';
|
|
|
|
|
|
|
|
exec = ''
|
2013-10-30 17:30:23 +00:00
|
|
|
${run} -c '${pkgs.rdf4store}/bin/4s-backend -D ${cfg.options} ${cfg.database}'
|
2011-04-15 17:10:13 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2013-10-30 17:30:23 +00:00
|
|
|
};
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2011-04-15 17:10:13 +01:00
|
|
|
}
|