Convert "postgresql"
svn path=/nixos/branches/fix-style/; revision=14390
This commit is contained in:
parent
72303e9b6c
commit
8e840a7aa4
3 changed files with 107 additions and 91 deletions
|
@ -479,64 +479,6 @@ in
|
|||
|
||||
};
|
||||
|
||||
postgresql = {
|
||||
enable = mkOption {
|
||||
default = false;
|
||||
description = "
|
||||
Whether to run PostgreSQL.
|
||||
";
|
||||
};
|
||||
port = mkOption {
|
||||
default = "5432";
|
||||
description = "
|
||||
Port for PostgreSQL.
|
||||
";
|
||||
};
|
||||
logDir = mkOption {
|
||||
default = "/var/log/postgresql";
|
||||
description = "
|
||||
Log directory for PostgreSQL.
|
||||
";
|
||||
};
|
||||
dataDir = mkOption {
|
||||
default = "/var/db/postgresql";
|
||||
description = "
|
||||
Data directory for PostgreSQL.
|
||||
";
|
||||
};
|
||||
subServices = mkOption {
|
||||
default = [];
|
||||
description = "
|
||||
Subservices list. As it is already implememnted,
|
||||
here is an interface...
|
||||
";
|
||||
};
|
||||
authentication = mkOption {
|
||||
default = ''
|
||||
# Generated file; do not edit!
|
||||
local all all ident sameuser
|
||||
host all all 127.0.0.1/32 md5
|
||||
host all all ::1/128 md5
|
||||
'';
|
||||
description = "
|
||||
Hosts (except localhost), who you allow to connect.
|
||||
";
|
||||
};
|
||||
allowedHosts = mkOption {
|
||||
default = [];
|
||||
description = "
|
||||
Hosts (except localhost), who you allow to connect.
|
||||
";
|
||||
};
|
||||
authMethod = mkOption {
|
||||
default = " ident sameuser ";
|
||||
description = "
|
||||
How to authorize users.
|
||||
Note: ident needs absolute trust to all allowed client hosts.";
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
openfire = {
|
||||
enable = mkOption {
|
||||
default = false;
|
||||
|
@ -856,6 +798,7 @@ in
|
|||
(import ../upstart-jobs/ircd-hybrid.nix) # TODO: doesn't compile on x86_64-linux, can't test
|
||||
(import ../upstart-jobs/xfs.nix)
|
||||
(import ../upstart-jobs/mysql.nix)
|
||||
(import ../upstart-jobs/postgresql.nix)
|
||||
|
||||
# nix
|
||||
(import ../upstart-jobs/nix.nix) # nix options and daemon
|
||||
|
|
|
@ -131,12 +131,6 @@ let
|
|||
inherit config;
|
||||
})
|
||||
|
||||
# Postgres SQL server
|
||||
++ optional config.services.postgresql.enable
|
||||
(import ../upstart-jobs/postgresql.nix {
|
||||
inherit config pkgs;
|
||||
})
|
||||
|
||||
# OpenFire XMPP server
|
||||
++ optional config.services.openfire.enable
|
||||
(import ../upstart-jobs/openfire.nix {
|
||||
|
|
|
@ -1,4 +1,72 @@
|
|||
{pkgs, config}:
|
||||
{pkgs, config, ...}:
|
||||
|
||||
###### interface
|
||||
let
|
||||
inherit (pkgs.lib) mkOption mkIf;
|
||||
|
||||
options = {
|
||||
services = {
|
||||
postgresql = {
|
||||
enable = mkOption {
|
||||
default = false;
|
||||
description = "
|
||||
Whether to run PostgreSQL.
|
||||
";
|
||||
};
|
||||
port = mkOption {
|
||||
default = "5432";
|
||||
description = "
|
||||
Port for PostgreSQL.
|
||||
";
|
||||
};
|
||||
logDir = mkOption {
|
||||
default = "/var/log/postgresql";
|
||||
description = "
|
||||
Log directory for PostgreSQL.
|
||||
";
|
||||
};
|
||||
dataDir = mkOption {
|
||||
default = "/var/db/postgresql";
|
||||
description = "
|
||||
Data directory for PostgreSQL.
|
||||
";
|
||||
};
|
||||
subServices = mkOption {
|
||||
default = [];
|
||||
description = "
|
||||
Subservices list. As it is already implememnted,
|
||||
here is an interface...
|
||||
";
|
||||
};
|
||||
authentication = mkOption {
|
||||
default = ''
|
||||
# Generated file; do not edit!
|
||||
local all all ident sameuser
|
||||
host all all 127.0.0.1/32 md5
|
||||
host all all ::1/128 md5
|
||||
'';
|
||||
description = "
|
||||
Hosts (except localhost), who you allow to connect.
|
||||
";
|
||||
};
|
||||
allowedHosts = mkOption {
|
||||
default = [];
|
||||
description = "
|
||||
Hosts (except localhost), who you allow to connect.
|
||||
";
|
||||
};
|
||||
authMethod = mkOption {
|
||||
default = " ident sameuser ";
|
||||
description = "
|
||||
How to authorize users.
|
||||
Note: ident needs absolute trust to all allowed client hosts.";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
in
|
||||
|
||||
###### implementation
|
||||
|
||||
let
|
||||
|
||||
|
@ -13,36 +81,47 @@ let
|
|||
|
||||
in
|
||||
|
||||
{
|
||||
name = "postgresql";
|
||||
|
||||
users = [
|
||||
{ name = "postgres";
|
||||
description = "PostgreSQL server user";
|
||||
}
|
||||
mkIf config.services.postgresql.enable {
|
||||
require = [
|
||||
options
|
||||
];
|
||||
|
||||
groups = [
|
||||
{ name = "postgres"; }
|
||||
];
|
||||
|
||||
extraPath = [postgresql];
|
||||
users = {
|
||||
extraUsers = [
|
||||
{ name = "postgres";
|
||||
description = "PostgreSQL server user";
|
||||
}
|
||||
];
|
||||
|
||||
job = ''
|
||||
description "PostgreSQL server"
|
||||
extraGroups = [
|
||||
{ name = "postgres"; }
|
||||
];
|
||||
};
|
||||
|
||||
start on ${startDependency}/started
|
||||
stop on shutdown
|
||||
|
||||
start script
|
||||
if ! test -e ${cfg.dataDir}; then
|
||||
mkdir -m 0700 -p ${cfg.dataDir}
|
||||
chown -R postgres ${cfg.dataDir}
|
||||
${run} -c '${postgresql}/bin/initdb -D ${cfg.dataDir} -U root'
|
||||
fi
|
||||
cp -f ${pkgs.writeText "pg_hba.conf" cfg.authentication} ${cfg.dataDir}/pg_hba.conf
|
||||
end script
|
||||
services = {
|
||||
extraJobs = [{
|
||||
name = "postgresql";
|
||||
|
||||
respawn ${run} -c '${postgresql}/bin/postgres -D ${cfg.dataDir}'
|
||||
'';
|
||||
extraPath = [postgresql];
|
||||
|
||||
job = ''
|
||||
description "PostgreSQL server"
|
||||
|
||||
start on ${startDependency}/started
|
||||
stop on shutdown
|
||||
|
||||
start script
|
||||
if ! test -e ${cfg.dataDir}; then
|
||||
mkdir -m 0700 -p ${cfg.dataDir}
|
||||
chown -R postgres ${cfg.dataDir}
|
||||
${run} -c '${postgresql}/bin/initdb -D ${cfg.dataDir} -U root'
|
||||
fi
|
||||
cp -f ${pkgs.writeText "pg_hba.conf" cfg.authentication} ${cfg.dataDir}/pg_hba.conf
|
||||
end script
|
||||
|
||||
respawn ${run} -c '${postgresql}/bin/postgres -D ${cfg.dataDir}'
|
||||
'';
|
||||
}];
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue