summary refs log tree commit diff
path: root/modules/services/databases/mongodb.nix
diff options
context:
space:
mode:
authorPeter Simons <simons@cryp.to>2012-01-18 20:34:07 +0000
committerPeter Simons <simons@cryp.to>2012-01-18 20:34:07 +0000
commitec445fbee7f10401c2868f05f981bbd2bf7f2024 (patch)
tree24ef8b8c67b59e92e5b68a227e126a78e0f76a82 /modules/services/databases/mongodb.nix
parent5144e946943862348b0900739b1a16c0689cd2d4 (diff)
downloadnixpkgs-ec445fbee7f10401c2868f05f981bbd2bf7f2024.tar
nixpkgs-ec445fbee7f10401c2868f05f981bbd2bf7f2024.tar.gz
nixpkgs-ec445fbee7f10401c2868f05f981bbd2bf7f2024.tar.bz2
nixpkgs-ec445fbee7f10401c2868f05f981bbd2bf7f2024.tar.lz
nixpkgs-ec445fbee7f10401c2868f05f981bbd2bf7f2024.tar.xz
nixpkgs-ec445fbee7f10401c2868f05f981bbd2bf7f2024.tar.zst
nixpkgs-ec445fbee7f10401c2868f05f981bbd2bf7f2024.zip
mongodb nixos module
svn path=/nixos/trunk/; revision=31658
Diffstat (limited to 'modules/services/databases/mongodb.nix')
-rw-r--r--modules/services/databases/mongodb.nix119
1 files changed, 119 insertions, 0 deletions
diff --git a/modules/services/databases/mongodb.nix b/modules/services/databases/mongodb.nix
new file mode 100644
index 00000000000..cf8caabfc8a
--- /dev/null
+++ b/modules/services/databases/mongodb.nix
@@ -0,0 +1,119 @@
+{ config, pkgs, ... }:
+
+with pkgs.lib;
+
+let
+
+  b2s = x: if x then "true" else "false";
+
+  cfg = config.services.mongodb;
+
+  mongodb = cfg.package;
+
+  mongoCnf = pkgs.writeText "mongodb.conf"
+  ''
+    bind_ip = ${cfg.bind_ip}
+    ${optionalString cfg.quiet "quiet = true"}
+    dbpath = ${cfg.dbpath}
+    logpath = ${cfg.logpath}
+    logappend = ${b2s cfg.logappend}
+  '';
+
+in
+
+{
+
+  ###### interface
+
+  options = {
+
+    services.mongodb = {
+
+      enable = mkOption {
+        default = false;
+        description = "
+          Whether to enable the MongoDB server.
+        ";
+      };
+
+      package = mkOption {
+        default = pkgs.mongodb.override { useV8 = cfg.useV8; };
+        description = "
+          Which MongoDB derivation to use.
+        ";
+      };
+
+      user = mkOption {
+        default = "mongodb";
+        description = "User account under which MongoDB runs";
+      };
+
+      bind_ip = mkOption {
+        default = "127.0.0.1";
+        description = "IP to bind to";
+      };
+
+      quiet = mkOption {
+        default = false;
+        description = "quieter output";
+      };
+
+      dbpath = mkOption {
+        default = "/var/db/mongodb";
+        description = "Location where MongoDB stores its files";
+      };
+
+      logpath = mkOption {
+        default = "/var/log/mongodb/mongod.log";
+        description = "Location where MongoDB stores its logfile";
+      };
+
+      logappend = mkOption {
+        default = true;
+        description = "Append logfile instead over overwriting";
+      };
+
+      useV8 = mkOption {
+        default = false;
+        description = "Use V8 instead of spidermonkey for js execution";
+      };
+    };
+
+  };
+
+
+  ###### implementation
+
+  config = mkIf config.services.mongodb.enable {
+
+    users.extraUsers = singleton
+      { name = cfg.user;
+        shell = "/bin/sh";
+        description = "MongoDB server user";
+      };
+
+    environment.systemPackages = [mongodb];
+
+    jobs.mongodb =
+      { description = "MongoDB server";
+
+        startOn = "filesystem";
+        daemonType = "daemon";
+
+        preStart =
+          ''
+            if ! test -e ${cfg.dbpath}; then
+                install -d -m0700 -o ${cfg.user} ${cfg.dbpath}
+                install -d -m0755 -o ${cfg.user} `dirname ${cfg.logpath}`
+            fi
+          '';
+
+        exec = "${pkgs.shadow}/bin/su ${cfg.user} -c \"${mongodb}/bin/mongod --config ${mongoCnf} --fork\"";
+        preStop = "${pkgs.shadow}/bin/su ${cfg.user} -c \"${mongodb}/bin/mongod --config ${mongoCnf} --shutdown\" &";
+
+        extraConfig = "kill timeout 10";
+      };
+
+  };
+
+}