2011-04-15 17:10:13 +01:00
|
|
|
{ config, pkgs, ... }:
|
|
|
|
let
|
|
|
|
cfg = config.services.fourStore;
|
|
|
|
stateDir = "/var/lib/4store";
|
|
|
|
fourStoreUser = "fourstore";
|
|
|
|
run = "${pkgs.su}/bin/su -s ${pkgs.stdenv.shell} ${fourStoreUser}";
|
|
|
|
in
|
|
|
|
with pkgs.lib;
|
|
|
|
{
|
|
|
|
|
|
|
|
###### 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
|
|
|
|
|
|
|
|
config = mkIf cfg.enable (
|
|
|
|
mkAssert (cfg.enable -> cfg.database != "")
|
|
|
|
"Must specify database name" {
|
|
|
|
|
|
|
|
users.extraUsers = singleton
|
|
|
|
{ name = fourStoreUser;
|
|
|
|
uid = config.ids.uids.fourStore;
|
|
|
|
description = "4Store database user";
|
|
|
|
home = stateDir;
|
|
|
|
};
|
|
|
|
|
|
|
|
services.avahi.enable = true;
|
|
|
|
|
|
|
|
jobs.fourStore = {
|
|
|
|
name = "4store";
|
|
|
|
startOn = "filesystem";
|
|
|
|
|
|
|
|
preStart = ''
|
|
|
|
mkdir -p ${stateDir}/
|
|
|
|
chown ${fourStoreUser} ${stateDir}
|
|
|
|
if ! test -e "${stateDir}/${cfg.database}"; then
|
|
|
|
${run} -c '${pkgs.rdf4store}/bin/4s-backend-setup ${cfg.database}'
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
|
|
|
|
exec = ''
|
|
|
|
${run} -c '${pkgs.rdf4store}/bin/4s-backend -D ${cfg.options} ${cfg.database}'
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
});
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2011-04-15 17:10:13 +01:00
|
|
|
}
|