From caa0f82bf8a0bf7712c9c004be45380ce6e78dd3 Mon Sep 17 00:00:00 2001 From: Danylo Hlynskyi Date: Sun, 21 Jul 2019 22:05:41 +0300 Subject: [PATCH] docs: update docs for postgresql plugins (#64899) docs: update docs for postgresql plugins Co-Authored-By: Mario Rodas --- .../modules/services/databases/postgresql.nix | 40 +++-------- .../modules/services/databases/postgresql.xml | 70 ++++++++++++++++++- pkgs/servers/sql/postgresql/default.nix | 3 + 3 files changed, 80 insertions(+), 33 deletions(-) diff --git a/nixos/modules/services/databases/postgresql.nix b/nixos/modules/services/databases/postgresql.nix index bc47e7e1e0dc..37d44e30fbeb 100644 --- a/nixos/modules/services/databases/postgresql.nix +++ b/nixos/modules/services/databases/postgresql.nix @@ -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" @@ -58,7 +42,7 @@ in package = mkOption { type = types.package; - example = literalExample "pkgs.postgresql_9_6"; + example = literalExample "pkgs.postgresql_11"; description = '' PostgreSQL package to use. ''; @@ -74,7 +58,7 @@ in dataDir = mkOption { type = types.path; - example = "/var/lib/postgresql/9.6"; + example = "/var/lib/postgresql/11"; description = '' Data directory for PostgreSQL. ''; @@ -195,17 +179,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 services.postgresql.package 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 { diff --git a/nixos/modules/services/databases/postgresql.xml b/nixos/modules/services/databases/postgresql.xml index 00bb02dcc5bf..02db47568d33 100644 --- a/nixos/modules/services/databases/postgresql.xml +++ b/nixos/modules/services/databases/postgresql.xml @@ -27,10 +27,10 @@ configuration.nix: = true; - = pkgs.postgresql_9_4; + = pkgs.postgresql_11; Note that you are required to specify the desired version of PostgreSQL - (e.g. pkgs.postgresql_9_4). Since upgrading your + (e.g. pkgs.postgresql_11). Since upgrading your PostgreSQL version requires a database dump and reload (see below), NixOS cannot provide a default value for such as the most recent @@ -74,4 +74,70 @@ Type "help" for help. here. +
+ Plugins + + + Plugins collection for each PostgreSQL version can be accessed with + .pkgs. For example, for + pkgs.postgresql_11 package, its plugin collection is + accessed by pkgs.postgresql_11.pkgs: + +$ nix repl '<nixpkgs>' + +Loading '<nixpkgs>'... +Added 10574 variables. + +nix-repl> postgresql_11.pkgs.<TAB><TAB> +postgresql_11.pkgs.cstore_fdw postgresql_11.pkgs.pg_repack +postgresql_11.pkgs.pg_auto_failover postgresql_11.pkgs.pg_safeupdate +postgresql_11.pkgs.pg_bigm postgresql_11.pkgs.pg_similarity +postgresql_11.pkgs.pg_cron postgresql_11.pkgs.pg_topn +postgresql_11.pkgs.pg_hll postgresql_11.pkgs.pgjwt +postgresql_11.pkgs.pg_partman postgresql_11.pkgs.pgroonga +... + + + + To add plugins via NixOS configuration, set services.postgresql.extraPlugins: + + = pkgs.postgresql_11; + = with pkgs.postgresql_11.pkgs; [ + pg_repack + postgis +]; + + + + You can build custom PostgreSQL-with-plugins (to be used outside of NixOS) using + function .withPackages. For example, creating a custom + PostgreSQL package in an overlay can look like: + +self: super: { + postgresql_custom = self.postgresql_11.withPackages (ps: [ + ps.pg_repack + ps.postgis + ]); +} + + + + Here's a recipe on how to override a particular plugin through an overlay: + +self: super: { + postgresql_11 = super.postgresql_11.override { this = self.postgresql_11; } // { + pkgs = super.postgresql_11.pkgs // { + pg_repack = super.postgresql_11.pkgs.pg_repack.overrideAttrs (_: { + name = "pg_repack-v20181024"; + src = self.fetchzip { + url = "https://github.com/reorg/pg_repack/archive/923fa2f3c709a506e111cc963034bf2fd127aa00.tar.gz"; + sha256 = "17k6hq9xaax87yz79j773qyigm4fwk8z4zh5cyp6z0sxnwfqxxw5"; + }; + }); + }; + }; +} + + +
diff --git a/pkgs/servers/sql/postgresql/default.nix b/pkgs/servers/sql/postgresql/default.nix index 440ee15a5180..774ed62a11a3 100644 --- a/pkgs/servers/sql/postgresql/default.nix +++ b/pkgs/servers/sql/postgresql/default.nix @@ -151,6 +151,9 @@ let # below. See #22653 pathsToLink = ["/" "/bin"]; + # Note: the duplication of executables is about 4MB size. + # So a nicer solution was patching postgresql to allow setting the + # libdir explicitely. postBuild = '' mkdir -p $out/bin rm $out/bin/{pg_config,postgres,pg_ctl}