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";
|
2018-03-01 19:38:53 +00:00
|
|
|
run = "${pkgs.su}/bin/su -s ${pkgs.runtimeShell} ${fourStoreUser}";
|
2011-04-15 17:10:13 +01:00
|
|
|
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;
|
|
|
|
|
2016-01-06 06:50:18 +00:00
|
|
|
systemd.services."4store" = {
|
2016-09-10 17:03:59 +01:00
|
|
|
after = [ "network.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
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
|
|
|
|
'';
|
|
|
|
|
2016-01-06 06:50:18 +00:00
|
|
|
script = ''
|
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-04-15 17:10:13 +01:00
|
|
|
}
|