2012-01-18 20:34:07 +00:00
|
|
|
{ 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}
|
2012-04-01 11:54:08 +01:00
|
|
|
${optionalString (cfg.replSetName != "") "replSet = ${cfg.replSetName}"}
|
2012-01-18 20:34:07 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
services.mongodb = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = "
|
|
|
|
Whether to enable the MongoDB server.
|
|
|
|
";
|
|
|
|
};
|
|
|
|
|
|
|
|
package = mkOption {
|
2013-03-22 20:11:15 +00:00
|
|
|
default = pkgs.mongodb;
|
2014-02-27 12:22:04 +00:00
|
|
|
type = types.package;
|
2012-01-18 20:34:07 +00:00
|
|
|
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";
|
|
|
|
};
|
|
|
|
|
2012-04-01 11:54:08 +01:00
|
|
|
replSetName = mkOption {
|
|
|
|
default = "";
|
|
|
|
description = ''
|
|
|
|
If this instance is part of a replica set, set its name here.
|
|
|
|
Otherwise, leave empty to run as single node.
|
|
|
|
'';
|
|
|
|
};
|
2012-01-18 20:34:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf config.services.mongodb.enable {
|
|
|
|
|
2013-11-07 10:25:14 +00:00
|
|
|
users.extraUsers.mongodb = mkIf (cfg.user == "mongodb")
|
|
|
|
{ name = "mongodb";
|
|
|
|
uid = config.ids.uids.mongodb;
|
2012-01-18 20:34:07 +00:00
|
|
|
description = "MongoDB server user";
|
|
|
|
};
|
|
|
|
|
2012-12-18 19:20:50 +00:00
|
|
|
environment.systemPackages = [ mongodb ];
|
2012-01-18 20:34:07 +00:00
|
|
|
|
2013-02-25 08:04:31 +00:00
|
|
|
systemd.services.mongodb_init =
|
|
|
|
{ description = "MongoDB server initialisation";
|
|
|
|
|
|
|
|
wantedBy = [ "mongodb.service" ];
|
|
|
|
before = [ "mongodb.service" ];
|
|
|
|
|
|
|
|
serviceConfig.Type = "oneshot";
|
|
|
|
|
|
|
|
script = ''
|
|
|
|
if ! test -e ${cfg.dbpath}; then
|
|
|
|
install -d -m0700 -o ${cfg.user} ${cfg.dbpath}
|
|
|
|
install -d -m0755 -o ${cfg.user} `dirname ${cfg.logpath}`
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2013-01-16 11:33:18 +00:00
|
|
|
systemd.services.mongodb =
|
2012-01-18 20:34:07 +00:00
|
|
|
{ description = "MongoDB server";
|
|
|
|
|
2012-12-18 19:20:50 +00:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "network.target" ];
|
2012-01-18 20:34:07 +00:00
|
|
|
|
2012-12-18 19:20:50 +00:00
|
|
|
serviceConfig = {
|
|
|
|
ExecStart = "${mongodb}/bin/mongod --quiet --config ${mongoCnf}";
|
|
|
|
User = cfg.user;
|
|
|
|
};
|
2012-01-18 20:34:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|