summary refs log tree commit diff
path: root/nixos/modules/services/databases
diff options
context:
space:
mode:
authorMichael Weiss <dev.primeos@gmail.com>2018-05-01 16:44:12 +0200
committerGitHub <noreply@github.com>2018-05-01 16:44:12 +0200
commit1b8642dff6bdbf7c39f1f46a4876f9c9beb775e3 (patch)
tree5ce5f508be9546a3e9f336a270dbcc1d084914a5 /nixos/modules/services/databases
parentde60146f592feb6482a82fc27d9d01f713f34277 (diff)
downloadnixlib-1b8642dff6bdbf7c39f1f46a4876f9c9beb775e3.tar
nixlib-1b8642dff6bdbf7c39f1f46a4876f9c9beb775e3.tar.gz
nixlib-1b8642dff6bdbf7c39f1f46a4876f9c9beb775e3.tar.bz2
nixlib-1b8642dff6bdbf7c39f1f46a4876f9c9beb775e3.tar.lz
nixlib-1b8642dff6bdbf7c39f1f46a4876f9c9beb775e3.tar.xz
nixlib-1b8642dff6bdbf7c39f1f46a4876f9c9beb775e3.tar.zst
nixlib-1b8642dff6bdbf7c39f1f46a4876f9c9beb775e3.zip
nixos/monetdb: init (#39812)
Diffstat (limited to 'nixos/modules/services/databases')
-rw-r--r--nixos/modules/services/databases/monetdb.nix100
1 files changed, 100 insertions, 0 deletions
diff --git a/nixos/modules/services/databases/monetdb.nix b/nixos/modules/services/databases/monetdb.nix
new file mode 100644
index 000000000000..5c66fc7b2e36
--- /dev/null
+++ b/nixos/modules/services/databases/monetdb.nix
@@ -0,0 +1,100 @@
+{ config, lib, pkgs, ... }:
+
+with lib;
+
+let
+  cfg = config.services.monetdb;
+
+in {
+  meta.maintainers = with maintainers; [ StillerHarpo primeos ];
+
+  ###### interface
+  options = {
+    services.monetdb = {
+
+      enable = mkEnableOption "the MonetDB database server";
+
+      package = mkOption {
+        type = types.package;
+        default = pkgs.monetdb;
+        defaultText = "pkgs.monetdb";
+        description = "MonetDB package to use.";
+      };
+
+      user = mkOption {
+        type = types.str;
+        default = "monetdb";
+        description = "User account under which MonetDB runs.";
+      };
+
+      group = mkOption {
+        type = types.str;
+        default = "monetdb";
+        description = "Group under which MonetDB runs.";
+      };
+
+      dataDir = mkOption {
+        type = types.path;
+        default = "/var/lib/monetdb";
+        description = "Data directory for the dbfarm.";
+      };
+
+      port = mkOption {
+        type = types.ints.u16;
+        default = 50000;
+        description = "Port to listen on.";
+      };
+
+      listenAddress = mkOption {
+        type = types.str;
+        default = "127.0.0.1";
+        example = "0.0.0.0";
+        description = "Address to listen on.";
+      };
+    };
+  };
+
+  ###### implementation
+  config = mkIf cfg.enable {
+
+    users.users.monetdb = mkIf (cfg.user == "monetdb") {
+      uid = config.ids.uids.monetdb;
+      group = cfg.group;
+      description = "MonetDB user";
+      home = cfg.dataDir;
+      createHome = true;
+    };
+
+    users.groups.monetdb = mkIf (cfg.group == "monetdb") {
+      gid = config.ids.gids.monetdb;
+      members = [ cfg.user ];
+    };
+
+    environment.systemPackages = [ cfg.package ];
+
+    systemd.services.monetdb = {
+      description = "MonetDB database server";
+      wantedBy = [ "multi-user.target" ];
+      after = [ "network.target" ];
+      path = [ cfg.package ];
+      unitConfig.RequiresMountsFor = "${cfg.dataDir}";
+      serviceConfig = {
+        User = cfg.user;
+        Group = cfg.group;
+        ExecStart = "${cfg.package}/bin/monetdbd start -n ${cfg.dataDir}";
+        ExecStop = "${cfg.package}/bin/monetdbd stop ${cfg.dataDir}";
+      };
+      preStart = ''
+        if [ ! -e ${cfg.dataDir}/.merovingian_properties ]; then
+          # Create the dbfarm (as cfg.user)
+          ${cfg.package}/bin/monetdbd create ${cfg.dataDir}
+        fi
+
+        # Update the properties
+        ${cfg.package}/bin/monetdbd set port=${toString cfg.port} ${cfg.dataDir}
+        ${cfg.package}/bin/monetdbd set listenaddr=${cfg.listenAddress} ${cfg.dataDir}
+      '';
+    };
+
+  };
+}