Skip to content

Commit

Permalink
services: put resources to resources, more sane ports
Browse files Browse the repository at this point in the history
  • Loading branch information
offlinehacker committed Feb 1, 2015
1 parent 82358ca commit af797a9
Show file tree
Hide file tree
Showing 16 changed files with 180 additions and 184 deletions.
14 changes: 4 additions & 10 deletions nixos/modules/system/boot/sal.nix
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,10 @@ in {
concatStrings (map (n:
let
dc = getAttr n config.sal.dataContainers;
path = "/var/${dc.type}/${if dc.name != "" then dc.name else n}";

in ''
mkdir -m ${dc.mode} -p ${path}
${optionalString (dc.user != "") "chown -R ${dc.user} ${path}"}
${optionalString (dc.group != "") "chgrp -R ${dc.group} ${path}"}
mkdir -m ${dc.mode} -p ${dc.path}
${optionalString (dc.user != "") "chown -R ${dc.user} ${dc.path}"}
${optionalString (dc.group != "") "chgrp -R ${dc.group} ${dc.path}"}
''
) s.requires.dataContainers)
);
Expand All @@ -106,10 +104,6 @@ in {
inherit (s) description;

listenStreams = [ s.listen ];
}) config.sal.sockets;

sal.dataContainerPaths = mapAttrs (n: dc:
"/var/${dc.type}/${if dc.name != "" then dc.name else n}"
) config.sal.dataContainers;
}) config.resources.sockets;

}
5 changes: 2 additions & 3 deletions services/databases/influxdb.nix
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ in
};

dataDir = mkOption {
default = config.sal.dataContainerPaths.influxdb;
default = config.resources.dataContainers.influxdb.path;
description = "Data directory for influxd data files.";
type = types.path;
};
Expand Down Expand Up @@ -233,8 +233,7 @@ in
'';
};

sal.dataContainers.influxdb = {
description = "PostgreSQL data container";
resources.dataContainers.influxdb = {
type = "db";
mode = "0770";
inherit (cfg) user group;
Expand Down
11 changes: 5 additions & 6 deletions services/databases/mongodb.nix
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ in
};

dbpath = mkOption {
default = config.sal.dataContainerPaths.mongodb;
default = config.resources.dataContainers.mongodb.path;
description = "Location where MongoDB stores its files";
};

pidFile = mkOption {
default = "${config.sal.dataContainerPaths.mongodb-state}/mongodb.pid";
default = "${config.resources.dataContainers.mongodb-state.path}/mongodb.pid";
description = "Location of MongoDB pid file";
};

Expand Down Expand Up @@ -100,21 +100,20 @@ in
requires = {
networking = true;
dataContainers = ["mongodb" "mongodb-state"];
port = [ 27017 ];
};

pidFile = cfg.pidFile;
user = "mongodb";
};

sal.dataContainers.mongodb = {
description = "Mongodb data container";
resources.dataContainers.mongodb = {
type = "db";
mode = "700";
user = "mongodb";
};

sal.dataContainers.mongodb-state = {
description = "Mongodb state container";
resources.dataContainers.mongodb-state = {
name = "mongodb";
type = "run";
mode = "755";
Expand Down
7 changes: 3 additions & 4 deletions services/databases/postgresql.nix
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ in

dataDir = mkOption {
type = types.path;
default = config.sal.dataContainerPaths.postgresql;
default = config.resources.dataContainers.postgresql.path;
description = ''
Data directory for PostgreSQL.
'';
Expand Down Expand Up @@ -172,8 +172,8 @@ in
requires = {
networking = true;
dataContainers = [ "postgresql" ];
ports = [ cfg.port ];
dropPrivileges = pm.supports.privileged;
ports = [ cfg.port ];
};

environment.PGDATA = cfg.dataDir;
Expand Down Expand Up @@ -226,8 +226,7 @@ in
stop.stopMode = "mixed";
};

sal.dataContainers.postgresql = {
description = "PostgreSQL data container";
resources.dataContainers.postgresql = {
type = "db";
mode = "0700";
user = "postgres";
Expand Down
10 changes: 5 additions & 5 deletions services/databases/redis.nix
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ in

pidFile = mkOption {
type = types.path;
default = config.sal.dataContainerPaths.redis-run;
default = config.resources.dataContainers.redis-run.path;
description = "";
};

Expand Down Expand Up @@ -121,7 +121,7 @@ in

dbpath = mkOption {
type = types.path;
default = config.sal.dataContainerPaths.redis;
default = config.resources.dataContainers.redis.path;
description = "The DB will be written inside this directory, with the filename specified using the 'dbFilename' configuration.";
};

Expand Down Expand Up @@ -205,22 +205,22 @@ in

requires = {
networking = true;
ports = [ cfg.port ];
dataContainers = ["redis" "redis-run"];
ports = [ cfg.port ];
};

start.command =
"${cfg.package}/bin/redis-server ${redisConfig}";
user = cfg.user;
};

sal.dataContainers.redis = {
resources.dataContainers.redis = {
type = "db";
mode = "0770";
user = cfg.user;
};

sal.dataContainers.redis-run = {
resources.dataContainers.redis-run = {
type = "run";
mode = "0770";
user = cfg.user;
Expand Down
130 changes: 130 additions & 0 deletions services/lib/resources.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
{ config, lib, pkgs, ... }:

with lib;

let
gconfig = config;

commonOptions = {
description = mkOption {
type = types.str;
default = "";
description = "Resource description.";
};
};

dataContainerOptions = { name, config, ... }: {
options = commonOptions // {

name = mkOption {
type = types.str;
description = "Name of data container.";
};

type = mkOption {
default = "lib";
type = types.enum ["db" "lib" "log" "run" "spool"];
description = "Type of data container.";
};

mode = mkOption {
default = "600";
type = types.str;
description = "File mode for data container";
};

user = mkOption {
default = "";
type = types.str;
description = "Data container user.";
};

group = mkOption {
default = "";
type = types.str;
description = "Data container group.";
};

path = mkOption {
type = types.path;
description = "Path exposed for resources.";
};

};

config = {
name = mkDefault name;
path = mkDefault (gconfig.resources.dataContainerMapping config);
};
};

socketOptions = { name, config, ... }: {
options = commonOptions // {
name = mkOption {
type = types.str;
description = "Name of socket.";
};

listen = mkOption {
type = types.str;
example = "0.0.0.0:993";
description = "Address or file where socket should listen.";
};

type = mkOption {
type = types.enum ["inet" "inet6" "unix"];
description = "Type of listening socket";
};

mode = mkOption {
default = "600";
type = types.str;
description = "File mode for socker";
};

user = mkOption {
default = "";
type = types.str;
description = "Socket owner user.";
};

group = mkOption {
default = "";
type = types.str;
description = "Socket owner group.";
};
};

config = {
name = mkDefault name;
};
};


in {
options = {
resources.dataContainers = mkOption {
default = {};
type = types.attrsOf types.optionSet;
options = [ dataContainerOptions ];
description = "Definition of data containers.";
};

resources.dataContainerMapping = mkOption {
default = dc: "/var/${dc.type}/${dc.name}";
description = "Mapping function for data containers that defines
concrete paths where the data should be.";
};

resources.sockets = mkOption {
default = {};
type = types.attrsOf types.optionSet;
options = [ socketOptions ];
description = "Definition of socket resources.";
};
};

config = {
assertions = [];
};
}
Loading

0 comments on commit af797a9

Please sign in to comment.