diff --git a/pkgs/servers/sql/postgresql/default.nix b/pkgs/servers/sql/postgresql/default.nix index f36f5d2982a06..bd6f3c7344213 100644 --- a/pkgs/servers/sql/postgresql/default.nix +++ b/pkgs/servers/sql/postgresql/default.nix @@ -1,11 +1,27 @@ { stdenv, lib, fetchurl, makeWrapper , glibc, zlib, readline, libossp_uuid, openssl, libxml2, tzdata, systemd -}: + +# Gate JIT support right now behind a flag; it increases closure size +# dramatically due to the PostgreSQL build system requiring a hard dependency +# on clang-wrapper (~140MB -> 1.4GB). This must be worked around before it can +# be enabled by default by making clang-wrapper a build-time only dependency. +, llvmPackages, enableJitSupport ? false +}@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; @@ -20,7 +36,8 @@ let buildInputs = [ zlib readline openssl libxml2 makeWrapper ] ++ lib.optionals (!stdenv.isDarwin) [ libossp_uuid ] - ++ lib.optionals (atLeast "9.6" && !stdenv.isDarwin) [ systemd ]; + ++ lib.optionals (atLeast "9.6" && !stdenv.isDarwin) [ systemd ] + ++ lib.optionals jitEnabled (with llvmPackages; [ clang llvm ]); enableParallelBuilding = true; @@ -39,6 +56,7 @@ let "--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 = @@ -87,11 +105,14 @@ let doInstallCheck = false; # needs a running daemon? - disallowedReferences = [ stdenv.cc ]; + disallowedReferences = lib.optionals (!jitEnabled) [ 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; { diff --git a/pkgs/servers/sql/postgresql/ext/postgis.nix b/pkgs/servers/sql/postgresql/ext/postgis.nix index a577d318523db..2700461f595bd 100644 --- a/pkgs/servers/sql/postgresql/ext/postgis.nix +++ b/pkgs/servers/sql/postgresql/ext/postgis.nix @@ -95,6 +95,10 @@ in stdenv.mkDerivation rec { "raster/scripts/python/Makefile"; ''; + passthru = { + versionCheck = postgresql.hasJitSupport == false; + }; + meta = with stdenv.lib; { description = "Geographic Objects for PostgreSQL"; homepage = http://postgis.refractions.net; diff --git a/pkgs/servers/sql/postgresql/packages.nix b/pkgs/servers/sql/postgresql/packages.nix index 9da69628d820e..94c1ad8c34f90 100644 --- a/pkgs/servers/sql/postgresql/packages.nix +++ b/pkgs/servers/sql/postgresql/packages.nix @@ -1,14 +1,16 @@ { pkgs, lib }: let - postgresqlPackages = pkgs.callPackages ./default.nix {}; + 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); makePackageSet = postgresql: let - callPackage = p: args: pkgs.callPackage p (args // { inherit postgresql; }); + stdenv = postgresql.stdenv; # Use the stdenv for the particular version of Postgres + callPackage = p: args: pkgs.callPackage p (args // { inherit postgresql stdenv; }); in filterPackages { # Convenience function for end-users to easily build packages against a specific