summary refs log tree commit diff
path: root/nixos/modules/services/databases/4store.nix
blob: 807317d274545ce1d1b5ed01bb6a47e2db39e3d2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
{ config, lib, pkgs, ... }:
let
  cfg = config.services.fourStore;
  stateDir = "/var/lib/4store";
  fourStoreUser = "fourstore";
  run = "${pkgs.su}/bin/su -s ${pkgs.stdenv.shell} ${fourStoreUser}";
in
with lib;
{

  ###### interface

  options = {

    services.fourStore = {

      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 {

    assertions = singleton
      { assertion = cfg.enable -> cfg.database != "";
        message = "Must specify 4Store 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 = "ip-up";

      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}'
      '';
    };

  };

}