Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
677c607
nixpkgs: deprecate the badly named 'postgresql100' attribute
thoughtpolice Aug 6, 2018
ac197be
nixpkgs: move postgresql patches into a common directory
thoughtpolice Aug 6, 2018
6d00a38
nixpkgs: reorganize the postgresql extensions
thoughtpolice Aug 6, 2018
abf7e3c
nixpkgs: tidy up pgjwt package
thoughtpolice Aug 6, 2018
3cbd0b2
nixpkgs: implement new postgresqlPackages infrastructure
thoughtpolice Aug 6, 2018
1cee11f
nixpkgs: migrate postgis to new postgresqlPackages infrastructure
thoughtpolice Aug 6, 2018
1864fc3
postgresqlPackages: add myself as a maintainer
thoughtpolice Aug 6, 2018
4eaf18b
postgresqlPackages: add versionCheck passthru to extension builds for…
thoughtpolice Aug 6, 2018
83e0444
postgresqlPackages.timescaledb: only works on 9.6+
thoughtpolice Aug 6, 2018
96babf1
postgresqlPackages.pg_cron: only works on 9.5+
thoughtpolice Aug 6, 2018
4c257d7
postgresqlPackages.pg_topn: only works on 9.4+
thoughtpolice Aug 6, 2018
ebcffbc
postgresqlPackages.pg_jobmon: init at 1.3.3
thoughtpolice Aug 6, 2018
f9c2f8d
postgresqlPackages.pg_partman: init at 3.1.2
thoughtpolice Aug 6, 2018
e5ad1dc
nixos/postgresql: add myself as the module maintainer
thoughtpolice Aug 6, 2018
2842c50
nixos/postgresql: kill ugly hack, now that postgresql has 'version' a…
thoughtpolice Aug 6, 2018
16624c6
nixos/postgresql: add new nixos module API
thoughtpolice Aug 6, 2018
31e15da
nixos/tests: migrate postgis test to new postgres API
thoughtpolice Aug 6, 2018
87ccdbe
nixpkgs/nixos: switch to PostgreSQL 10 by default
thoughtpolice Aug 6, 2018
ef1f8be
nixos/postgres: update manual
thoughtpolice Aug 6, 2018
44fc8a9
nixpkgs: actually deprecate old postgresql extension names
thoughtpolice Aug 6, 2018
2f32398
nixos/tests: migrate to new postgresql api
thoughtpolice Aug 6, 2018
f20b306
postgresql: always create $out/bin (issue #22653).
basvandijk Aug 6, 2018
b671e68
postgresqlPackages.pg_journal: init at 0.2.0
basvandijk Aug 6, 2018
8bdf30e
postgresqlPackages.tsearch_extras: 0.3 -> 0.4
thoughtpolice Aug 6, 2018
5083436
postgresqlPackages.pg_cron: 1.0.2 -> 1.1.2
thoughtpolice Aug 6, 2018
7571fb4
postgresqlPackages.pg_partman: 3.1.2 -> 3.2.1
thoughtpolice Aug 6, 2018
6f6dcc0
postgresqlPackages.pg_topn 2.0.2 -> 2.1.0
thoughtpolice Aug 6, 2018
1e83cf3
postgresql: enable systemd service notification on 9.6+
thoughtpolice Aug 6, 2018
af3d0e5
postgresqlPackages: simplify versionCheck comparisons
thoughtpolice Aug 6, 2018
7c8281c
postgresqlPackages.pg_repack: (re)indent to 2 spaces
thoughtpolice Aug 6, 2018
fafa88f
nixos/manual: add 18.09 release notes for PostgreSQL
thoughtpolice Aug 6, 2018
f30de35
postgresql: add postgresql 11.0 beta2 package
thoughtpolice Aug 6, 2018
dcd9455
postgresql11: preliminary JIT support
thoughtpolice Aug 6, 2018
8caf523
postgresql11: remove hard clang dependency for JIT support
thoughtpolice Aug 6, 2018
91841ff
postgresql11: keep bitcode/llvmjit.so in $out, not $lib
thoughtpolice Aug 6, 2018
dce94b7
postgresqlPackages: add new withPackages combinator
thoughtpolice Aug 6, 2018
9b06c7a
postgresqlPackages.pg_similarity: remove needless dir
thoughtpolice Aug 6, 2018
49dbf9f
postgresqlPackages: make PGXS install phase Nix-compatible
thoughtpolice Aug 6, 2018
54ec98d
nixos/manual: finish section on PostgreSQL server upgrades
thoughtpolice Aug 6, 2018
4119c9f
postgresqlPackages: init citus 7.5.0
thoughtpolice Aug 6, 2018
429f350
postgresqlPackages.postgis: fix gdal against the same postgresql the …
thoughtpolice Aug 6, 2018
a022a95
postgresqlPackages: expose a set containing all postgresqlPackages se…
thoughtpolice Aug 6, 2018
364c06b
nixos/postgresql-backup: migrate to new module API
thoughtpolice Aug 6, 2018
73866e5
nixos/tests: touch up PostgreSQL tests, migrate to new module API
thoughtpolice Aug 6, 2018
c0a7848
nixos/tests: wibble for postgis tests [NFC]
thoughtpolice Aug 6, 2018
2fc694e
nixos/tests: touch up pgjwt tests
thoughtpolice Aug 6, 2018
69dd764
nixos/tests: migrate trac to new postgresql API
thoughtpolice Aug 6, 2018
01610cf
nixos/virtualisation: fix example
thoughtpolice Aug 6, 2018
224ca9f
nixos/gitea: update to new PostgreSQL interface
thoughtpolice Aug 6, 2018
9e398a1
nixos/gitlab: use new postgres module API
thoughtpolice Aug 6, 2018
075f1b7
nixos/matrix-synapse: use new postgres module API
thoughtpolice Aug 6, 2018
0b3d622
postgresqlPackages.postgis: enable PostgreSQL 11 JIT support
thoughtpolice Aug 6, 2018
0b7377a
postgresqlPackages: remove outdated comments
thoughtpolice Aug 6, 2018
c2e3535
nixos/manual: add more postgresql modules to 18.09 release notes
thoughtpolice Aug 6, 2018
c3919f5
nixos/postgresql: give the plugins option the selectorFunction type
basvandijk Aug 7, 2018
da504b6
nixos/postgresql: give the postgres user a homedir and shell
thoughtpolice Aug 7, 2018
bcf4858
timescaledb-parallel-copy: init at 2018-05-14
thoughtpolice Aug 7, 2018
8a0deeb
postgresqlPackages: add .man to all withPackage/NixOS configurations
thoughtpolice Aug 7, 2018
0ca1def
postgresqlPackages: enable LLVM JIT by default on PostgreSQL 11+
thoughtpolice Aug 15, 2018
9a88df8
postgresql: add doc section id module-services-postgres-new-extensions
basvandijk Sep 9, 2018
a1d18b7
postgresql: introduce the deprecated, readOnly and invisible postgres…
basvandijk Sep 10, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions nixos/doc/manual/release-notes/rl-1809.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,33 @@
</para>

<itemizedlist>
<listitem>
<para>
The PostgreSQL server infrastructure has been greatly improved and is
much easier to use. Extensions are always built against the correct
version of the server without overrides. Server versions are exposed as
"sets" of packages along with their compatible extensions, which are all
compiled and checked continuously. This means you can now use extensions
like plv8 with any PostgreSQL version without compiling anything.
Extensions expressions are easier to write, and new extensions are
available: <literal>pg_cron</literal>, <literal>postgres-hll</literal>,
<literal>postgres-topn</literal>, <literal>pg_journal</literal>,
<literal>pg_jobmon</literal>, <literal>pg_partman</literal>,
and <literal>citus</literal>. (Almost all existing extensions have seen
version updates, as well.)
</para>
<para>
NixOS 18.09 is the last release that will offer PostgreSQL 9.3 as a
server option. 9.3 will reach its 5-year End of Life in September 2018;
the NixOS 18.09 branch will see no updates at all to PostgreSQL 9.3. It
will only be available to keep existing servers running, so they may be
migrated to new versions.
</para>
<para>
PostgreSQL 10 is now the default option for new NixOS 18.09
installations.
</para>
</listitem>
<listitem>
<para>
Support for wrapping binaries using <literal>firejail</literal> has been
Expand Down
4 changes: 2 additions & 2 deletions nixos/modules/services/backup/bacula.nix
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,8 @@ in {
serviceConfig.ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
preStart = ''
if ! test -e "${libDir}/db-created"; then
${pkgs.postgresql}/bin/createuser --no-superuser --no-createdb --no-createrole bacula
#${pkgs.postgresql}/bin/createdb --owner bacula bacula
${config.services.postgresql.postgresqlPackage}/bin/createuser --no-superuser --no-createdb --no-createrole bacula
#${config.services.postgresql.postgresqlPackage}/bin/createdb --owner bacula bacula

# populate DB
${pkgs.bacula}/etc/create_bacula_database postgresql
Expand Down
74 changes: 36 additions & 38 deletions nixos/modules/services/backup/postgresql-backup.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,44 @@
with lib;

let

cfg = config.services.postgresqlBackup;

postgresqlBackupService = db :
{
enable = true;

description = "Backup of database ${db}";

requires = [ "postgresql.service" ];

preStart = ''
mkdir -m 0700 -p ${cfg.location}
chown postgres ${cfg.location}
'';

script = ''
if [ -e ${cfg.location}/${db}.sql.gz ]; then
${pkgs.coreutils}/bin/mv ${cfg.location}/${db}.sql.gz ${cfg.location}/${db}.prev.sql.gz
fi

${config.services.postgresql.package}/bin/pg_dump ${cfg.pgdumpOptions} ${db} | \
${pkgs.gzip}/bin/gzip -c > ${cfg.location}/${db}.sql.gz
'';

serviceConfig = {
Type = "oneshot";
PermissionsStartOnly = "true";
User = "postgres";
};

startAt = cfg.startAt;
postgresqlBackupService = db: {
description = "Backup of database ${db}";
enable = true;
requires = [ "postgresql.service" ];
startAt = cfg.startAt;

preStart = ''
mkdir -m 0700 -p ${cfg.location}
chown postgres ${cfg.location}
'';

script = ''
# Use the same PATH as the PostgreSQL instance, as it's configured
# with plugins and extensions. This is a bit of a hack; we can't easily
# set the nixos systemd options to do this, because the path is already
# constructed and is too long by the time the systemd.nix module examines
# it
export PATH="${config.systemd.services.postgresql.environment.PATH}"

if [ -e ${cfg.location}/${db}.sql.gz ]; then
mv ${cfg.location}/${db}.sql.gz ${cfg.location}/${db}.prev.sql.gz
fi

pg_dump ${cfg.pgdumpOptions} ${db} | ${pkgs.gzip}/bin/gzip -c > ${cfg.location}/${db}.sql.gz
'';

serviceConfig = {
Type = "oneshot";
PermissionsStartOnly = "true";
User = "postgres";
};
};

in {

options = {

services.postgresqlBackup = {

enable = mkOption {
default = false;
description = ''
Expand Down Expand Up @@ -81,14 +79,14 @@ in {
'';
};
};

};

config = mkIf config.services.postgresqlBackup.enable {

systemd.services = listToAttrs (map (db : {
name = "postgresqlBackup-${db}";
value = postgresqlBackupService db; } ) cfg.databases);
};
systemd.services = listToAttrs (map (db: {
name = "postgresqlBackup-${db}";
value = postgresqlBackupService db;
}) cfg.databases);

};
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ let

cfg = config.services.hydra;

pg = config.services.postgresql;

baseDir = "/var/lib/hydra";

hydraConf = pkgs.writeScript "hydra.conf" cfg.extraConfig;
Expand Down Expand Up @@ -271,8 +273,8 @@ in

${optionalString haveLocalDB ''
if ! [ -e ${baseDir}/.db-created ]; then
${pkgs.sudo}/bin/sudo -u ${config.services.postgresql.superUser} ${config.services.postgresql.package}/bin/createuser hydra
${pkgs.sudo}/bin/sudo -u ${config.services.postgresql.superUser} ${config.services.postgresql.package}/bin/createdb -O hydra hydra
${pkgs.sudo}/bin/sudo -u ${pg.superUser} ${pg.postgresqlPackage}/bin/createuser hydra
${pkgs.sudo}/bin/sudo -u ${pg.superUser} ${pg.postgresqlPackage}/bin/createdb -O hydra hydra
touch ${baseDir}/.db-created
fi
''}
Expand Down
132 changes: 109 additions & 23 deletions nixos/modules/services/databases/postgresql.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,16 @@ let

cfg = config.services.postgresql;

packageSetPlugins = cfg.plugins cfg.packages;
plugins = if cfg.extraPlugins != [] then cfg.extraPlugins else packageSetPlugins;

# 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;
buildInputs = [ pkgs.makeWrapper ];
postBuild =
''
mkdir -p $out/bin
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
'';
};
# See the note about withPackages in postgresql/packages.nix for more
let ps = import ../../../../pkgs/servers/sql/postgresql/packages.nix { inherit pkgs lib; };
in ps.withPackages pg plugins;

postgresql = postgresqlAndPlugins cfg.package;
postgresql = postgresqlAndPlugins cfg.postgresqlPackage;

# The main PostgreSQL configuration file.
configFile = pkgs.writeText "postgresql.conf"
Expand All @@ -35,6 +28,18 @@ let
${cfg.extraConfig}
'';

# TODO: propose to move this to lib/types.nix
# since selector functions are used in at least 6 other options in NixOS.
selectorFunction = mkOptionType {
name = "selectorFunction";
description =
"function that takes an attribute set and returns a list " +
"containing a selection of the values of the input set";
check = select: isFunction select;
merge = _loc: defs:
as: concatMap (select: select as) (getValues defs);
};

in

{
Expand All @@ -54,10 +59,37 @@ in
};

package = mkOption {
type = types.package;
type = types.nullOr types.package;
example = literalExample "pkgs.postgresql96";
default = null;
description = ''
PostgreSQL package to use.
PostgreSQL package to use. Deprecated. Use services.postgresql.packages instead
to specify an entire package set (including compatible extensions) at once.
'';
};

packages = mkOption {
type = types.nullOr (types.attrsOf types.package);
default = null;
example = literalExample "pkgs.postgresql96Packages";
description = ''
The set of PostgreSQL packages to use, including the database
server and all available extensions.
'';
};

postgresqlPackage = mkOption {
type = types.package;
default =
if cfg.package != null
then cfg.package
else cfg.packages.postgresql;
readOnly = true;
visible = false;
description = ''
A deprecated, read-only and invisible option that refers to the
selected PostgreSQL package. This should be removed at the same time
that the deprecated config.services.postgresql.package option is removed.
'';
};

Expand Down Expand Up @@ -120,11 +152,31 @@ in
default = [];
example = literalExample "[ (pkgs.postgis.override { postgresql = pkgs.postgresql94; }) ]";
description = ''
When this list contains elements a new store path is created.
Deprecated. 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.

This attribute is hard to use, and is deprecated in favor of the more general
services.postgresql.plugins attribute, which will correctly override the specified
packages for you.
'';
};

plugins = mkOption {
default = _: [];
type = selectorFunction;
example = literalExample "p: with p; [ postgis timescaledb ]";
description = ''
A function that selects plugins to include in the PostgreSQL server.
When this function returns a non-empty list, 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.

The value provided as an argument to the function is the set of available
PostgreSQL plugins, specified by the services.postgresql.packages argument.
'';
# Note: the duplication of executables is about 4MB size.
# So a nicer solution was patching postgresql to allow setting the
Expand Down Expand Up @@ -163,16 +215,46 @@ in

config = mkIf config.services.postgresql.enable {

services.postgresql.package =
assertions =
[ # The user specified both 'package' and 'packages', which are mutually exclusive
{ assertion = (cfg.package != null -> cfg.packages != null);
message = ''
The option services.postgresql.{package,packages} cannot both be set. Please use the 'packages' option
to specify the entire set of PostgreSQL packages.
'';
}

# The user specified the old extraPlugins attribute, but they *also* specified some 'plugins' function
# which returned a non-empty list. These are mutually exclusive.
{ assertion = (cfg.extraPlugins != [] -> packageSetPlugins == []);
message = ''
The option services.postgresql.extraPlugins and .plugins cannot both be non-empty at the same time; please remove
uses of .extraPlugins.
'';
}
];

warnings =
(optional (cfg.package != null)
''The services.postgresql.package attribute is deprecated. Please use services.postgresql.packages (with an 's') instead.
See the NixOS manual ('nixos-help') for more information.'') ++
(optional (cfg.extraPlugins != [])
''The services.postgresql.extraPlugins attribute is deprecated. Please use services.postgresql.plugins instead,
which will correctly override PostgreSQL attributes for you and will provide a list of compatible plugins for
the given server version.
'');

services.postgresql.packages =
# 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.postgresql96
else if versionAtLeast config.system.stateVersion "16.03" then pkgs.postgresql95
else pkgs.postgresql94);
mkDefault (if versionAtLeast config.system.stateVersion "18.09" then pkgs.postgresql10Packages
else if versionAtLeast config.system.stateVersion "17.09" then pkgs.postgresql96Packages
else if versionAtLeast config.system.stateVersion "16.03" then pkgs.postgresql95Packages
else pkgs.postgresql94Packages);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be made dependent on cfg.package.version instead of config.system.stateVersion?

Copy link
Member Author

@thoughtpolice thoughtpolice May 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The intent is that e.g. if you were on NixOS 16.03, and you upgrade to NixOS 17.09, you should keep using PostgreSQL 9.5, because 9.6 is not on-disk compatible, and breaking your database across an upgrade isnt friendly. This is because when you installed NixOS, the (16.03) installer explicitly sets stateVersion = "16.03" in configuration.nix by default, and that should not be changed even beyond upgrades.

I might be misunderstanding what you mean, of course (a diff would be helpful if that's the case!). But otherwise, this logic must remain to not break already-installed databases.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't a direct problem by itself, but rather a simplification for those who use PG older than NixOS default. When you set services.postgresql.package to some old version, you now have to set services.postgresql.packages to an older pacakgeset too, which, I think, can be detected by NixOS automatically.


services.postgresql.dataDir =
mkDefault (if versionAtLeast config.system.stateVersion "17.09" then "/var/lib/postgresql/${config.services.postgresql.package.psqlSchema}"
mkDefault (if versionAtLeast config.system.stateVersion "17.09" then "/var/lib/postgresql/${cfg.postgresqlPackage.psqlSchema}"
else "/var/db/postgresql");

services.postgresql.authentication = mkAfter
Expand All @@ -188,6 +270,8 @@ in
uid = config.ids.uids.postgres;
group = "postgres";
description = "PostgreSQL server user";
home = "${cfg.dataDir}";
useDefaultShell = true;
};

users.groups.postgres.gid = config.ids.gids.postgres;
Expand Down Expand Up @@ -245,6 +329,8 @@ in
# Give Postgres a decent amount of time to clean up after
# receiving systemd's SIGINT.
TimeoutSec = 120;

Type = if versionAtLeast cfg.postgresqlPackage.psqlSchema "9.6" then "notify" else "simple";
};

# Wait for PostgreSQL to be ready to accept connections.
Expand All @@ -269,5 +355,5 @@ in
};

meta.doc = ./postgresql.xml;

meta.maintainers = with lib.maintainers; [ thoughtpolice ];
}
Loading