mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-13 13:15:30 +03:00
Merge branch 'master' into postgresql_group
This commit is contained in:
commit
2c77c53487
14714 changed files with 548639 additions and 460914 deletions
|
@ -6,26 +6,10 @@ let
|
|||
|
||||
cfg = config.services.postgresql;
|
||||
|
||||
# see description of extraPlugins
|
||||
postgresqlAndPlugins = pg:
|
||||
if cfg.extraPlugins == [] then pg
|
||||
else pkgs.buildEnv {
|
||||
name = "postgresql-and-plugins-${(builtins.parseDrvName pg.name).version}";
|
||||
paths = [ pg pg.lib ] ++ cfg.extraPlugins;
|
||||
# We include /bin to ensure the $out/bin directory is created which is
|
||||
# needed because we'll be removing files from that directory in postBuild
|
||||
# below. See #22653
|
||||
pathsToLink = [ "/" "/bin" ];
|
||||
buildInputs = [ pkgs.makeWrapper ];
|
||||
postBuild =
|
||||
''
|
||||
rm $out/bin/{pg_config,postgres,pg_ctl}
|
||||
cp --target-directory=$out/bin ${pg}/bin/{postgres,pg_config,pg_ctl}
|
||||
wrapProgram $out/bin/postgres --set NIX_PGLIBDIR $out/lib
|
||||
'';
|
||||
};
|
||||
|
||||
postgresql = postgresqlAndPlugins cfg.package;
|
||||
postgresql =
|
||||
if cfg.extraPlugins == []
|
||||
then cfg.package
|
||||
else cfg.package.withPackages (_: cfg.extraPlugins);
|
||||
|
||||
# The main PostgreSQL configuration file.
|
||||
configFile = pkgs.writeText "postgresql.conf"
|
||||
|
@ -60,7 +44,7 @@ in
|
|||
|
||||
package = mkOption {
|
||||
type = types.package;
|
||||
example = literalExample "pkgs.postgresql_9_6";
|
||||
example = literalExample "pkgs.postgresql_11";
|
||||
description = ''
|
||||
PostgreSQL package to use.
|
||||
'';
|
||||
|
@ -76,7 +60,7 @@ in
|
|||
|
||||
dataDir = mkOption {
|
||||
type = types.path;
|
||||
example = "/var/lib/postgresql/9.6";
|
||||
example = "/var/lib/postgresql/11";
|
||||
description = ''
|
||||
Data directory for PostgreSQL.
|
||||
'';
|
||||
|
@ -111,6 +95,10 @@ in
|
|||
default = "";
|
||||
description = ''
|
||||
Defines the mapping from system users to database users.
|
||||
|
||||
The general form is:
|
||||
|
||||
map-name system-username database-username
|
||||
'';
|
||||
};
|
||||
|
||||
|
@ -219,17 +207,11 @@ in
|
|||
extraPlugins = mkOption {
|
||||
type = types.listOf types.path;
|
||||
default = [];
|
||||
example = literalExample "[ (pkgs.postgis.override { postgresql = pkgs.postgresql_9_4; }) ]";
|
||||
example = literalExample "with pkgs.postgresql_11.pkgs; [ postgis pg_repack ]";
|
||||
description = ''
|
||||
When this list contains elements a new store path is created.
|
||||
PostgreSQL and the elements are symlinked into it. Then pg_config,
|
||||
postgres and pg_ctl are copied to make them use the new
|
||||
$out/lib directory as pkglibdir. This makes it possible to use postgis
|
||||
without patching the .sql files which reference $libdir/postgis-1.5.
|
||||
List of PostgreSQL plugins. PostgreSQL version for each plugin should
|
||||
match version for <literal>services.postgresql.package</literal> value.
|
||||
'';
|
||||
# Note: the duplication of executables is about 4MB size.
|
||||
# So a nicer solution was patching postgresql to allow setting the
|
||||
# libdir explicitely.
|
||||
};
|
||||
|
||||
extraConfig = mkOption {
|
||||
|
@ -276,9 +258,10 @@ in
|
|||
# Note: when changing the default, make it conditional on
|
||||
# ‘system.stateVersion’ to maintain compatibility with existing
|
||||
# systems!
|
||||
mkDefault (if versionAtLeast config.system.stateVersion "17.09" then pkgs.postgresql_9_6
|
||||
mkDefault (if versionAtLeast config.system.stateVersion "20.03" then pkgs.postgresql_11
|
||||
else if versionAtLeast config.system.stateVersion "17.09" then pkgs.postgresql_9_6
|
||||
else if versionAtLeast config.system.stateVersion "16.03" then pkgs.postgresql_9_5
|
||||
else pkgs.postgresql_9_4);
|
||||
else throw "postgresql_9_4 was removed, please upgrade your postgresql version.");
|
||||
|
||||
services.postgresql.dataDir =
|
||||
mkDefault (if versionAtLeast config.system.stateVersion "17.09"
|
||||
|
@ -309,6 +292,10 @@ in
|
|||
|
||||
environment.systemPackages = [ postgresql ];
|
||||
|
||||
environment.pathsToLink = [
|
||||
"/share/postgresql"
|
||||
];
|
||||
|
||||
systemd.services.postgresql =
|
||||
{ description = "PostgreSQL Server";
|
||||
|
||||
|
@ -387,13 +374,13 @@ in
|
|||
fi
|
||||
'' + optionalString (cfg.ensureDatabases != []) ''
|
||||
${concatMapStrings (database: ''
|
||||
$PSQL -tAc "SELECT 1 FROM pg_database WHERE datname = '${database}'" | grep -q 1 || $PSQL -tAc "CREATE DATABASE ${database}"
|
||||
$PSQL -tAc "SELECT 1 FROM pg_database WHERE datname = '${database}'" | grep -q 1 || $PSQL -tAc 'CREATE DATABASE "${database}"'
|
||||
'') cfg.ensureDatabases}
|
||||
'' + ''
|
||||
${concatMapStrings (user: ''
|
||||
$PSQL -tAc "SELECT 1 FROM pg_roles WHERE rolname='${user.name}'" | grep -q 1 || $PSQL -tAc "CREATE USER ${user.name}"
|
||||
$PSQL -tAc "SELECT 1 FROM pg_roles WHERE rolname='${user.name}'" | grep -q 1 || $PSQL -tAc 'CREATE USER "${user.name}"'
|
||||
${concatStringsSep "\n" (mapAttrsToList (database: permission: ''
|
||||
$PSQL -tAc "GRANT ${permission} ON ${database} TO ${user.name}"
|
||||
$PSQL -tAc 'GRANT ${permission} ON ${database} TO "${user.name}"'
|
||||
'') user.ensurePermissions)}
|
||||
'') cfg.ensureUsers}
|
||||
'';
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue