diff --git a/system/options.nix b/system/options.nix index 5644247d3fae..6afc6ee97fac 100644 --- a/system/options.nix +++ b/system/options.nix @@ -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 diff --git a/upstart-jobs/default.nix b/upstart-jobs/default.nix index 173bb1d4606b..1075bfd6446e 100644 --- a/upstart-jobs/default.nix +++ b/upstart-jobs/default.nix @@ -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 { diff --git a/upstart-jobs/postgresql.nix b/upstart-jobs/postgresql.nix index a37780678fc9..77cf1a582e9b 100644 --- a/upstart-jobs/postgresql.nix +++ b/upstart-jobs/postgresql.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}' + ''; + }]; + }; }