at 17.09-beta 1.7 kB view raw
1{ config, lib, pkgs, ... }: 2let 3 cfg = config.services.fourStoreEndpoint; 4 endpointUser = "fourstorehttp"; 5 run = "${pkgs.su}/bin/su -s ${pkgs.stdenv.shell} ${endpointUser} -c"; 6in 7with lib; 8{ 9 10 ###### interface 11 12 options = { 13 14 services.fourStoreEndpoint = { 15 16 enable = mkOption { 17 default = false; 18 description = "Whether to enable 4Store SPARQL endpoint."; 19 }; 20 21 database = mkOption { 22 default = config.services.fourStore.database; 23 description = "RDF database name to expose via the endpoint. Defaults to local 4Store database name."; 24 }; 25 26 listenAddress = mkOption { 27 default = null; 28 description = "IP address to listen on."; 29 }; 30 31 port = mkOption { 32 default = 8080; 33 description = "port to listen on."; 34 }; 35 36 options = mkOption { 37 default = ""; 38 description = "Extra CLI options to pass to 4Store's 4s-httpd process."; 39 }; 40 41 }; 42 43 }; 44 45 46 ###### implementation 47 48 config = mkIf cfg.enable { 49 50 assertions = singleton 51 { assertion = cfg.enable -> cfg.database != ""; 52 message = "Must specify 4Store database name"; 53 }; 54 55 users.extraUsers = singleton 56 { name = endpointUser; 57 uid = config.ids.uids.fourstorehttp; 58 description = "4Store SPARQL endpoint user"; 59 }; 60 61 services.avahi.enable = true; 62 63 systemd.services."4store-endpoint" = { 64 after = [ "network.target" ]; 65 wantedBy = [ "multi-user.target" ]; 66 67 script = '' 68 ${run} '${pkgs.rdf4store}/bin/4s-httpd -D ${cfg.options} ${if cfg.listenAddress!=null then "-H ${cfg.listenAddress}" else "" } -p ${toString cfg.port} ${cfg.database}' 69 ''; 70 }; 71 72 }; 73 74}