diff --git a/nixos/tests/postgresql.nix b/nixos/tests/postgresql.nix index 975ba7f488e28..9e1f4f235af03 100644 --- a/nixos/tests/postgresql.nix +++ b/nixos/tests/postgresql.nix @@ -7,7 +7,7 @@ with import ../lib/testing.nix { inherit system pkgs; }; with pkgs.lib; let - postgresql-versions = pkgs.callPackages ../../pkgs/servers/sql/postgresql { }; + postgresql-versions = import ../../pkgs/servers/sql/postgresql pkgs pkgs; test-sql = pkgs.writeText "postgresql-test" '' CREATE EXTENSION pgcrypto; -- just to check if lib loading works CREATE TABLE sth ( @@ -29,8 +29,8 @@ let machine = {...}: { - services.postgresql.package = postgresql-package; services.postgresql.enable = true; + services.postgresql.package = postgresql-package; services.postgresqlBackup.enable = true; services.postgresqlBackup.databases = optional (!backup-all) "postgres"; diff --git a/pkgs/servers/sql/postgresql/default.nix b/pkgs/servers/sql/postgresql/default.nix index 2b22c36e829fc..0624998e5deba 100644 --- a/pkgs/servers/sql/postgresql/default.nix +++ b/pkgs/servers/sql/postgresql/default.nix @@ -1,14 +1,22 @@ -{ lib, stdenv, glibc, fetchurl, zlib, readline, libossp_uuid, openssl, libxml2, makeWrapper, tzdata, systemd, icu, pkgconfig }: - let - common = { version, sha256, psqlSchema }: + generic = + # dependencies + { stdenv, lib, fetchurl, makeWrapper + , glibc, zlib, readline, openssl, icu, systemd, libossp_uuid + , pkgconfig, libxml2, tzdata + + # for postgreql.pkgs + , this, self, newScope, buildEnv + + # source specification + , version, sha256, psqlSchema + }: let atLeast = lib.versionAtLeast version; - - # Build with ICU by default on versions that support it icuEnabled = atLeast "10"; - in stdenv.mkDerivation (rec { + + in stdenv.mkDerivation rec { name = "postgresql-${version}"; inherit version; @@ -97,50 +105,94 @@ let disallowedReferences = [ stdenv.cc ]; passthru = { - inherit readline psqlSchema; + inherit readline psqlSchema version; + + pkgs = let + scope = { postgresql = this; }; + newSelf = self // scope; + newSuper = { callPackage = newScope (scope // this.pkgs); }; + in import ./packages.nix newSelf newSuper; + + withPackages = postgresqlWithPackages { + inherit makeWrapper buildEnv; + postgresql = this; + } + this.pkgs; }; meta = with lib; { homepage = https://www.postgresql.org; description = "A powerful, open source object-relational database system"; license = licenses.postgresql; - maintainers = with maintainers; [ ocharles thoughtpolice ]; + maintainers = with maintainers; [ ocharles thoughtpolice danbst ]; platforms = platforms.unix; knownVulnerabilities = optional (!atLeast "9.4") "PostgreSQL versions older than 9.4 are not maintained anymore!"; }; - }); + }; + + postgresqlWithPackages = { postgresql, makeWrapper, buildEnv }: pkgs: f: buildEnv { + name = "postgresql-and-plugins-${postgresql.version}"; + paths = f pkgs ++ [ + postgresql + postgresql.lib + postgresql.man # in case user installs this into environment + ]; + buildInputs = [ makeWrapper ]; + + # 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"]; + + 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 + ''; + }; -in { +in self: super: { - postgresql_9_4 = common { + postgresql_9_4 = super.callPackage generic { version = "9.4.20"; psqlSchema = "9.4"; sha256 = "0zzqjz5jrn624hzh04drpj6axh30a9k6bgawid6rwk45nbfxicgf"; + this = self.postgresql_9_4; + inherit self; }; - postgresql_9_5 = common { + postgresql_9_5 = super.callPackage generic { version = "9.5.15"; psqlSchema = "9.5"; sha256 = "0i2lylgmsmy2g1ixlvl112fryp7jmrd0i2brk8sxb7vzzpg3znnv"; + this = self.postgresql_9_5; + inherit self; }; - postgresql_9_6 = common { + postgresql_9_6 = super.callPackage generic { version = "9.6.11"; psqlSchema = "9.6"; sha256 = "0c55akrkzqd6p6a8hr0338wk246hl76r9j16p4zn3s51d7f0l99q"; + this = self.postgresql_9_6; + inherit self; }; - postgresql_10 = common { + postgresql_10 = super.callPackage generic { version = "10.6"; psqlSchema = "10.0"; sha256 = "0jv26y3f10svrjxzsgqxg956c86b664azyk2wppzpa5x11pjga38"; + this = self.postgresql_10; + inherit self; }; - postgresql_11 = common { + postgresql_11 = super.callPackage generic { version = "11.1"; psqlSchema = "11.1"; sha256 = "026v0sicsh7avzi45waf8shcbhivyxmi7qgn9fd1x0vl520mx0ch"; + this = self.postgresql_11; + inherit self; }; -} +} \ No newline at end of file diff --git a/pkgs/servers/sql/postgresql/packages.nix b/pkgs/servers/sql/postgresql/packages.nix new file mode 100644 index 0000000000000..ba3da25bc16be --- /dev/null +++ b/pkgs/servers/sql/postgresql/packages.nix @@ -0,0 +1,30 @@ +self: super: { + + pg_repack = super.callPackage ./ext/pg_repack.nix { }; + + pg_similarity = super.callPackage ./ext/pg_similarity.nix { }; + + pgroonga = super.callPackage ./ext/pgroonga.nix { }; + + plv8 = super.callPackage ./ext/plv8.nix { + v8 = super.callPackage ../../../development/libraries/v8/plv8_6_x.nix { + python = self.python2; + }; + }; + + pgjwt = super.callPackage ./ext/pgjwt.nix { }; + + cstore_fdw = super.callPackage ./ext/cstore_fdw.nix { }; + + pg_hll = super.callPackage ./ext/pg_hll.nix { }; + + pg_cron = super.callPackage ./ext/pg_cron.nix { }; + + pg_topn = super.callPackage ./ext/pg_topn.nix { }; + + pgtap = super.callPackage ./ext/pgtap.nix { }; + + timescaledb = super.callPackage ./ext/timescaledb.nix { }; + + tsearch_extras = super.callPackage ./ext/tsearch_extras.nix { }; +} \ No newline at end of file diff --git a/pkgs/top-level/aliases.nix b/pkgs/top-level/aliases.nix index e13e9adfa1657..fcabdf7c69a8b 100644 --- a/pkgs/top-level/aliases.nix +++ b/pkgs/top-level/aliases.nix @@ -240,6 +240,20 @@ mapAliases ({ postgresql95 = postgresql_9_5; postgresql96 = postgresql_9_6; postgresql100 = throw "deprecated 2018-10-21: use postgresql_10 instead"; + # postgresql plugins + pgjwt = postgresqlPackages.pgjwt; + pg_repack = postgresqlPackages.pg_repack; + pgroonga = postgresqlPackages.pgroonga; + pg_similarity = postgresqlPackages.pg_similarity; + pgtap = postgresqlPackages.pgtap; + plv8 = postgresqlPackages.plv8; + timescaledb = postgresqlPackages.timescaledb; + tsearch_extras = postgresqlPackages.tsearch_extras; + cstore_fdw = postgresqlPackages.cstore_fdw; + pg_hll = postgresqlPackages.pg_hll; + pg_cron = postgresqlPackages.pg_cron; + pg_topn = postgresqlPackages.pg_topn; + # end procps-ng = procps; # added 2018-06-08 prometheus-statsd-bridge = prometheus-statsd-exporter; # added 2017-08-27 pulseaudioLight = pulseaudio; # added 2018-04-25 diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 8709e4d90f249..44d513dca6947 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -13949,14 +13949,15 @@ in timescaledb-parallel-copy = callPackage ../development/tools/database/timescaledb-parallel-copy { }; - postgresql = postgresql_9_6; - - inherit (callPackages ../servers/sql/postgresql { }) + inherit (import ../servers/sql/postgresql pkgs super) postgresql_9_4 postgresql_9_5 postgresql_9_6 postgresql_10 - postgresql_11; + postgresql_11 + ; + postgresql = postgresql_9_6.override { this = postgresql; }; + postgresqlPackages = recurseIntoAttrs postgresql.pkgs; postgresql_jdbc = callPackage ../development/java-modules/postgresql_jdbc { };