diff --git a/nixos/doc/manual/release-notes/rl-1809.xml b/nixos/doc/manual/release-notes/rl-1809.xml index 9ec465d8955eb..b8db03ca8ad11 100644 --- a/nixos/doc/manual/release-notes/rl-1809.xml +++ b/nixos/doc/manual/release-notes/rl-1809.xml @@ -18,6 +18,33 @@ + + + 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: pg_cron, postgres-hll, + postgres-topn, pg_journal, + pg_jobmon, pg_partman, + and citus. (Almost all existing extensions have seen + version updates, as well.) + + + 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. + + + PostgreSQL 10 is now the default option for new NixOS 18.09 + installations. + + Support for wrapping binaries using firejail has been diff --git a/nixos/modules/services/backup/bacula.nix b/nixos/modules/services/backup/bacula.nix index a0565ca26204b..a4a1f6532ff21 100644 --- a/nixos/modules/services/backup/bacula.nix +++ b/nixos/modules/services/backup/bacula.nix @@ -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 diff --git a/nixos/modules/services/backup/postgresql-backup.nix b/nixos/modules/services/backup/postgresql-backup.nix index 2ec78ce6f2cfa..039c079463187 100644 --- a/nixos/modules/services/backup/postgresql-backup.nix +++ b/nixos/modules/services/backup/postgresql-backup.nix @@ -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 = '' @@ -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); + }; } diff --git a/nixos/modules/services/continuous-integration/hydra/default.nix b/nixos/modules/services/continuous-integration/hydra/default.nix index c7fe4eeeab996..4fb4a54e9230f 100644 --- a/nixos/modules/services/continuous-integration/hydra/default.nix +++ b/nixos/modules/services/continuous-integration/hydra/default.nix @@ -6,6 +6,8 @@ let cfg = config.services.hydra; + pg = config.services.postgresql; + baseDir = "/var/lib/hydra"; hydraConf = pkgs.writeScript "hydra.conf" cfg.extraConfig; @@ -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 ''} diff --git a/nixos/modules/services/databases/postgresql.nix b/nixos/modules/services/databases/postgresql.nix index f59fb1c817726..2566ba7c7626f 100644 --- a/nixos/modules/services/databases/postgresql.nix +++ b/nixos/modules/services/databases/postgresql.nix @@ -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" @@ -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 { @@ -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. ''; }; @@ -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 @@ -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); 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 @@ -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; @@ -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. @@ -269,5 +355,5 @@ in }; meta.doc = ./postgresql.xml; - + meta.maintainers = with lib.maintainers; [ thoughtpolice ]; } diff --git a/nixos/modules/services/databases/postgresql.xml b/nixos/modules/services/databases/postgresql.xml index 1aaf339632454..9e021691ddaca 100644 --- a/nixos/modules/services/databases/postgresql.xml +++ b/nixos/modules/services/databases/postgresql.xml @@ -6,16 +6,60 @@ PostgreSQL - - - Source: modules/services/databases/postgresql.nix Upstream documentation: - +Maintainer: Austin Seipp + +Default version: 10.x + +PostgreSQL is an advanced, free, feature-rich relational database. NixOS +provides multiple versions of PostgreSQL, as well as a set of extensions that +provide powerful features on top of the default installation. + +
+Introduction to the PostgreSQL packaging infrastructure + +NixOS provides multiple versions of PostgreSQL, available as +sets of packages, which you use to configure the +PostgreSQL system services and specify extensions. Extensions are available +only for the correct PostgreSQL versions that they are compatible with, and +they are automatically built against the proper PostgreSQL server for +you. + +The available set of PostgreSQL packages are available under the name +pkgs.postgresqlXXPackages, where XX +contains the major version number, without any bugfix releases. For example, +the following are all available: + + +pkgs.postgresql93Packages +pkgs.postgresql94Packages +pkgs.postgresql95Packages +pkgs.postgresql96Packages +pkgs.postgresql10Packages + +# points to default version specified by Nixpkgs +pkgs.postgresqlPackages + + + +These names are each attribute sets containing A) the +.postgresql attribute, pointing to the derivation for the +PostgreSQL server, and an assorted set of other attributes which specify +extensions that can be installed into the server. Because extensions are tied +to the version of PostgreSQL they're built against, they must all be bundled +together. For example, the following attributes yield the derivations for +PostgreSQL 9.6, and the PostGIS extension built against PostgreSQL 9.6: + + +pkgs.postgresql96Packages.postgres +pkgs.postgresql96Packages.postgis + + -PostgreSQL is an advanced, free relational database. +
Configuring @@ -27,25 +71,23 @@ = pkgs.postgresql94; -Note that you are required to specify the desired version of -PostgreSQL (e.g. pkgs.postgresql94). 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 -release of PostgreSQL. +Note that you are required to specify the desired version of PostgreSQL (e.g. +pkgs.postgresql96Packages). 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 release of PostgreSQL. - +postgres=> + + By default, PostgreSQL stores its databases in /var/db/postgresql. You can override this using @@ -59,19 +101,123 @@ alice=>
+
Enabling and installing extensions -
Upgrading +In order to install extensions, use the + option. This option should contain +a function which takes an attribute set, and from that attribute set, returns a +list of the extensions the user wishes to enable. This extension set is the +same one specified by . + +For example, to enable the PostGIS and TimescaleDB extension, you can +say: -FIXME: document dump/upgrade/load cycle. + +services.postgresql.plugins = p: with p; + [ postgis + timescaledb + ]; + + + +This example imports the set of PostgreSQL attributes into scope and +selects the postgis and timescaledb +attributes. Note that not all of these attributes are available for every +version of PostgreSQL, e.g. TimescaleDB does not work with PostgreSQL 9.5. +Should you specify v9.5 (using ), +the above example would fail with an evaluation error. + +Once this has been done and nixos-rebuild has been +run, you may run CREATE EXTENSION> in order to +install the extension for the given database you've selected: + + +postgres=> CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE; + + +Any functions, types, etc that are provided by the extension should +now be available.
+
Upgrading + +This section will be brief. Be sure to read the +official +PostgreSQL Upgrading documentation for more detailed information +about the steps below. This section will use the pg_dumpall +method. + +First, you must dump all data from the server using +pg_dumpall, but this must be executed by the +new version of the PostgreSQL tools. This can be done +easily using the existing Postgres infrastructure, by using nix-shell +in order to install the tools: + + +a@link> nix-shell -p 'postgresql10Packages.withPackages (_: [])' +[nix-shell:~]$ sudo -u postgres pg_dumpall > dumpfile + + + +At this point, the file dumpfile contains a dump of +the entire server, and can be backed up or transported elsewhere. Also note +that the above command is analagous to the NixOS module configuration: you +can enter a shell with extensions available, by selecting them from the +attribute set provided to the lambda. The above example uses no extensions. + + +Next, stop the PostgreSQL service using systemctl stop: + + +[nix-shell:~]$ sudo systemctl stop postgres + + + +At this point, you may move the data directory out of the way, so that +the database will be re-initialized in a clean manner once the new +server version is installed. By default, the NixOS module for +PostgreSQL installs each database by default into its own directory +under /var/lib/postgresql with a unique name based +on the version number, so installing a new version will not overwrite +data from the old one. However, you may wish to do this anyway at this +point, and you must do it if you changed the data +directory yourself: + + +[nix-shell:~]$ sudo mv /var/lib/postgresql/* ... + + + +Finally, upgrade your configuration.nix to point the + option to point to the new +version of PostgreSQL; for example, postgresql10Packages. +Then start the new service using nixos-rebuild switch. Note +that you do not need to keep a backup or resupply copies of any configuration +files, since they're managed by Nix. However, you might want to make some tweaks +for the new version of the server, as well. + +At this point, you can simply use psql in order to load +the old data into the new server, including roles, databases, etc: + + +[nix-shell:~]$ sudo -u postgres psql -d postgres -f dumpfile + + + +
Options - A complete list of options for the PostgreSQL module may be found here. +A complete list of options for the PostgreSQL module may be found here.
+
Authoring new extensions + +FIXME: document how to write an extension + +
diff --git a/nixos/modules/services/misc/gammu-smsd.nix b/nixos/modules/services/misc/gammu-smsd.nix index 3057d7fd1a095..72c3ba43be363 100644 --- a/nixos/modules/services/misc/gammu-smsd.nix +++ b/nixos/modules/services/misc/gammu-smsd.nix @@ -232,7 +232,7 @@ in { '' + (let execPsql = extraArgs: concatStringsSep " " [ (optionalString (sql.password != null) "PGPASSWORD=${sql.password}") - "${config.services.postgresql.package}/bin/psql" + "${config.services.postgresql.postgresqlPackage}/bin/psql" (optionalString (sql.host != null) "-h ${sql.host}") (optionalString (sql.user != null) "-U ${sql.user}") "$extraArgs" diff --git a/nixos/modules/services/misc/gitea.nix b/nixos/modules/services/misc/gitea.nix index a222325579fec..61981cde64cf5 100644 --- a/nixos/modules/services/misc/gitea.nix +++ b/nixos/modules/services/misc/gitea.nix @@ -5,7 +5,9 @@ with lib; let cfg = config.services.gitea; gitea = cfg.package; + pg = config.services.postgresql; + usePostgresql = cfg.database.type == "postgres"; configFile = pkgs.writeText "app.ini" '' APP_NAME = ${cfg.appName} @@ -308,9 +310,9 @@ in echo "CREATE ROLE ${cfg.database.user} WITH ENCRYPTED PASSWORD '$(head -n1 ${cfg.database.passwordFile})' NOCREATEDB NOCREATEROLE LOGIN" | - ${pkgs.sudo}/bin/sudo -u ${pg.superUser} ${pg.package}/bin/psql + ${pkgs.sudo}/bin/sudo -u ${pg.superUser} ${pg.postgresqlPackage}/bin/psql ${pkgs.sudo}/bin/sudo -u ${pg.superUser} \ - ${pg.package}/bin/createdb \ + ${pg.postgresqlPackage}/bin/createdb \ --owner=${cfg.database.user} \ --encoding=UTF8 \ --lc-collate=C \ diff --git a/nixos/modules/services/misc/gitlab.nix b/nixos/modules/services/misc/gitlab.nix index 5bf66354f487e..b4bbd22822f46 100644 --- a/nixos/modules/services/misc/gitlab.nix +++ b/nixos/modules/services/misc/gitlab.nix @@ -12,7 +12,7 @@ let gitlabSocket = "${cfg.statePath}/tmp/sockets/gitlab.socket"; gitalySocket = "${cfg.statePath}/tmp/sockets/gitaly.socket"; pathUrlQuote = url: replaceStrings ["/"] ["%2F"] url; - pgSuperUser = config.services.postgresql.superUser; + pg = config.services.postgresql; databaseYml = '' production: @@ -162,7 +162,7 @@ let makeWrapper ${cfg.packages.gitlab.rubyEnv}/bin/rake $out/bin/gitlab-rake \ ${concatStrings (mapAttrsToList (name: value: "--set ${name} '${value}' ") gitlabEnv)} \ --set GITLAB_CONFIG_PATH '${cfg.statePath}/config' \ - --set PATH '${lib.makeBinPath [ pkgs.nodejs pkgs.gzip pkgs.git pkgs.gnutar config.services.postgresql.package ]}:$PATH' \ + --set PATH '${lib.makeBinPath [ pkgs.nodejs pkgs.gzip pkgs.git pkgs.gnutar pg.postgresqlPackage ]}:$PATH' \ --set RAKEOPT '-f ${cfg.packages.gitlab}/share/gitlab/Rakefile' \ --run 'cd ${cfg.packages.gitlab}/share/gitlab' ''; @@ -465,7 +465,7 @@ in { partOf = [ "gitlab.service" ]; environment = gitlabEnv; path = with pkgs; [ - config.services.postgresql.package + pg.postgresqlPackage gitAndTools.git ruby openssh @@ -541,7 +541,7 @@ in { wantedBy = [ "multi-user.target" ]; environment = gitlabEnv; path = with pkgs; [ - config.services.postgresql.package + pg.postgresqlPackage gitAndTools.git openssh nodejs @@ -608,13 +608,13 @@ in { if [ "${cfg.databaseHost}" = "127.0.0.1" ]; then if ! test -e "${cfg.statePath}/db-created"; then - ${pkgs.sudo}/bin/sudo -u ${pgSuperUser} psql postgres -c "CREATE ROLE ${cfg.databaseUsername} WITH LOGIN NOCREATEDB NOCREATEROLE ENCRYPTED PASSWORD '${cfg.databasePassword}'" - ${pkgs.sudo}/bin/sudo -u ${pgSuperUser} ${config.services.postgresql.package}/bin/createdb --owner ${cfg.databaseUsername} ${cfg.databaseName} + ${pkgs.sudo}/bin/sudo -u ${pg.superUser} psql postgres -c "CREATE ROLE ${cfg.databaseUsername} WITH LOGIN NOCREATEDB NOCREATEROLE ENCRYPTED PASSWORD '${cfg.databasePassword}'" + ${pkgs.sudo}/bin/sudo -u ${pg.superUser} createdb --owner ${cfg.databaseUsername} ${cfg.databaseName} touch "${cfg.statePath}/db-created" fi # enable required pg_trgm extension for gitlab - ${pkgs.sudo}/bin/sudo -u ${pgSuperUser} psql ${cfg.databaseName} -c "CREATE EXTENSION IF NOT EXISTS pg_trgm" + ${pkgs.sudo}/bin/sudo -u ${pg.superUser} psql ${cfg.databaseName} -c "CREATE EXTENSION IF NOT EXISTS pg_trgm" fi # Always do the db migrations just to be sure the database is up-to-date diff --git a/nixos/modules/services/misc/matrix-synapse.nix b/nixos/modules/services/misc/matrix-synapse.nix index 18e13f6ac0300..373814e113772 100644 --- a/nixos/modules/services/misc/matrix-synapse.nix +++ b/nixos/modules/services/misc/matrix-synapse.nix @@ -5,6 +5,7 @@ with lib; let cfg = config.services.matrix-synapse; pg = config.services.postgresql; + usePostgresql = cfg.database_type == "psycopg2"; logConfigFile = pkgs.writeText "log_config.yaml" cfg.logConfig; mkResource = r: ''{names: ${builtins.toJSON r.names}, compress: ${boolToString r.compress}}''; @@ -663,14 +664,14 @@ in { '' + optionalString (usePostgresql && cfg.create_local_database) '' if ! test -e "${cfg.dataDir}/db-created"; then ${pkgs.sudo}/bin/sudo -u ${pg.superUser} \ - ${pg.package}/bin/createuser \ + ${pg.postgresqlPackage}/bin/createuser \ --login \ --no-createdb \ --no-createrole \ --encrypted \ ${cfg.database_user} ${pkgs.sudo}/bin/sudo -u ${pg.superUser} \ - ${pg.package}/bin/createdb \ + ${pg.postgresqlPackage}/bin/createdb \ --owner=${cfg.database_user} \ --encoding=UTF8 \ --lc-collate=C \ diff --git a/nixos/modules/services/monitoring/zabbix-server.nix b/nixos/modules/services/monitoring/zabbix-server.nix index 5f9fc12832fc0..bd27e35d3c6be 100644 --- a/nixos/modules/services/monitoring/zabbix-server.nix +++ b/nixos/modules/services/monitoring/zabbix-server.nix @@ -7,6 +7,8 @@ let cfg = config.services.zabbixServer; + pg = config.services.postgresql; + stateDir = "/var/run/zabbix"; logDir = "/var/log/zabbix"; @@ -103,11 +105,11 @@ in chown zabbix ${stateDir} ${logDir} ${libDir} if ! test -e "${libDir}/db-created"; then - ${pkgs.su}/bin/su -s "$SHELL" ${config.services.postgresql.superUser} -c '${pkgs.postgresql}/bin/createuser --no-superuser --no-createdb --no-createrole zabbix' || true - ${pkgs.su}/bin/su -s "$SHELL" ${config.services.postgresql.superUser} -c '${pkgs.postgresql}/bin/createdb --owner zabbix zabbix' || true - cat ${pkgs.zabbix.server}/share/zabbix/db/schema/postgresql.sql | ${pkgs.su}/bin/su -s "$SHELL" zabbix -c '${pkgs.postgresql}/bin/psql zabbix' - cat ${pkgs.zabbix.server}/share/zabbix/db/data/images_pgsql.sql | ${pkgs.su}/bin/su -s "$SHELL" zabbix -c '${pkgs.postgresql}/bin/psql zabbix' - cat ${pkgs.zabbix.server}/share/zabbix/db/data/data.sql | ${pkgs.su}/bin/su -s "$SHELL" zabbix -c '${pkgs.postgresql}/bin/psql zabbix' + ${pkgs.su}/bin/su -s "$SHELL" ${pg.superUser} -c '${pg.postgresqlPackage}/bin/createuser --no-superuser --no-createdb --no-createrole zabbix' || true + ${pkgs.su}/bin/su -s "$SHELL" ${pg.superUser} -c '${pg.postgresqlPackage}/bin/createdb --owner zabbix zabbix' || true + cat ${pkgs.zabbix.server}/share/zabbix/db/schema/postgresql.sql | ${pkgs.su}/bin/su -s "$SHELL" zabbix -c '${pg.postgresqlPackage}/bin/psql zabbix' + cat ${pkgs.zabbix.server}/share/zabbix/db/data/images_pgsql.sql | ${pkgs.su}/bin/su -s "$SHELL" zabbix -c '${pg.postgresqlPackage}/bin/psql zabbix' + cat ${pkgs.zabbix.server}/share/zabbix/db/data/data.sql | ${pkgs.su}/bin/su -s "$SHELL" zabbix -c '${pg.postgresqlPackage}/bin/psql zabbix' touch "${libDir}/db-created" fi ''; diff --git a/nixos/modules/services/web-apps/mattermost.nix b/nixos/modules/services/web-apps/mattermost.nix index 8c7fc4056adc9..50a0dac7e7119 100644 --- a/nixos/modules/services/web-apps/mattermost.nix +++ b/nixos/modules/services/web-apps/mattermost.nix @@ -6,6 +6,8 @@ let cfg = config.services.mattermost; + pg = config.services.postgresql; + defaultConfig = builtins.fromJSON (readFile "${pkgs.mattermost}/config/config.json"); mattermostConf = foldl recursiveUpdate defaultConfig @@ -184,11 +186,11 @@ in fi '' + lib.optionalString cfg.localDatabaseCreate '' if ! test -e "${cfg.statePath}/.db-created"; then - ${pkgs.sudo}/bin/sudo -u ${config.services.postgresql.superUser} \ - ${config.services.postgresql.package}/bin/psql postgres -c \ + ${pkgs.sudo}/bin/sudo -u ${pg.superUser} \ + ${pg.postgresqlPackage}/bin/psql postgres -c \ "CREATE ROLE ${cfg.localDatabaseUser} WITH LOGIN NOCREATEDB NOCREATEROLE ENCRYPTED PASSWORD '${cfg.localDatabasePassword}'" - ${pkgs.sudo}/bin/sudo -u ${config.services.postgresql.superUser} \ - ${config.services.postgresql.package}/bin/createdb \ + ${pkgs.sudo}/bin/sudo -u ${pg.superUser} \ + ${pg.postgresqlPackage}/bin/createdb \ --owner ${cfg.localDatabaseUser} ${cfg.localDatabaseName} touch ${cfg.statePath}/.db-created fi @@ -227,4 +229,3 @@ in }) ]; } - diff --git a/nixos/modules/services/web-apps/restya-board.nix b/nixos/modules/services/web-apps/restya-board.nix index bc6689bdb2712..4c493253ba6c3 100644 --- a/nixos/modules/services/web-apps/restya-board.nix +++ b/nixos/modules/services/web-apps/restya-board.nix @@ -10,6 +10,8 @@ with lib; let cfg = config.services.restya-board; + pg = config.services.postgresql; + runDir = "/run/restya-board"; poolName = "restya-board"; @@ -312,16 +314,16 @@ in ${optionalString (isNull cfg.database.host) '' if ! [ -e "${cfg.dataDir}/.db-initialized" ]; then - ${pkgs.sudo}/bin/sudo -u ${config.services.postgresql.superUser} \ - ${config.services.postgresql.package}/bin/psql -U ${config.services.postgresql.superUser} \ + ${pkgs.sudo}/bin/sudo -u ${pg.superUser} \ + ${pg.postgresqlPackage}/bin/psql -U ${pg.superUser} \ -c "CREATE USER ${cfg.database.user} WITH ENCRYPTED PASSWORD 'restya'" - ${pkgs.sudo}/bin/sudo -u ${config.services.postgresql.superUser} \ - ${config.services.postgresql.package}/bin/psql -U ${config.services.postgresql.superUser} \ + ${pkgs.sudo}/bin/sudo -u ${pg.superUser} \ + ${pg.postgresqlPackage}/bin/psql -U ${pg.superUser} \ -c "CREATE DATABASE ${cfg.database.name} OWNER ${cfg.database.user} ENCODING 'UTF8' TEMPLATE template0" ${pkgs.sudo}/bin/sudo -u ${cfg.user} \ - ${config.services.postgresql.package}/bin/psql -U ${cfg.database.user} \ + ${pg.postgresqlPackage}/bin/psql -U ${cfg.database.user} \ -d ${cfg.database.name} -f "${runDir}/sql/restyaboard_with_empty_data.sql" touch "${cfg.dataDir}/.db-initialized" @@ -381,4 +383,3 @@ in }; } - diff --git a/nixos/modules/services/web-apps/tt-rss.nix b/nixos/modules/services/web-apps/tt-rss.nix index 2b171aa1b2b29..f37dc9af26db1 100644 --- a/nixos/modules/services/web-apps/tt-rss.nix +++ b/nixos/modules/services/web-apps/tt-rss.nix @@ -4,6 +4,8 @@ with lib; let cfg = config.services.tt-rss; + pg = config.services.postgresql; + configVersion = 26; cacheDir = "cache"; @@ -528,7 +530,7 @@ let callSql = e: if cfg.database.type == "pgsql" then '' ${optionalString (cfg.database.password != null) "PGPASSWORD=${cfg.database.password}"} \ - ${pkgs.sudo}/bin/sudo -u ${cfg.user} ${config.services.postgresql.package}/bin/psql \ + ${pkgs.sudo}/bin/sudo -u ${cfg.user} ${pg.postgresqlPackage}/bin/psql \ -U ${cfg.database.user} \ ${optionalString (cfg.database.host != null) "-h ${cfg.database.host} --port ${toString dbPort}"} \ -c '${e}' \ @@ -565,8 +567,8 @@ let + (optionalString (cfg.database.type == "pgsql") '' ${optionalString (cfg.database.host == null && cfg.database.password == null) '' if ! [ -e ${cfg.root}/.db-created ]; then - ${pkgs.sudo}/bin/sudo -u ${config.services.postgresql.superUser} ${config.services.postgresql.package}/bin/createuser ${cfg.database.user} - ${pkgs.sudo}/bin/sudo -u ${config.services.postgresql.superUser} ${config.services.postgresql.package}/bin/createdb -O ${cfg.database.user} ${cfg.database.name} + ${pkgs.sudo}/bin/sudo -u ${pg.superUser} ${pg.postgresqlPackage}/bin/createuser ${cfg.database.user} + ${pkgs.sudo}/bin/sudo -u ${pg.superUser} ${pg.postgresqlPackage}/bin/createdb -O ${cfg.database.user} ${cfg.database.name} touch ${cfg.root}/.db-created fi ''} diff --git a/nixos/modules/services/web-servers/apache-httpd/owncloud.nix b/nixos/modules/services/web-servers/apache-httpd/owncloud.nix index 6345a9a569355..b81a084892e12 100644 --- a/nixos/modules/services/web-servers/apache-httpd/owncloud.nix +++ b/nixos/modules/services/web-servers/apache-httpd/owncloud.nix @@ -332,7 +332,7 @@ let 'logtimezone' => '${tz}', ''; - postgresql = serverInfo.fullConfig.services.postgresql.package; + postgresql = serverInfo.fullConfig.services.postgresql.postgresqlPackage; setupDb = pkgs.writeScript "setup-owncloud-db" '' #!${pkgs.runtimeShell} diff --git a/nixos/modules/services/web-servers/hydron.nix b/nixos/modules/services/web-servers/hydron.nix index ed63230bc7842..c1c3a41a2eea0 100644 --- a/nixos/modules/services/web-servers/hydron.nix +++ b/nixos/modules/services/web-servers/hydron.nix @@ -2,7 +2,7 @@ let cfg = config.services.hydron; - postgres = config.services.postgresql; + pg = config.services.postgresql; in with lib; { options.services.hydron = { enable = mkEnableOption "hydron"; @@ -105,11 +105,11 @@ in with lib; { chown -R hydron:hydron ${escapeShellArg cfg.dataDir} # Ensure the database is correct or create it - ${pkgs.sudo}/bin/sudo -u ${postgres.superUser} ${postgres.package}/bin/createuser \ + ${pkgs.sudo}/bin/sudo -u ${pg.superUser} ${pg.postgresqlPackage}/bin/createuser \ -SDR hydron || true - ${pkgs.sudo}/bin/sudo -u ${postgres.superUser} ${postgres.package}/bin/createdb \ + ${pkgs.sudo}/bin/sudo -u ${pg.superUser} ${pg.postgresqlPackage}/bin/createdb \ -T template0 -E UTF8 -O hydron hydron || true - ${pkgs.sudo}/bin/sudo -u hydron ${postgres.package}/bin/psql \ + ${pkgs.sudo}/bin/sudo -u hydron ${pg.postgresqlPackage}/bin/psql \ -c "ALTER ROLE hydron WITH PASSWORD '$(cat ${escapeShellArg cfg.passwordFile})';" || true ''; @@ -139,7 +139,7 @@ in with lib; { description = "Automatically import paths into hydron and possibly fetch tags"; after = [ "network.target" "hydron.service" ]; wantedBy = [ "timers.target" ]; - + timerConfig = { Persistent = true; OnCalendar = cfg.interval; @@ -148,7 +148,7 @@ in with lib; { users = { groups.hydron.gid = config.ids.gids.hydron; - + users.hydron = { description = "hydron server service user"; home = cfg.dataDir; diff --git a/nixos/modules/services/web-servers/meguca.nix b/nixos/modules/services/web-servers/meguca.nix index 11aebcb91d88a..6db66edf66a9a 100644 --- a/nixos/modules/services/web-servers/meguca.nix +++ b/nixos/modules/services/web-servers/meguca.nix @@ -2,7 +2,7 @@ let cfg = config.services.meguca; - postgres = config.services.postgresql; + pg = config.services.postgresql; in with lib; { options.services.meguca = { enable = mkEnableOption "meguca"; @@ -108,11 +108,11 @@ in with lib; { chown -R meguca:meguca ${escapeShellArg cfg.dataDir} # Ensure the database is correct or create it - ${pkgs.sudo}/bin/sudo -u ${postgres.superUser} ${postgres.package}/bin/createuser \ + ${pkgs.sudo}/bin/sudo -u ${pg.superUser} ${pg.postgresqlPackage}/bin/createuser \ -SDR meguca || true - ${pkgs.sudo}/bin/sudo -u ${postgres.superUser} ${postgres.package}/bin/createdb \ + ${pkgs.sudo}/bin/sudo -u ${pg.superUser} ${pg.postgresqlPackage}/bin/createdb \ -T template0 -E UTF8 -O meguca meguca || true - ${pkgs.sudo}/bin/sudo -u meguca ${postgres.package}/bin/psql \ + ${pkgs.sudo}/bin/sudo -u meguca ${pg.postgresqlPackage}/bin/psql \ -c "ALTER ROLE meguca WITH PASSWORD '$(cat ${escapeShellArg cfg.passwordFile})';" || true ''; diff --git a/nixos/modules/virtualisation/containers.nix b/nixos/modules/virtualisation/containers.nix index b91165ce3b827..fd04951d918c4 100644 --- a/nixos/modules/virtualisation/containers.nix +++ b/nixos/modules/virtualisation/containers.nix @@ -605,8 +605,6 @@ in { config = { config, pkgs, ... }: { services.postgresql.enable = true; - services.postgresql.package = pkgs.postgresql96; - system.stateVersion = "17.03"; }; }; diff --git a/nixos/tests/pgjwt.nix b/nixos/tests/pgjwt.nix index a2d81288c8122..9f4cce806b422 100644 --- a/nixos/tests/pgjwt.nix +++ b/nixos/tests/pgjwt.nix @@ -1,37 +1,30 @@ import ./make-test.nix ({ pkgs, lib, ...}: + let - test = with pkgs; runCommand "patch-test" { - nativeBuildInputs = [ pgjwt ]; - } - '' + pgjwt = pkgs.postgresqlPackages.pgjwt; + pg_prove = "${pkgs.perlPackages.TAPParserSourceHandlerpgTAP}/bin/pg_prove"; + + test = pkgs.runCommand "test.sql" {} '' sed -e '12 i CREATE EXTENSION pgcrypto;\nCREATE EXTENSION pgtap;\nSET search_path TO tap,public;' ${pgjwt.src}/test.sql > $out; ''; in -with pkgs; { +{ name = "pgjwt"; - meta = with lib.maintainers; { - maintainers = [ spinus willibutz ]; - }; + meta.maintainers = with lib.maintainers; [ thoughtpolice spinus willibutz ]; nodes = { - master = { ... }: - { + master = { ... }: { services.postgresql = { enable = true; - extraPlugins = [ pgjwt pgtap ]; + plugins = p: with p; [ pgjwt pgtap ]; }; }; }; - testScript = { nodes, ... }: - let - sqlSU = "${nodes.master.config.services.postgresql.superUser}"; - pgProve = "${pkgs.perlPackages.TAPParserSourceHandlerpgTAP}"; - in - '' + testScript = { nodes, ... }: '' startAll; $master->waitForUnit("postgresql"); $master->copyFileFromHost("${test}","/tmp/test.sql"); - $master->succeed("${pkgs.sudo}/bin/sudo -u ${sqlSU} PGOPTIONS=--search_path=tap,public ${pgProve}/bin/pg_prove -d postgres -v -f /tmp/test.sql"); + $master->succeed("${pkgs.sudo}/bin/sudo -u postgres PGOPTIONS=--search_path=tap,public ${pg_prove} -v -d postgres -f /tmp/test.sql"); ''; }) diff --git a/nixos/tests/postgis.nix b/nixos/tests/postgis.nix index f8b63c5b6a27b..79dfcaf427ea1 100644 --- a/nixos/tests/postgis.nix +++ b/nixos/tests/postgis.nix @@ -1,7 +1,7 @@ import ./make-test.nix ({ pkgs, ...} : { name = "postgis"; meta = with pkgs.stdenv.lib.maintainers; { - maintainers = [ lsix ]; + maintainers = [ thoughtpolice lsix ]; }; nodes = { @@ -9,10 +9,9 @@ import ./make-test.nix ({ pkgs, ...} : { { pkgs, ... }: { - services.postgresql = let mypg = pkgs.postgresql100; in { - enable = true; - package = mypg; - extraPlugins = [ (pkgs.postgis.override { postgresql = mypg; }) ]; + services.postgresql = { + enable = true; + plugins = p: with p; [ postgis ]; }; }; }; diff --git a/nixos/tests/postgresql.nix b/nixos/tests/postgresql.nix index f1f09277f342a..46dcf75cd3619 100644 --- a/nixos/tests/postgresql.nix +++ b/nixos/tests/postgresql.nix @@ -1,9 +1,24 @@ -{ system ? builtins.currentSystem }: +{ system ? builtins.currentSystem +}: + with import ../lib/testing.nix { inherit system; }; with pkgs.lib; + let - postgresql-versions = pkgs.callPackages ../../pkgs/servers/sql/postgresql { }; - test-sql = pkgs.writeText "postgresql-test" '' + + # An attrset containing every version of PostgreSQL, shipped by Nixpkgs. The + # tests are run once for each version. + postgresql-versions = + # This is an existing attrset containing every supported version... + let allPackages = (pkgs.callPackage ../../pkgs/servers/sql/postgresql/packages.nix { }).allPostgresqlPackages; + # ... now swizzle the names of the attrset in order to be more user-friendly. This is a bit of a hack; + # ideally we would use postgresql.version, but that normally results in something like 'postgresql-10.4' + # which is an attribute name that can't be evaluated easily by 'nix-build' + in mapAttrs' (name: value: { name = "${builtins.substring 0 12 name}"; inherit value; }) allPackages; + + # Sample SQL script to use. Note: this should work on _every_ available, supported + # version of PostgreSQL shipped by Nixpkgs. + test-sql = pkgs.writeText "test.sql" '' CREATE EXTENSION pgcrypto; -- just to check if lib loading works CREATE TABLE sth ( id int @@ -16,16 +31,19 @@ let CREATE TABLE xmltest ( doc xml ); INSERT INTO xmltest (doc) VALUES ('ok'); -- check if libxml2 enabled ''; - make-postgresql-test = postgresql-name: postgresql-package: makeTest { - name = postgresql-name; + + # Actual test + make-test = name: packages: makeTest { + inherit name; + meta = with pkgs.stdenv.lib.maintainers; { - maintainers = [ zagy ]; + maintainers = [ thoughtpolice zagy ]; }; machine = {...}: { - services.postgresql.package=postgresql-package; services.postgresql.enable = true; + services.postgresql.packages = packages; services.postgresqlBackup.enable = true; services.postgresqlBackup.databases = [ "postgres" ]; @@ -38,11 +56,14 @@ let } $machine->start; - $machine->waitForUnit("postgresql"); + # postgresql should be available just after unit start + $machine->waitForUnit("postgresql"); $machine->succeed("cat ${test-sql} | sudo -u postgres psql"); $machine->shutdown; # make sure that postgresql survive restart (bug #1735) sleep(2); + + # run some basic queries against the schema $machine->start; $machine->waitForUnit("postgresql"); $machine->fail(check_count("SELECT * FROM sth;", 3)); @@ -55,7 +76,7 @@ let $machine->succeed("zcat /var/backup/postgresql/postgres.sql.gz | grep 'ok'"); $machine->shutdown; ''; - }; -in - mapAttrs' (p-name: p-package: {name=p-name; value=make-postgresql-test p-name p-package;}) postgresql-versions + + results = mapAttrs' (name: pkg: { inherit name; value = make-test name pkg; }) postgresql-versions; +in results diff --git a/nixos/tests/trac.nix b/nixos/tests/trac.nix index 4599885acde69..fc440c96d3b23 100644 --- a/nixos/tests/trac.nix +++ b/nixos/tests/trac.nix @@ -17,7 +17,6 @@ import ./make-test.nix ({ pkgs, ... }: { postgresql = { pkgs, ... }: { services.postgresql.enable = true; - services.postgresql.package = pkgs.postgresql; services.postgresql.enableTCPIP = true; services.postgresql.authentication = '' # Generated file; do not edit! diff --git a/pkgs/servers/sql/postgresql/jdbc/default.nix b/pkgs/development/java-modules/postgresql_jdbc/default.nix similarity index 100% rename from pkgs/servers/sql/postgresql/jdbc/default.nix rename to pkgs/development/java-modules/postgresql_jdbc/default.nix diff --git a/pkgs/servers/sql/postgresql/psqlodbc/default.nix b/pkgs/development/libraries/psqlodbc/default.nix similarity index 100% rename from pkgs/servers/sql/postgresql/psqlodbc/default.nix rename to pkgs/development/libraries/psqlodbc/default.nix diff --git a/pkgs/development/tools/database/timescaledb-parallel-copy/default.nix b/pkgs/development/tools/database/timescaledb-parallel-copy/default.nix new file mode 100644 index 0000000000000..d667e49e7cbeb --- /dev/null +++ b/pkgs/development/tools/database/timescaledb-parallel-copy/default.nix @@ -0,0 +1,26 @@ +{ stdenv, buildGoPackage, fetchFromGitHub }: + +buildGoPackage rec { + name = "timescaledb-parallel-copy-${version}"; + version = "2018-05-14"; + + owner = "timescale"; + repo = "timescaledb-parallel-copy"; + + goPackagePath = with src; "github.com/${owner}/${repo}"; + goDeps = ./deps.nix; + + src = fetchFromGitHub { + inherit owner repo; + rev = "20d3e8f8219329f2f4b0a5aa985f280dd04d10bb"; + sha256 = "0waaccw991cnxaxjdxh9ksb94kiiyx1r7gif6pkd5k58js0kfvdn"; + }; + + meta = with stdenv.lib; { + description = "Bulk, parallel insert of CSV records into PostgreSQL"; + homepage = http://github.com/timescale/timescaledb-parallel-copy; + license = licenses.asl20; + platforms = platforms.linux; + maintainers = with maintainers; [ thoughtpolice ]; + }; +} diff --git a/pkgs/development/tools/database/timescaledb-parallel-copy/deps.nix b/pkgs/development/tools/database/timescaledb-parallel-copy/deps.nix new file mode 100644 index 0000000000000..c672611e09c10 --- /dev/null +++ b/pkgs/development/tools/database/timescaledb-parallel-copy/deps.nix @@ -0,0 +1,21 @@ +# This file was generated by https://github.com/kamilchm/go2nix v1.2.1 +[ + { + goPackagePath = "github.com/jmoiron/sqlx"; + fetch = { + type = "git"; + url = "https://github.com/jmoiron/sqlx"; + rev = "0dae4fefe7c0e190f7b5a78dac28a1c82cc8d849"; + sha256 = "0r8fyj70n0v84byvagw8w8rzz532s94mjr72b9sx018j0b6xglmy"; + }; + } + { + goPackagePath = "github.com/lib/pq"; + fetch = { + type = "git"; + url = "https://github.com/lib/pq"; + rev = "90697d60dd844d5ef6ff15135d0203f65d2f53b8"; + sha256 = "0hb4bfsk8g5473yzbf3lzrb373xicakjznkf0v085xgimz991i9r"; + }; + } +] diff --git a/pkgs/servers/sql/postgresql/default.nix b/pkgs/servers/sql/postgresql/default.nix index bccd54ca4ba89..09876fd21e5ef 100644 --- a/pkgs/servers/sql/postgresql/default.nix +++ b/pkgs/servers/sql/postgresql/default.nix @@ -1,10 +1,28 @@ -{ lib, stdenv, glibc, fetchurl, zlib, readline, libossp_uuid, openssl, libxml2, makeWrapper, tzdata }: +{ stdenv, lib, fetchurl, makeWrapper +, glibc, zlib, readline, libossp_uuid, openssl, libxml2, tzdata, systemd + +# For now, keep JIT support behind a conditional flag, even though it is on by +# default -- so we can turn all features (and impacts to closure size, +# dependencies, etc) off easily, if we need to. +, llvmPackages, enableJitSupport ? true +}@deps: let common = { version, sha256, psqlSchema }: - let atLeast = lib.versionAtLeast version; in stdenv.mkDerivation (rec { + let + atLeast = lib.versionAtLeast version; + + # JIT is only supported on Linux, for now. (Darwin may build, but must be + # tested). + jitEnabled = atLeast "11" && enableJitSupport && deps.stdenv.isLinux; + + # Note: use deps.stdenv, not just 'stdenv', otherwise infinite recursion + # will occur due to lexical scoping rules. + stdenv = if jitEnabled then llvmPackages.stdenv else deps.stdenv; + in stdenv.mkDerivation (rec { name = "postgresql-${version}"; + inherit version; src = fetchurl { url = "mirror://postgresql/source/v${version}/${name}.tar.bz2"; @@ -16,7 +34,9 @@ let buildInputs = [ zlib readline openssl libxml2 makeWrapper ] - ++ lib.optionals (!stdenv.isDarwin) [ libossp_uuid ]; + ++ lib.optionals (!stdenv.isDarwin) [ libossp_uuid ] + ++ lib.optionals (atLeast "9.6" && !stdenv.isDarwin) [ systemd ] + ++ lib.optionals jitEnabled (with llvmPackages; [ clang llvm ]); enableParallelBuilding = true; @@ -33,14 +53,16 @@ let "--sysconfdir=/etc" "--libdir=$(lib)/lib" "--with-system-tzdata=${tzdata}/share/zoneinfo" + (lib.optionalString (atLeast "9.6" && !stdenv.isDarwin) "--with-systemd") (if stdenv.isDarwin then "--with-uuid=e2fs" else "--with-ossp-uuid") + (lib.optionalString jitEnabled "--with-llvm") ]; patches = - [ (if atLeast "9.4" then ./disable-resolve_symlinks-94.patch else ./disable-resolve_symlinks.patch) - (if atLeast "9.6" then ./less-is-more-96.patch else ./less-is-more.patch) - (if atLeast "9.6" then ./hardcode-pgxs-path-96.patch else ./hardcode-pgxs-path.patch) - ./specify_pkglibdir_at_runtime.patch + [ (if atLeast "9.4" then ./patches/disable-resolve_symlinks-94.patch else ./patches/disable-resolve_symlinks.patch) + (if atLeast "9.6" then ./patches/less-is-more-96.patch else ./patches/less-is-more.patch) + (if atLeast "9.6" then ./patches/hardcode-pgxs-path-96.patch else ./patches/hardcode-pgxs-path.patch) + ./patches/specify_pkglibdir_at_runtime.patch ]; installTargets = [ "install-world" ]; @@ -60,9 +82,6 @@ let moveToOutput "lib/*.a" "$out" moveToOutput "lib/libecpg*" "$out" - # Prevent a retained dependency on gcc-wrapper. - substituteInPlace "$out/lib/pgxs/src/Makefile.global" --replace ${stdenv.cc}/bin/ld ld - if [ -z "''${dontDisableStatic:-}" ]; then # Remove static libraries in case dynamic are available. for i in $out/lib/*.a; do @@ -72,6 +91,22 @@ let fi done fi + + # Fix the PGXS installation paths, since they can't write into the Nix store + patch -d "$out/lib/pgxs/src" < ${./patches/pgxs-nix.patch} + substituteInPlace "$out/lib/pgxs/src/Makefile.global" \ + --subst-var-by NIX_POSTGRES_INCLUDE "$out/include" + + # Prevent a retained dependency on gcc-wrapper. + substituteInPlace "$out/lib/pgxs/src/Makefile.global" --replace ${stdenv.cc}/bin/ld ld + '' + lib.optionalString jitEnabled '' + # In the case of JIT support, prevent a retained dependency on clang-wrapper, too + substituteInPlace "$out/lib/pgxs/src/Makefile.global" --replace ${stdenv.cc}/bin/clang clang + + # Move the bitcode and libllvmjit.so library out of $lib; otherwise, every client that + # depends on libpq.so will also have libLLVM.so in its closure too, bloating it + moveToOutput "lib/bitcode" "$out" + moveToOutput "lib/llvmjit*" "$out" ''; postFixup = lib.optionalString (!stdenv.isDarwin && stdenv.hostPlatform.libc == "glibc") @@ -85,15 +120,19 @@ let disallowedReferences = [ stdenv.cc ]; passthru = { - inherit readline psqlSchema; + # Note: we export 'stdenv', because the chosen stdenv *might* be a llvmPackages-based + # one, and we want to propagate that to all extensions. + inherit readline psqlSchema stdenv; + compareVersion = builtins.compareVersions version; + hasJitSupport = jitEnabled; }; meta = with lib; { - homepage = https://www.postgresql.org; description = "A powerful, open source object-relational database system"; - license = licenses.postgresql; - maintainers = [ maintainers.ocharles ]; - platforms = platforms.unix; + homepage = https://www.postgresql.org; + license = licenses.postgresql; + maintainers = with maintainers; [ ocharles thoughtpolice ]; + platforms = platforms.unix; }; }); @@ -123,10 +162,19 @@ in { sha256 = "09l4zqs74fqnazdsyln9x657mq3wsbgng9wpvq71yh26cv2sq5c6"; }; - postgresql100 = common { + # NOTE: starting with PostgreSQL 10, the versioning scheme changed from + # .. to .. Thus there is no longer a + # 3rd component, and we should name attributes following only the major + # number. + postgresql10 = common { version = "10.5"; psqlSchema = "10.0"; sha256 = "04a07jkvc5s6zgh6jr78149kcjmsxclizsqabjw44ld4j5n633kc"; }; + postgresql11 = common { + version = "11beta2"; + psqlSchema = "11.0"; + sha256 = "0qxlfh1a7bhhamrbs3msk71pny7jxx0c0fs26zlmp7jjn138zqii"; + }; } diff --git a/pkgs/servers/sql/postgresql/ext/citus.nix b/pkgs/servers/sql/postgresql/ext/citus.nix new file mode 100644 index 0000000000000..f963ea63e316e --- /dev/null +++ b/pkgs/servers/sql/postgresql/ext/citus.nix @@ -0,0 +1,33 @@ +{ stdenv, fetchFromGitHub, postgresql, curl }: + +stdenv.mkDerivation rec { + name = "citus-${version}"; + version = "7.5.0"; + + src = fetchFromGitHub { + owner = "citusdata"; + repo = "citus"; + rev = "refs/tags/v${version}"; + sha256 = "1ipzla0whfr4zfzz4csjrzw1w9chlpgxxjlxblbsb9v9y9wd7i72"; + }; + + buildInputs = [ postgresql curl ]; + makeFlags = [ "PREFIX=$(out)" ]; + + patchPhase = '' + substituteInPlace ./Makefile \ + --replace '$(DESTDIR)$(includedir_server)' "$out/include/server" + ''; + + passthru = { + versionCheck = postgresql.compareVersion "9.6" >= 0 && postgresql.compareVersion "11" < 0; + }; + + meta = with stdenv.lib; { + description = "Transparent, distributed sharding and replication for PostgreSQL"; + homepage = https://www.citusdata.com/; + maintainers = with maintainers; [ thoughtpolice ]; + platforms = platforms.linux; + license = licenses.asl20; + }; +} diff --git a/pkgs/servers/sql/postgresql/cstore_fdw/default.nix b/pkgs/servers/sql/postgresql/ext/cstore_fdw.nix similarity index 79% rename from pkgs/servers/sql/postgresql/cstore_fdw/default.nix rename to pkgs/servers/sql/postgresql/ext/cstore_fdw.nix index b6b9f3a5650f5..d6b0b3da74306 100644 --- a/pkgs/servers/sql/postgresql/cstore_fdw/default.nix +++ b/pkgs/servers/sql/postgresql/ext/cstore_fdw.nix @@ -14,13 +14,11 @@ stdenv.mkDerivation rec { sha256 = "1cpkpbv4c82l961anzwp74r1jc8f0n5z5cvwy4lyrqg5jr501nd4"; }; - installPhase = '' - mkdir -p $out/{lib,share/extension} + makeFlags = [ "PREFIX=$(out)" ]; - cp *.so $out/lib - cp *.sql $out/share/extension - cp *.control $out/share/extension - ''; + passthru = { + versionCheck = postgresql.compareVersion "11" < 0; + }; meta = with stdenv.lib; { description = "Columnar storage for PostgreSQL"; diff --git a/pkgs/servers/sql/postgresql/pg_cron/default.nix b/pkgs/servers/sql/postgresql/ext/pg_cron.nix similarity index 66% rename from pkgs/servers/sql/postgresql/pg_cron/default.nix rename to pkgs/servers/sql/postgresql/ext/pg_cron.nix index c5a7a40546ef2..ce5e636084112 100644 --- a/pkgs/servers/sql/postgresql/pg_cron/default.nix +++ b/pkgs/servers/sql/postgresql/ext/pg_cron.nix @@ -2,7 +2,7 @@ stdenv.mkDerivation rec { name = "pg_cron-${version}"; - version = "1.0.2"; + version = "1.1.2"; buildInputs = [ postgresql ]; @@ -10,16 +10,14 @@ stdenv.mkDerivation rec { owner = "citusdata"; repo = "pg_cron"; rev = "refs/tags/v${version}"; - sha256 = "0z743bbal9j0pvqskznfj0zvjsqvdl7p90d4fdrl0sc0crc3nvyx"; + sha256 = "0n74dx1wkg9qxvjhnx03028465ap3p97v2kzqww833dws1wqk5m1"; }; - installPhase = '' - mkdir -p $out/{lib,share/extension} + makeFlags = [ "PREFIX=$(out)" ]; - cp *.so $out/lib - cp *.sql $out/share/extension - cp *.control $out/share/extension - ''; + passthru = { + versionCheck = postgresql.compareVersion "9.5" >= 0; + }; meta = with stdenv.lib; { description = "Run Cron jobs through PostgreSQL"; diff --git a/pkgs/servers/sql/postgresql/pg_hll/default.nix b/pkgs/servers/sql/postgresql/ext/pg_hll.nix similarity index 79% rename from pkgs/servers/sql/postgresql/pg_hll/default.nix rename to pkgs/servers/sql/postgresql/ext/pg_hll.nix index 6c453f6a40c32..7e9816d6136bd 100644 --- a/pkgs/servers/sql/postgresql/pg_hll/default.nix +++ b/pkgs/servers/sql/postgresql/ext/pg_hll.nix @@ -13,13 +13,11 @@ stdenv.mkDerivation rec { sha256 = "044x9v9kjhxb0idqb9f5i7c3yygxxsqliswl4kspqy9f9qcblckl"; }; - installPhase = '' - mkdir -p $out/{lib,share/extension} + makeFlags = [ "PREFIX=$(out)" ]; - cp *.so $out/lib - cp *.sql $out/share/extension - cp *.control $out/share/extension - ''; + passthru = { + versionCheck = postgresql.compareVersion "11" < 0; + }; meta = with stdenv.lib; { description = "HyperLogLog for PostgreSQL"; diff --git a/pkgs/servers/sql/postgresql/ext/pg_jobmon.nix b/pkgs/servers/sql/postgresql/ext/pg_jobmon.nix new file mode 100644 index 0000000000000..b92618a2efa97 --- /dev/null +++ b/pkgs/servers/sql/postgresql/ext/pg_jobmon.nix @@ -0,0 +1,25 @@ +{ stdenv, fetchFromGitHub, postgresql }: + +stdenv.mkDerivation rec { + name = "pg_jobmon-${version}"; + version = "1.3.3"; + + buildInputs = [ postgresql ]; + + src = fetchFromGitHub { + owner = "omniti-labs"; + repo = "pg_jobmon"; + rev = "refs/tags/v${version}"; + sha256 = "09izh6j1rpkllmy2kjhd9pwzld6lryp7825129k5jbbvnavxv6g8"; + }; + + makeFlags = [ "PREFIX=$(out)" ]; + + meta = with stdenv.lib; { + description = "Log and monitor PostgreSQL jobs"; + homepage = https://github.com/omniti-labs/pg_jobmon; + maintainers = with maintainers; [ thoughtpolice ]; + platforms = platforms.linux; + license = licenses.postgresql; + }; +} diff --git a/pkgs/servers/sql/postgresql/ext/pg_journal.nix b/pkgs/servers/sql/postgresql/ext/pg_journal.nix new file mode 100644 index 0000000000000..1754aec27ab90 --- /dev/null +++ b/pkgs/servers/sql/postgresql/ext/pg_journal.nix @@ -0,0 +1,32 @@ +{ stdenv, fetchFromGitHub, fetchpatch, pkgconfig, postgresql, systemd, openssl }: + +stdenv.mkDerivation rec { + name = "pg_journal-${version}"; + version = "0.2.0"; + + buildInputs = [ postgresql pkgconfig systemd.dev openssl.dev ]; + + src = fetchFromGitHub { + owner = "intgr"; + repo = "pg_journal"; + rev = "e3847a1ff34c0aa8e7d16646bf921f69433b39ae"; + sha256 = "0kgqw75hnm7dx9haiv26gwa8h73c39276pqkmnryn3fg469hl8wb"; + }; + + patches = [ + # See: https://github.com/intgr/pg_journal/issues/1 + (fetchpatch { + url = https://github.com/gosuai/pg_journal/commit/a8e534ee1089c35bc073113358166ce2fd9e2c99.patch; + sha256 = "1bgc1jzhkvwc86gvf5s8qfzlr9xiqdrdbi9zgppd1zb0i4ndmqcp"; + }) + ]; + + makeFlags = [ "PREFIX=$(out)" ]; + + meta = with stdenv.lib; { + description = "Log PostgreSQL messages to systemd journal"; + homepage = https://github.com/intgr/pg_journal; + maintainers = with maintainers; [ basvandijk ]; + license = licenses.postgresql; + }; +} diff --git a/pkgs/servers/sql/postgresql/ext/pg_partman.nix b/pkgs/servers/sql/postgresql/ext/pg_partman.nix new file mode 100644 index 0000000000000..abf7d76824e8f --- /dev/null +++ b/pkgs/servers/sql/postgresql/ext/pg_partman.nix @@ -0,0 +1,29 @@ +{ stdenv, fetchFromGitHub, postgresql }: + +stdenv.mkDerivation rec { + name = "pg_partman-${version}"; + version = "3.2.1"; + + buildInputs = [ postgresql ]; + + src = fetchFromGitHub { + owner = "keithf4"; + repo = "pg_partman"; + rev = "refs/tags/v${version}"; + sha256 = "069m2y20pkpk7lw7d2spaa1zpkb47dmm76rxi1d4qvq3vgfd739m"; + }; + + makeFlags = [ "PREFIX=$(out)" ]; + + passthru = { + versionCheck = postgresql.compareVersion "9.4" >= 0 && postgresql.compareVersion "11" < 0; + }; + + meta = with stdenv.lib; { + description = "Partition management extension for PostgreSQL"; + homepage = https://github.com/keithf4/pg_partman; + maintainers = with maintainers; [ thoughtpolice ]; + platforms = platforms.linux; + license = licenses.postgresql; + }; +} diff --git a/pkgs/servers/sql/postgresql/ext/pg_repack.nix b/pkgs/servers/sql/postgresql/ext/pg_repack.nix new file mode 100644 index 0000000000000..d74716ae50134 --- /dev/null +++ b/pkgs/servers/sql/postgresql/ext/pg_repack.nix @@ -0,0 +1,35 @@ +{ stdenv, fetchFromGitHub, postgresql, openssl, zlib, readline }: + +stdenv.mkDerivation rec { + name = "pg_repack-${version}"; + version = "1.4.3"; + + buildInputs = [ postgresql openssl zlib readline ]; + + src = fetchFromGitHub { + owner = "reorg"; + repo = "pg_repack"; + rev = "refs/tags/ver_${version}"; + sha256 = "1mmd22nfaxjwnbl3i95f3ivmjvfqwdflgaczlg3129dbpwg265xr"; + }; + + makeFlags = [ "PREFIX=$(out)" ]; + + passthru = { + versionCheck = postgresql.compareVersion "11" < 0; + }; + + meta = with stdenv.lib; { + description = "Reorganize tables in PostgreSQL databases with minimal locks"; + longDescription = '' + pg_repack is a PostgreSQL extension which lets you remove bloat from tables and indexes, and optionally restore + the physical order of clustered indexes. Unlike CLUSTER and VACUUM FULL it works online, without holding an + exclusive lock on the processed tables during processing. pg_repack is efficient to boot, + with performance comparable to using CLUSTER directly. + ''; + license = licenses.bsd3; + maintainers = with maintainers; [ danbst ]; + inherit (postgresql.meta) platforms; + inherit (src.meta) homepage; + }; +} diff --git a/pkgs/servers/sql/postgresql/pg_similarity/default.nix b/pkgs/servers/sql/postgresql/ext/pg_similarity.nix similarity index 66% rename from pkgs/servers/sql/postgresql/pg_similarity/default.nix rename to pkgs/servers/sql/postgresql/ext/pg_similarity.nix index 32945c9fa62b3..806a8ab81cdd3 100644 --- a/pkgs/servers/sql/postgresql/pg_similarity/default.nix +++ b/pkgs/servers/sql/postgresql/ext/pg_similarity.nix @@ -1,4 +1,4 @@ -{ stdenv, lib, fetchFromGitHub, gcc, postgresql }: +{ stdenv, lib, fetchFromGitHub, postgresql }: stdenv.mkDerivation { @@ -10,13 +10,10 @@ stdenv.mkDerivation { sha256 = "1z4v4r2yccdr8kz3935fnk1bc5vj0qj0apscldyap4wxlyi89xim"; }; - buildInputs = [ postgresql gcc ]; - buildPhase = "USE_PGXS=1 make"; - installPhase = '' - mkdir -p $out/bin # for buildEnv to setup proper symlinks - install -D pg_similarity.so -t $out/lib/ - install -D ./{pg_similarity--unpackaged--1.0.sql,pg_similarity--1.0.sql,pg_similarity.control} -t $out/share/extension - ''; + buildInputs = [ postgresql ]; + makeFlags = [ "PREFIX=$(out)" ]; + + USE_PGXS=1; # needed for 'make' to work meta = { description = '' diff --git a/pkgs/servers/sql/postgresql/topn/default.nix b/pkgs/servers/sql/postgresql/ext/pg_topn.nix similarity index 77% rename from pkgs/servers/sql/postgresql/topn/default.nix rename to pkgs/servers/sql/postgresql/ext/pg_topn.nix index 6886c80cf50d1..1f89f65b3efd3 100644 --- a/pkgs/servers/sql/postgresql/topn/default.nix +++ b/pkgs/servers/sql/postgresql/ext/pg_topn.nix @@ -2,7 +2,7 @@ stdenv.mkDerivation rec { name = "pg_topn-${version}"; - version = "2.0.2"; + version = "2.1.0"; nativeBuildInputs = [ protobufc ]; buildInputs = [ postgresql ]; @@ -14,13 +14,11 @@ stdenv.mkDerivation rec { sha256 = "00hc3hgnqv9xaalizbcvprb7s55sydj2qgk3rhgrdlwg2g025h62"; }; - installPhase = '' - mkdir -p $out/{lib,share/extension} + makeFlags = [ "PREFIX=$(out)" ]; - cp *.so $out/lib - cp *.sql $out/share/extension - cp *.control $out/share/extension - ''; + passthru = { + versionCheck = postgresql.compareVersion "9.4" >= 0; + }; meta = with stdenv.lib; { description = "Efficient querying of 'top values' for PostgreSQL"; diff --git a/pkgs/servers/sql/postgresql/pgjwt/default.nix b/pkgs/servers/sql/postgresql/ext/pgjwt.nix similarity index 54% rename from pkgs/servers/sql/postgresql/pgjwt/default.nix rename to pkgs/servers/sql/postgresql/ext/pgjwt.nix index 3e01d9bfe2ca0..503a09b0cd58e 100644 --- a/pkgs/servers/sql/postgresql/pgjwt/default.nix +++ b/pkgs/servers/sql/postgresql/ext/pgjwt.nix @@ -1,19 +1,19 @@ -{ stdenv, fetchFromGitHub }: +{ stdenv, fetchFromGitHub, postgresql }: + stdenv.mkDerivation rec { - name = "pgjwt-${version}"; + name = "pgjwt-${version}"; version = "unstable-2017-04-24"; + src = fetchFromGitHub { - owner = "michelp"; - repo = "pgjwt"; - rev = "546a2911027b716586e241be7fd4c6f1785237cd"; + owner = "michelp"; + repo = "pgjwt"; + rev = "546a2911027b716586e241be7fd4c6f1785237cd"; sha256 = "1riz0xvwb6y02j0fljbr9hcbqb2jqs4njlivmavy9ysbcrrv1vrf"; }; - dontBuild = true; - installPhase = '' - mkdir -p $out/bin # current postgresql extension mechanism in nixos requires bin directory - mkdir -p $out/share/extension - cp pg*sql *.control $out/share/extension - ''; + + buildInputs = [ postgresql ]; + makeFlags = [ "PREFIX=$(out)" ]; + meta = with stdenv.lib; { description = "PostgreSQL implementation of JSON Web Tokens"; longDescription = '' diff --git a/pkgs/servers/sql/postgresql/pgroonga/default.nix b/pkgs/servers/sql/postgresql/ext/pgroonga.nix similarity index 83% rename from pkgs/servers/sql/postgresql/pgroonga/default.nix rename to pkgs/servers/sql/postgresql/ext/pgroonga.nix index f4c7bfb1b85f1..1b48e33aada78 100644 --- a/pkgs/servers/sql/postgresql/pgroonga/default.nix +++ b/pkgs/servers/sql/postgresql/ext/pgroonga.nix @@ -12,13 +12,11 @@ stdenv.mkDerivation rec { nativeBuildInputs = [ pkgconfig ]; buildInputs = [ postgresql msgpack groonga ]; - makeFlags = [ "HAVE_MSGPACK=1" ]; + makeFlags = [ "HAVE_MSGPACK=1" "PREFIX=$(out)" ]; - installPhase = '' - mkdir -p $out/bin - install -D pgroonga.so -t $out/lib/ - install -D ./{pgroonga-*.sql,pgroonga.control} -t $out/share/extension - ''; + passthru = { + versionCheck = postgresql.compareVersion "11" < 0; + }; meta = with stdenv.lib; { description = "A PostgreSQL extension to use Groonga as the index"; diff --git a/pkgs/servers/sql/postgresql/pgtap/default.nix b/pkgs/servers/sql/postgresql/ext/pgtap.nix similarity index 90% rename from pkgs/servers/sql/postgresql/pgtap/default.nix rename to pkgs/servers/sql/postgresql/ext/pgtap.nix index c6eb4013c5ce4..fa493448b8c93 100644 --- a/pkgs/servers/sql/postgresql/pgtap/default.nix +++ b/pkgs/servers/sql/postgresql/ext/pgtap.nix @@ -13,9 +13,7 @@ stdenv.mkDerivation rec { nativeBuildInputs = [ postgresql perl perlPackages.TAPParserSourceHandlerpgTAP which ]; - installPhase = '' - install -D {sql/pgtap--${version}.sql,pgtap.control} -t $out/share/extension - ''; + makeFlags = [ "PREFIX=$(out)" ]; meta = with stdenv.lib; { description = "pgTAP is a unit testing framework for PostgreSQL"; diff --git a/pkgs/servers/sql/postgresql/plv8/default.nix b/pkgs/servers/sql/postgresql/ext/plv8.nix similarity index 68% rename from pkgs/servers/sql/postgresql/plv8/default.nix rename to pkgs/servers/sql/postgresql/ext/plv8.nix index 009f65b9d81c6..c090ebcc8777e 100644 --- a/pkgs/servers/sql/postgresql/plv8/default.nix +++ b/pkgs/servers/sql/postgresql/ext/plv8.nix @@ -14,15 +14,16 @@ stdenv.mkDerivation rec { sha256 = "1sfpxz0zcbinn6822j12lkwgrw9kfacrs83ic968rm489rl9w241"; }; + makeFlags = [ "PREFIX=$(out)" ]; + preConfigure = '' - substituteInPlace Makefile --replace '-lv8_libplatform' '-lv8_libplatform -lv8_libbase' + substituteInPlace Makefile \ + --replace '-lv8_libplatform' '-lv8_libplatform -lv8_libbase' ''; - installPhase = '' - mkdir -p $out/bin - install -D plv8.so -t $out/lib - install -D {plls,plcoffee,plv8}{--${version}.sql,.control} -t $out/share/extension - ''; + passthru = { + versionCheck = postgresql.compareVersion "11" < 0; + }; meta = with stdenv.lib; { description = "PL/v8 - A Procedural Language in JavaScript powered by V8"; diff --git a/pkgs/development/libraries/postgis/default.nix b/pkgs/servers/sql/postgresql/ext/postgis.nix similarity index 71% rename from pkgs/development/libraries/postgis/default.nix rename to pkgs/servers/sql/postgresql/ext/postgis.nix index a577d318523db..e2fc89ff0fae6 100644 --- a/pkgs/development/libraries/postgis/default.nix +++ b/pkgs/servers/sql/postgresql/ext/postgis.nix @@ -11,36 +11,6 @@ , file }: - /* - - ### NixOS - usage: - ================== - - services.postgresql.extraPlugins = [ (pkgs.postgis.override { postgresql = pkgs.postgresql95; }) ]; - - - ### important Postgis implementation details: - ============================================= - - Postgis provides a shared library implementing many operations. They are - exposed to the Postgres SQL interpreter by special SQL queries eg: - - CREATE FUNCTION [...] - AS '[..]liblwgeom', 'lwhistogram2d_in' LANGUAGE 'C' IMMUTABLE STRICT; -- WITH (isstrict); - - where liblwgeom is the shared library. - Postgis < 1.5 used absolute paths, in NixOS $libdir is always used. - - Thus if you want to use postgresql dumps which were created by non NixOS - systems you have to adopt the library path. - - - ### TODO: - ========= - the bin commands to have gtk gui: - */ - - let version = "2.4.4"; sha256 = "1hm8migjb53cymp4qvg1h20yqllmy9f7x0awv5450391i6syyqq6"; @@ -71,20 +41,28 @@ in stdenv.mkDerivation rec { ''; buildInputs = [ libxml2 postgresql geos proj perl gdal json_c pkgconfig ]; + dontDisableStatic = true; sql_comments = "postgis_comments.sql"; - sql_srcs = ["postgis.sql" "spatial_ref_sys.sql"]; # postgis config directory assumes /include /lib from the same root for json-c library NIX_LDFLAGS = "-L${stdenv.lib.getLib json_c}/lib"; - dontDisableStatic = true; preConfigure = '' sed -i 's@/usr/bin/file@${file}/bin/file@' configure configureFlags="--datadir=$out/share --datarootdir=$out/share --bindir=$out/bin --with-gdalconfig=${gdal}/bin/gdal-config --with-jsondir=${json_c.dev}" + makeFlags="PERL=${perl}/bin/perl datadir=$out/share pkglibdir=$out/lib bindir=$out/bin" + + # fix the build with clang/JIT support + # see https://trac.osgeo.org/postgis/ticket/4060 -- can be removed later + substituteInPlace ./postgis/Makefile.in \ + --replace 'PG_CPPFLAGS +=' 'PG_CPPFLAGS += -I../liblwgeom' + substituteInPlace ./raster/rt_pg/Makefile.in \ + --replace 'LIBPGCOMMON_CFLAGS="-I../../libpgcommon"' 'LIBPGCOMMON_CFLAGS=-I ../../liblwgeom -I../../libpgcommon' ''; + postConfigure = '' sed -i "s|@mkdir -p \$(DESTDIR)\$(PGSQL_BINDIR)||g ; s|\$(DESTDIR)\$(PGSQL_BINDIR)|$prefix/bin|g diff --git a/pkgs/servers/sql/postgresql/timescaledb/default.nix b/pkgs/servers/sql/postgresql/ext/timescaledb.nix similarity index 87% rename from pkgs/servers/sql/postgresql/timescaledb/default.nix rename to pkgs/servers/sql/postgresql/ext/timescaledb.nix index fab515035ce69..93c68dce7486d 100644 --- a/pkgs/servers/sql/postgresql/timescaledb/default.nix +++ b/pkgs/servers/sql/postgresql/ext/timescaledb.nix @@ -34,12 +34,9 @@ stdenv.mkDerivation rec { done ''; - postInstall = '' - # work around an annoying bug, by creating $out/bin, so buildEnv doesn't freak out later - # see https://github.com/NixOS/nixpkgs/issues/22653 - - mkdir -p $out/bin - ''; + passthru = { + versionCheck = postgresql.compareVersion "9.6" >= 0 && postgresql.compareVersion "11" < 0; + }; meta = with stdenv.lib; { description = "Scales PostgreSQL for time-series data via automatic partitioning across time and space"; diff --git a/pkgs/servers/sql/postgresql/tsearch_extras/default.nix b/pkgs/servers/sql/postgresql/ext/tsearch_extras.nix similarity index 59% rename from pkgs/servers/sql/postgresql/tsearch_extras/default.nix rename to pkgs/servers/sql/postgresql/ext/tsearch_extras.nix index 5140ae1a228f1..42814e87f6060 100644 --- a/pkgs/servers/sql/postgresql/tsearch_extras/default.nix +++ b/pkgs/servers/sql/postgresql/ext/tsearch_extras.nix @@ -2,23 +2,18 @@ stdenv.mkDerivation rec { name = "tsearch-extras-${version}"; - version = "0.3"; + version = "0.4"; src = fetchFromGitHub { - owner = "zulip"; - repo = "tsearch_extras"; - rev = version; - sha256 = "0i3i99lw80jwd4xflgdqabxmn1dnm1gm7dzf1mqv2drllxcy3yix"; + owner = "zulip"; + repo = "tsearch_extras"; + rev = "84e78f00931c4ef261d98197d6b5d94fc141f742"; # no release tag? + sha256 = "18j0saqblg3jhrz38splk173xjwdf32c67ymm18m8n5y94h8d2ba"; }; nativenativeBuildInputs = [ pkgconfig ]; buildInputs = [ postgresql ]; - - installPhase = '' - mkdir -p $out/bin - install -D tsearch_extras.so -t $out/lib/ - install -D ./{tsearch_extras--1.0.sql,tsearch_extras.control} -t $out/share/extension - ''; + makeFlags = [ "PREFIX=$(out)" ]; meta = with stdenv.lib; { description = "Provides a few PostgreSQL functions for a lower-level data full text search"; diff --git a/pkgs/servers/sql/postgresql/packages.nix b/pkgs/servers/sql/postgresql/packages.nix new file mode 100644 index 0000000000000..40718ee64f747 --- /dev/null +++ b/pkgs/servers/sql/postgresql/packages.nix @@ -0,0 +1,130 @@ +{ pkgs, lib }: + +let + llvmPackages = pkgs.llvmPackages_6; + postgresqlPackages = pkgs.callPackages ./default.nix { inherit llvmPackages; }; + + # Filter out any versions which fail a version check. + filterPackages = lib.filterAttrs (_: drv: drv.versionCheck or true); + + # Build an environment containing PostgreSQL, its libraries, and any paths + # containing binary-compatible installed plugins. + withPackages = postgresql: plugins: + if plugins == [] + then postgresql + else pkgs.buildEnv { + name = "postgresql-and-plugins-${postgresql.version}"; + # Make sure we include .man so that manual pages work for the user in their + # environment + paths = [ postgresql postgresql.lib postgresql.man ] ++ plugins; + + # We include /bin to ensure the $out/bin directory is created, which is + # needed because we'll be removing the files from that directory in postBuild + # below. See #22653 + pathsToLink = ["/" "/bin"]; + + buildInputs = [ pkgs.makeWrapper ]; + postBuild = '' + mkdir -p $out/bin + rm $out/bin/{pg_config,postgres,pg_ctl} + cp --target-directory=$out/bin ${postgresql}/bin/{postgres,pg_config,pg_ctl} + wrapProgram $out/bin/postgres --set NIX_PGLIBDIR $out/lib + ''; + }; + + # This is the same as above, but a bit more spicy: it takes a postgres + # package set and a continuation, which determines which extensions to use in + # the resulting environment. This is the analog of the NixOS module's method + # for selecting compatible plugins -- incompatible plugins will not exist in + # the attrset, resulting in an evaluation error. + withPackageSet = ps: k: withPackages ps.postgresql (k ps); + + makePackageSet = postgresql: + let + stdenv = postgresql.stdenv; # Use the stdenv for the particular version of Postgres + callPackage = p: args: pkgs.callPackage p (args // { inherit postgresql stdenv; }); + + self = filterPackages { + # Convenience function for end-users to easily build packages against a specific + # version. + inherit callPackage; + + # Convenience function for getting a full PostgreSQL derivation with extensions + # for the given version. + withPackages = withPackageSet self; + + # Convenience attribute that exports the postgres derivation used for builds. We + # export these from all-packages.nix to consolidate everything here. + inherit postgresql; + + # PostgreSQL extensions follow from here. + + citus = callPackage ./ext/citus.nix {}; + + cstore_fdw = callPackage ./ext/cstore_fdw.nix {}; + + pg_cron = callPackage ./ext/pg_cron.nix {}; + + pg_hll = callPackage ./ext/pg_hll.nix {}; + + pgjwt = callPackage ./ext/pgjwt.nix {}; + + pg_jobmon = callPackage ./ext/pg_jobmon.nix {}; + + pg_journal = callPackage ./ext/pg_journal.nix {}; + + pg_partman = callPackage ./ext/pg_partman.nix {}; + + pg_repack = callPackage ./ext/pg_repack.nix {}; + + pgroonga = callPackage ./ext/pgroonga.nix {}; + + pg_similarity = callPackage ./ext/pg_similarity.nix {}; + + pgtap = callPackage ./ext/pgtap.nix {}; + + pg_topn = callPackage ./ext/pg_topn.nix {}; + + plv8 = callPackage ./ext/plv8.nix { + v8 = pkgs.v8_6_x; + }; + + postgis = callPackage ./ext/postgis.nix { + ## NOTE: set postgresql to the version we use, so we don't end up in + ## the odd case where 'gdal' pulls in a different postgresql version and + ## causes various versions to depend on each other. e.g. if 9.6 is the + ## default and this is not overridden, and you choose 10, then psql 10's + ## closure will depend on psql 9.6 + gdal = pkgs.gdal.override { inherit postgresql; }; + }; + + timescaledb = callPackage ./ext/timescaledb.nix {}; + + tsearch_extras = callPackage ./ext/tsearch_extras.nix { }; + }; + in self; + + allPostgresqlPackages = with postgresqlPackages; { + postgresql93Packages = makePackageSet postgresql93; + postgresql94Packages = makePackageSet postgresql94; + postgresql95Packages = makePackageSet postgresql95; + postgresql96Packages = makePackageSet postgresql96; + postgresql10Packages = makePackageSet postgresql10; + postgresql11Packages = makePackageSet postgresql11; + }; +in +{ + # HEADS UP: do NOT export this from the top level of all-packages.nix! it is + # only used by the NixOS module for PostgreSQL in order to reduce some of the + # duplicated logic needed for withPackages. this should _only_ be used by + # postgresql.nix, and nothing more. Do not taunt Happy Fun Ball. + inherit withPackages; + + # This expression is useful primarily for NixOS tests: they run the basic + # tests with every version of PostgreSQL available, so they use this in order + # to enumerate them. It should also not be exported from all-packages.nix. + inherit allPostgresqlPackages; + + # Finally, include all of the package sets directly as well, so they can + # be exposed in all-packages.nix +} // allPostgresqlPackages diff --git a/pkgs/servers/sql/postgresql/disable-resolve_symlinks-94.patch b/pkgs/servers/sql/postgresql/patches/disable-resolve_symlinks-94.patch similarity index 100% rename from pkgs/servers/sql/postgresql/disable-resolve_symlinks-94.patch rename to pkgs/servers/sql/postgresql/patches/disable-resolve_symlinks-94.patch diff --git a/pkgs/servers/sql/postgresql/disable-resolve_symlinks.patch b/pkgs/servers/sql/postgresql/patches/disable-resolve_symlinks.patch similarity index 100% rename from pkgs/servers/sql/postgresql/disable-resolve_symlinks.patch rename to pkgs/servers/sql/postgresql/patches/disable-resolve_symlinks.patch diff --git a/pkgs/servers/sql/postgresql/hardcode-pgxs-path-96.patch b/pkgs/servers/sql/postgresql/patches/hardcode-pgxs-path-96.patch similarity index 100% rename from pkgs/servers/sql/postgresql/hardcode-pgxs-path-96.patch rename to pkgs/servers/sql/postgresql/patches/hardcode-pgxs-path-96.patch diff --git a/pkgs/servers/sql/postgresql/hardcode-pgxs-path.patch b/pkgs/servers/sql/postgresql/patches/hardcode-pgxs-path.patch similarity index 100% rename from pkgs/servers/sql/postgresql/hardcode-pgxs-path.patch rename to pkgs/servers/sql/postgresql/patches/hardcode-pgxs-path.patch diff --git a/pkgs/servers/sql/postgresql/less-is-more-96.patch b/pkgs/servers/sql/postgresql/patches/less-is-more-96.patch similarity index 100% rename from pkgs/servers/sql/postgresql/less-is-more-96.patch rename to pkgs/servers/sql/postgresql/patches/less-is-more-96.patch diff --git a/pkgs/servers/sql/postgresql/less-is-more.patch b/pkgs/servers/sql/postgresql/patches/less-is-more.patch similarity index 100% rename from pkgs/servers/sql/postgresql/less-is-more.patch rename to pkgs/servers/sql/postgresql/patches/less-is-more.patch diff --git a/pkgs/servers/sql/postgresql/patches/pgxs-nix.patch b/pkgs/servers/sql/postgresql/patches/pgxs-nix.patch new file mode 100644 index 0000000000000..478dc0a4686f8 --- /dev/null +++ b/pkgs/servers/sql/postgresql/patches/pgxs-nix.patch @@ -0,0 +1,29 @@ +--- Makefile.global 2018-08-06 02:21:37.865065005 -0500 ++++ Makefile.global.new 2018-08-06 02:30:17.063261754 -0500 +@@ -153,16 +153,16 @@ + PG_CONFIG = pg_config + endif + +-bindir := $(shell $(PG_CONFIG) --bindir) +-datadir := $(shell $(PG_CONFIG) --sharedir) +-sysconfdir := $(shell $(PG_CONFIG) --sysconfdir) +-libdir := $(shell $(PG_CONFIG) --libdir) +-pkglibdir := $(shell $(PG_CONFIG) --pkglibdir) +-includedir := $(shell $(PG_CONFIG) --includedir) +-pkgincludedir := $(shell $(PG_CONFIG) --pkgincludedir) +-mandir := $(shell $(PG_CONFIG) --mandir) +-docdir := $(shell $(PG_CONFIG) --docdir) +-localedir := $(shell $(PG_CONFIG) --localedir) ++bindir := $(PREFIX)/bin ++datadir := $(PREFIX)/share ++sysconfdir := $(PREFIX)/etc ++libdir := $(PREFIX)/lib ++pkglibdir := $(PREFIX)/lib ++includedir := $(PREFIX)/include ++pkgincludedir := @NIX_POSTGRES_INCLUDE@ ++mandir := $(PREFIX)/share/man ++docdir := $(PREFIX)/share/doc ++localedir := $(PREFIX)/share/locale + + endif # PGXS + diff --git a/pkgs/servers/sql/postgresql/specify_pkglibdir_at_runtime.patch b/pkgs/servers/sql/postgresql/patches/specify_pkglibdir_at_runtime.patch similarity index 100% rename from pkgs/servers/sql/postgresql/specify_pkglibdir_at_runtime.patch rename to pkgs/servers/sql/postgresql/patches/specify_pkglibdir_at_runtime.patch diff --git a/pkgs/servers/sql/postgresql/pg_repack/default.nix b/pkgs/servers/sql/postgresql/pg_repack/default.nix deleted file mode 100644 index 1b7cd08b082b7..0000000000000 --- a/pkgs/servers/sql/postgresql/pg_repack/default.nix +++ /dev/null @@ -1,35 +0,0 @@ -{ stdenv, fetchFromGitHub, postgresql, openssl, zlib, readline }: - -stdenv.mkDerivation rec { - name = "pg_repack-${version}"; - version = "1.4.3"; - - buildInputs = [ postgresql openssl zlib readline ]; - - src = fetchFromGitHub { - owner = "reorg"; - repo = "pg_repack"; - rev = "refs/tags/ver_${version}"; - sha256 = "1mmd22nfaxjwnbl3i95f3ivmjvfqwdflgaczlg3129dbpwg265xr"; - }; - - installPhase = '' - install -D bin/pg_repack -t $out/bin/ - install -D lib/pg_repack.so -t $out/lib/ - install -D lib/{pg_repack--${version}.sql,pg_repack.control} -t $out/share/extension - ''; - - meta = with stdenv.lib; { - description = "Reorganize tables in PostgreSQL databases with minimal locks"; - longDescription = '' - pg_repack is a PostgreSQL extension which lets you remove bloat from tables and indexes, and optionally restore - the physical order of clustered indexes. Unlike CLUSTER and VACUUM FULL it works online, without holding an - exclusive lock on the processed tables during processing. pg_repack is efficient to boot, - with performance comparable to using CLUSTER directly. - ''; - license = licenses.bsd3; - maintainers = with maintainers; [ danbst ]; - inherit (postgresql.meta) platforms; - inherit (src.meta) homepage; - }; -} diff --git a/pkgs/top-level/aliases.nix b/pkgs/top-level/aliases.nix index fed02f40134d2..9f0b886f5d07c 100644 --- a/pkgs/top-level/aliases.nix +++ b/pkgs/top-level/aliases.nix @@ -214,6 +214,19 @@ mapAliases ({ pltScheme = racket; # just to be sure poppler_qt5 = libsForQt5.poppler; # added 2015-12-19 procps-ng = procps; # added 2018-06-08 + + # added 2018-04-11, remove after 18.09 release + postgresql100 = throw "deprecated: 'postgresql100' was badly misnamed, use 'postgresql10' instead"; + postgis = throw "deprecated: use 'postgresqlPackages.postgis' instead"; + pgjwt = throw "deprecated: use 'postgresqlPackages.pgjwt' instead"; + pg_repack = throw "deprecated: use 'postgresqlPackages.pg_repack' instead"; + pgroonga = throw "deprecated: use 'postgresqlPackages.pgroonga' instead"; + pg_similarity = throw "deprecated: use 'postgresqlPackages.pg_similarity' instead"; + pgtap = throw "deprecated: use 'postgresqlPackages.pgtap' instead"; + plv8 = throw "deprecated: use 'postgresqlPackages.plv8' instead"; + timescaledb = throw "deprecated: use 'postgresqlPackages.timescaledb' instead"; + tsearch_extras = throw "deprecated: use 'postgresqlPackages.tsearch_extras' instead"; + prometheus-statsd-bridge = prometheus-statsd-exporter; # added 2017-08-27 pulseaudioLight = pulseaudio; # added 2018-04-25 qca-qt5 = libsForQt5.qca-qt5; # added 2015-12-19 diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 182eb55557e97..d51cf5013cbb8 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -3034,18 +3034,6 @@ with pkgs; pgf_graphics = callPackage ../tools/graphics/pgf { }; - pgjwt = callPackage ../servers/sql/postgresql/pgjwt {}; - - cstore_fdw = callPackage ../servers/sql/postgresql/cstore_fdw {}; - - pg_hll = callPackage ../servers/sql/postgresql/pg_hll {}; - - pg_cron = callPackage ../servers/sql/postgresql/pg_cron {}; - - pgtap = callPackage ../servers/sql/postgresql/pgtap {}; - - pg_topn = callPackage ../servers/sql/postgresql/topn {}; - pigz = callPackage ../tools/compression/pigz { }; pixz = callPackage ../tools/compression/pixz { }; @@ -11501,18 +11489,8 @@ with pkgs; pdf2xml = callPackage ../development/libraries/pdf2xml {} ; - pg_repack = callPackage ../servers/sql/postgresql/pg_repack {}; - - pg_similarity = callPackage ../servers/sql/postgresql/pg_similarity {}; - pg_tmp = callPackage ../development/tools/database/pg_tmp { }; - pgroonga = callPackage ../servers/sql/postgresql/pgroonga {}; - - plv8 = callPackage ../servers/sql/postgresql/plv8 { - v8 = v8_6_x; - }; - phonon = callPackage ../development/libraries/phonon {}; phonon-backend-gstreamer = callPackage ../development/libraries/phonon/backends/gstreamer.nix {}; @@ -11588,8 +11566,6 @@ with pkgs; buildPythonApplication click future six; }; - postgis = callPackage ../development/libraries/postgis { }; - protobuf = protobuf3_4; protobuf3_5 = callPackage ../development/libraries/protobuf/3.5.nix { }; @@ -13350,16 +13326,38 @@ with pkgs; libmemcached = null; # Detection is broken upstream }; - postgresql = postgresql96; + ## ----- POSTGRESQL ------------------------------------------------------------------- + + # all postgresql packages, including extensions + inherit (import ../servers/sql/postgresql/packages.nix { inherit pkgs lib; }) + postgresql93Packages + postgresql94Packages + postgresql95Packages + postgresql96Packages + postgresql10Packages + postgresql11Packages; + + # the default postgres version + package set + postgresqlPackages = postgresql10Packages; + postgresql = postgresqlPackages.postgresql; + + # named attributes for non-default versions of postgresql by itself. + postgresql93 = postgresql93Packages.postgresql; + postgresql94 = postgresql94Packages.postgresql; + postgresql95 = postgresql95Packages.postgresql; + postgresql96 = postgresql96Packages.postgresql; + postgresql10 = postgresql10Packages.postgresql; + postgresql11 = postgresql11Packages.postgresql; + + ## -- miscellaneous postgresql-related packages. - inherit (callPackages ../servers/sql/postgresql { }) - postgresql93 - postgresql94 - postgresql95 - postgresql96 - postgresql100; + postgresql_jdbc = callPackage ../development/java-modules/postgresql_jdbc { }; - postgresql_jdbc = callPackage ../servers/sql/postgresql/jdbc { }; + psqlodbc = callPackage ../development/libraries/psqlodbc { }; + + timescaledb-parallel-copy = callPackage ../development/tools/database/timescaledb-parallel-copy { }; + + ## ----- END: POSTGRESQL -------------------------------------------------------------- inherit (callPackage ../servers/monitoring/prometheus { buildGoPackage = buildGo110Package; @@ -13398,8 +13396,6 @@ with pkgs; prometheus-varnish-exporter = callPackage ../servers/monitoring/prometheus/varnish-exporter.nix { }; prometheus-jmx-httpserver = callPackage ../servers/monitoring/prometheus/jmx-httpserver.nix { }; - psqlodbc = callPackage ../servers/sql/postgresql/psqlodbc { }; - pure-ftpd = callPackage ../servers/ftp/pure-ftpd { }; pyIRCt = callPackage ../servers/xmpp/pyIRCt {}; @@ -18865,8 +18861,6 @@ with pkgs; fftw = fftwSinglePrec; }; - timescaledb = callPackage ../servers/sql/postgresql/timescaledb {}; - timewarrior = callPackage ../applications/misc/timewarrior { }; timidity = callPackage ../tools/misc/timidity { }; @@ -18950,8 +18944,6 @@ with pkgs; trojita = libsForQt5.callPackage ../applications/networking/mailreaders/trojita { }; - tsearch_extras = callPackage ../servers/sql/postgresql/tsearch_extras { }; - tudu = callPackage ../applications/office/tudu { }; tuxguitar = callPackage ../applications/editors/music/tuxguitar { };