Commit Graph

128 Commits

Author SHA1 Message Date
Wolfgang Walther
14b3ea2789
postgresql: refactor to pass jitSupport/llvm via scope instead of passthru
This makes it less error-prone to use the llvm package in extensions, because
it will always match the package used by the postgresql derivation itself.

Previously, you could've accidentally used llvm instead of postgresql.llvm
with a different result.
2024-03-15 21:11:09 +01:00
Maximilian Bosch
d363f52625
nixos/postgresql: drop ensurePermissions option
...effectively what was planned already in #266270, but it was too late
because the branches were restricted and didn't allow any breaking
changes anymore.

It also suffers from the same issue that we already had when discussing
this the last time[1] when `ensureDBOwnership` was ultimately introduced
as band-aid fix: newly created users don't get CREATE permission on
the `public` schema anymore (since psql 15), even with `ALL PRIVILEGES`.

If one's use-case is more sophisticated than having a single owner, it's
questionable anyways if this module is the correct tool since
permissions aren't dropped on a change to this option or a removal which
is pretty surprising in the context of NixOS.

[1] https://github.com/NixOS/nixpkgs/pull/266270
2024-02-12 21:10:33 +01:00
Thomas Gerbet
a9da4c2260
Merge pull request #257504 from SuperSandro2000/postgres-doc
nixos/postgresql: point doc link to current like all others
2023-12-15 00:43:13 +01:00
Sandro Jäckel
4fe5824fc7
nixos/postgresql: take extraPlugins packageset from package option
This allows to reuse the extraPlugins option in other context's for
example an upgrade script.
2023-12-08 14:58:18 +01:00
h7x4
0a37316d6c
treewide: use mkPackageOption
This commit replaces a lot of usages of `mkOption` with the package
type, to be `mkPackageOption`, in order to reduce the amount of code.
2023-11-27 01:28:36 +01:00
Sandro Jäckel
515ce669bc
nixos/postgresql: point doc link to current like all others 2023-11-20 14:44:23 +01:00
Sandro
809f926017
nixos/postgresql: fix mentioned settings in ensurePermissions warnings 2023-11-20 14:42:57 +01:00
Raito Bezarius
d57926c0b6 nixos/postgresql: improve the assertions for equality of DB user and DB name
It is hard to figure out which one is offending without the database name.
2023-11-13 17:16:25 +01:00
Raito Bezarius
12797a6a39 nixos/postgresql: restore ensurePermissions and strong-deprecate it
As it is technically a breaking change, we should at least make a strong deprecation
of `ensurePermissions` and leave it in the broken state it is, for out of tree users.

We give them a 6 months notice to migrate away by doing so, which is honest.
In the meantime, we forbid usage of `ensurePermissions` inside of nixpkgs.
2023-11-13 17:16:25 +01:00
Maximilian Bosch
48459567ae nixos/postgresql: drop ensurePermissions, fix ensureUsers for postgresql15
Closes #216989

First of all, a bit of context: in PostgreSQL, newly created users don't
have the CREATE privilege on the public schema of a database even with
`ALL PRIVILEGES` granted via `ensurePermissions` which is how most of
the DB users are currently set up "declaratively"[1]. This means e.g. a
freshly deployed Nextcloud service will break early because Nextcloud
itself cannot CREATE any tables in the public schema anymore.

The other issue here is that `ensurePermissions` is a mere hack. It's
effectively a mixture of SQL code (e.g. `DATABASE foo` is relying on how
a value is substituted in a query. You'd have to parse a subset of SQL
to actually know which object are permissions granted to for a user).

After analyzing the existing modules I realized that in every case with
a single exception[2] the UNIX system user is equal to the db user is
equal to the db name and I don't see a compelling reason why people
would change that in 99% of the cases. In fact, some modules would even
break if you'd change that because the declarations of the system user &
the db user are mixed up[3].

So I decided to go with something new which restricts the ways to use
`ensure*` options rather than expanding those[4]. Effectively this means
that

* The DB user _must_ be equal to the DB name.
* Permissions are granted via `ensureDBOwnerhip` for an attribute-set in
  `ensureUsers`. That way, the user is actually the owner and can
  perform `CREATE`.
* For such a postgres user, a database must be declared in
  `ensureDatabases`.

For anything else, a custom state management should be implemented. This
can either be `initialScript`, doing it manual, outside of the module or
by implementing proper state management for postgresql[5], but the
current state of `ensure*` isn't even declarative, but a convergent tool
which is what Nix actually claims to _not_ do.

Regarding existing setups: there are effectively two options:

* Leave everything as-is (assuming that system user == db user == db
  name): then the DB user will automatically become the DB owner and
  everything else stays the same.

* Drop the `createDatabase = true;` declarations: nothing will change
  because a removal of `ensure*` statements is ignored, so it doesn't
  matter at all whether this option is kept after the first deploy (and
  later on you'd usually restore from backups anyways).

  The DB user isn't the owner of the DB then, but for an existing setup
  this is irrelevant because CREATE on the public schema isn't revoked
  from existing users (only not granted for new users).

[1] not really declarative though because removals of these statements
    are simply ignored for instance: https://github.com/NixOS/nixpkgs/issues/206467
[2] `services.invidious`: I removed the `ensure*` part temporarily
    because it IMHO falls into the category "manage the state on your
    own" (see the commit message). See also
    https://github.com/NixOS/nixpkgs/pull/265857
[3] e.g. roundcube had `"DATABASE ${cfg.database.username}" = "ALL PRIVILEGES";`
[4] As opposed to other changes that are considered a potential fix, but
    also add more things like collation for DBs or passwords that are
    _never_ touched again when changing those.
[5] As suggested in e.g. https://github.com/NixOS/nixpkgs/issues/206467
2023-11-13 17:16:25 +01:00
Anthony Roussel
e30f48be94
treewide: fix redirected and broken URLs
Using the script in maintainers/scripts/update-redirected-urls.sh
2023-11-11 10:49:01 +01:00
Maximilian Bosch
1220a4d4dd
postgresql_11: remove
As described in the release lifecycle docs from postgresql[1], v11 will
stop receiving fixes as of Nov 9 2023. This means it's EOL throughout
the entire lifetime of 23.11, so let's drop it now.

A lot of examples are also referencing postgresql_11. Where it's
sensible, use postgresql_15 as example now to avoid confusion.

This is also handy because the LLVM 16 fix for postgresql is not
available for postgresql 11 ;-)

[1] https://www.postgresql.org/support/versioning/
2023-10-30 10:41:16 +01:00
github-actions[bot]
75d4639be3
Merge master into staging-next 2023-10-09 18:00:59 +00:00
Maximilian Bosch
9f1d4b79e3
nixos/postgresql: fix identMap example
This was causing the following warning before when building the manual:

    warning: literalExample is deprecated, use literalExpression instead, or use literalMD for a non-Nix description.

Rather than using `literalExpression`, nothing is used. This option
expects a string and the example is a string, no special handling
required. Both `literalExample` from the docbook ages and
`literalExpression` now are only required if the example is
a Nix expression rather than a value of the option's type.
2023-10-09 17:41:44 +02:00
github-actions[bot]
b7f2311d92
Merge staging-next into staging 2023-09-27 18:01:33 +00:00
Gary Guo
e037977239 postgresql: default to v15 in 23.11 2023-09-27 03:51:06 +02:00
Matthieu Coudron
b53c715e50 services.postgres: add initialScript example 2023-09-18 11:57:58 +02:00
Matthieu Coudron
956a1876aa services.postgresql: add identMap example
to make things clearer
2023-09-18 11:57:58 +02:00
Matthieu Coudron
482619dac7 services.postgres: move the generated statement at the top of the file 2023-09-18 11:57:57 +02:00
Matthieu Coudron
6774f3fc04 services.postgresql: fix example 2023-07-27 11:35:55 -05:00
Robert Hensing
2e2f0d28ea nixos: Use checks instead of extraDependencies
... as appropriate.

This drops a few unnecessary store paths from the system closure.
2023-05-11 21:18:38 +02:00
Maximilian Bosch
e2fb651752
nixos/postgresql: fix enableJIT
Make sure that JIT is actually available when using

    services.postgresql = {
      enable = true;
      enableJIT = true;
      package = pkgs.postgresql_15;
    };

The current behavior is counter-intuitive because the docs state that
`enableJIT = true;` is sufficient even though it wasn't in that case
because the declared package doesn't have the LLVM dependency.

Fixed by using `package.withJIT` if `enableJIT = true;` and
`package.jitSupport` is `false`.

Also updated the postgresql-jit test to test for that case.
2023-03-29 08:39:47 +02:00
Maximilian Bosch
43dbeae02d
postgresql: pass through JIT-enabled variant of non-JIT postgres and vice versa
This is useful if your postgresql version is dependant on
`system.stateVersion` and not pinned down manually. Then it's not
necessary to find out which version exactly is in use and define
`package` manually, but just stay with what NixOS provides as default:

    $ nix-instantiate -A postgresql
    /nix/store/82fzmb77mz2b787dgj7mn4a8i4f6l6sn-postgresql-14.7.drv
    $ nix-instantiate -A postgresql_jit
    /nix/store/qsjkb72fcrrfpsszrwbsi9q9wgp39m50-postgresql-14.7.drv
    $ nix-instantiate -A postgresql.withJIT
    /nix/store/qsjkb72fcrrfpsszrwbsi9q9wgp39m50-postgresql-14.7.drv
    $ nix-instantiate -A postgresql.withJIT.withoutJIT
    /nix/store/82fzmb77mz2b787dgj7mn4a8i4f6l6sn-postgresql-14.7.drv

I.e. you can use postgresql with JIT (for complex queries only[1]) like
this:

    services.postgresql = {
      enable = true;
      enableJIT = true;
    };

Performing a new override instead of re-using the `_jit`-variants for
that has the nice property that overlays for the original package apply
to the JIT-enabled variant, i.e.

    with import ./. {
      overlays = [
        (self: super: {
          postgresql = super.postgresql.overrideAttrs (_: { fnord = "snens"; });
        })
      ];
    };
    postgresql.withJIT.fnord

still gives the string `snens` whereas `postgresql_jit` doesn't have the
attribute `fnord` in its derivation.

[1] https://www.postgresql.org/docs/current/runtime-config-query.html#GUC-JIT-ABOVE-COST
2023-03-29 08:39:46 +02:00
pennae
0a6e6cf7e6 nixos/manual: render module chapters with nixos-render-docs
this converts meta.doc into an md pointer, not an xml pointer. since we
no longer need xml for manual chapters we can also remove support for
manual chapters from md-to-db.sh

since pandoc converts smart quotes to docbook quote elements and our
nixos-render-docs does not we lose this distinction in the rendered
output. that's probably not that bad, our stylesheet didn't make use of
this anyway (and pre-23.05 versions of the chapters didn't use quote
elements either).

also updates the nixpkgs manual to clarify that option docs support all
extensions (although it doesn't support headings at all, so heading
anchors don't work by extension).
2023-01-27 20:07:34 +01:00
Robert Hensing
7bfbf037d7 Merge remote-tracking branch 'upstream/master' into allow-configuration-of-roles 2022-12-02 18:12:14 +00:00
Daniel Nagy
dbe8182e74
treewide: switch to port type for nixos modules 2022-12-01 22:30:00 +01:00
Jonathan Lorimer
4e502a1c4d
Update nixos/modules/services/databases/postgresql.nix
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2022-11-28 10:21:18 -05:00
Jonathan Lorimer
193aa6faf4
Add declarative role config to postgres.service
remove trailing whitespace

switch docs to markdown

use mdDoc

remove trailing whitespace

get rid of double space

add tests and update options to use submodule

remove whitespace

remove whitespace

use mdDoc

remove whitespace

make default a no-op

make ALTER ROLE a single sql statement

document null case
2022-11-28 09:44:46 -05:00
pennae
722b99bc0e nixos/*: convert options with admonitions to MD
rendering changes only slightly, most changes are in spacing.
2022-08-31 16:36:16 +02:00
pennae
9547123258 nixos/*: convert internal option descriptions to MD
we'll have to do it eventually, may as well be now.
2022-08-31 16:32:54 +02:00
pennae
ef176dcf7e nixos/*: automatically convert option descriptions
conversions were done using https://github.com/pennae/nix-doc-munge
using (probably) rev f34e145 running

    nix-doc-munge nixos/**/*.nix
    nix-doc-munge --import nixos/**/*.nix

the tool ensures that only changes that could affect the generated
manual *but don't* are committed, other changes require manual review
and are discarded.
2022-08-31 16:32:53 +02:00
pennae
6039648c50 nixos/*: automatically convert option docs 2022-08-19 22:40:58 +02:00
pennae
f1d39b6d61 nixos/postgresql: replace <function> with <literal>
there's only this one use, we can live with the tiny rendering change.
2022-08-19 22:40:58 +02:00
pennae
61e93df189 nixos/*: automatically convert option docs to MD
once again using nix-doc-munge (69d080323a)
2022-08-03 22:46:41 +02:00
pennae
3aebb4a2be nixos/*: normalize link format
make (almost) all links appear on only a single line, with no
unnecessary whitespace, using double quotes for attributes. this lets us
automatically convert them to markdown easily.

the few remaining links are extremely long link in a gnome module, we'll
come back to those at a later date.
2022-08-03 21:57:46 +02:00
pennae
16102dce2f nixos/*: replace <code> in option docs with <literal>
markdown can't represent the difference without another extension and
both the html manual and the manpage render them the same, so keeping the
distinction is not very useful on its own. with the distinction removed
we can automatically convert many options that use <code> tags to markdown.

the manpage remains unchanged, html manual does not render
differently (but class names on code tags do change from "code" to "literal").
2022-08-03 21:03:23 +02:00
pennae
2e751c0772 treewide: automatically md-convert option descriptions
the conversion procedure is simple:

 - find all things that look like options, ie calls to either `mkOption`
   or `lib.mkOption` that take an attrset. remember the attrset as the
   option
 - for all options, find a `description` attribute who's value is not a
   call to `mdDoc` or `lib.mdDoc`
 - textually convert the entire value of the attribute to MD with a few
   simple regexes (the set from mdize-module.sh)
 - if the change produced a change in the manual output, discard
 - if the change kept the manual unchanged, add some text to the
   description to make sure we've actually found an option. if the
   manual changes this time, keep the converted description

this procedure converts 80% of nixos options to markdown. around 2000
options remain to be inspected, but most of those fail the "does not
change the manual output check": currently the MD conversion process
does not faithfully convert docbook tags like <code> and <package>, so
any option using such tags will not be converted at all.
2022-07-30 15:16:34 +02:00
Ivan Kozik
96a8c0ac23 nixos/postgresql: use postgres 14 for 22.05
postgresql: alias to postgresql_14
2022-05-03 22:23:08 +00:00
ajs124
757dd008b2 postgresql_9_6: drop 2021-12-03 01:14:29 +01:00
Naïm Favier
2ddc335e6f
nixos/doc: clean up defaults and examples 2021-10-04 12:47:20 +02:00
Yuka
7d24d06c71
nixos/postgresql: use postgres 13 for 21.11 (#131018)
Co-authored-by: Kim Lindberger <kim.lindberger@gmail.com>
2021-07-24 19:12:08 +02:00
Richard Marko
29158fc0ac nixos/postgresql: fix description of ensureUsers.ensurePermissions
`attrName` and `attrValue` are now in correct order.
2021-05-17 18:03:04 +09:00
Mario Rodas
72ab382fb6 postgresql_9_5: drop
PostgreSQL 9.5 has reached EOL on February 11, 2021.
See https://www.postgresql.org/support/versioning/
2021-04-01 04:20:00 +00:00
Joe Hermaszewski
580d88efa0
services.postgresql: Improve example clarity
Although the quotes here aren't necessary, they may be if a user cargo-cults this example with a database name with hyphens (or other "unusual" characters).
2021-04-10 11:12:36 +08:00
Guillaume Girol
fe0e0afbc0
Merge pull request #92929 from symphorien/postgresql-check-config-file
nixos/postgresql: check config file syntax at build time
2021-04-02 16:27:03 +00:00
Jade
2df221ec8a
nixos/postgresql: fix inaccurate docs for authentication (#97622)
* nixos/postgresql: fix inaccurate docs for authentication

We actually use peer authentication, then md5 based authentication.
trust is not used.

* Use a link for mkForce docs

Co-authored-by: aszlig <aszlig@redmoonstudios.org>

Co-authored-by: lf- <lf-@users.noreply.github.com>
Co-authored-by: aszlig <aszlig@redmoonstudios.org>
2020-10-31 03:35:19 -04:00
Symphorien Gibol
1b7ca69ecc nixos/postgresql: check config file syntax at build time 2020-09-20 13:43:20 +02:00
Aaron Andersen
2a44265608 nixos/postgresql: replace extraConfig option with settings option 2020-08-26 17:06:48 -04:00
Aaron Andersen
8e045b42fd nixos/postgresql: move ExecStartPost into postStart 2020-08-15 16:59:53 -04:00
Aaron Andersen
ec82ae3c39 nixos/postgresql: run ExecStartPost as an unprivileged user 2020-08-15 16:59:49 -04:00