Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use pkgsStatic instead of static-haskell-nix, bump to libpq 16 and support GSSAPI #3169

Merged
merged 4 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
### Fixed

- #3149, Misleading "Starting PostgREST.." logs on schema cache reloading - @steve-chavez
- #2815, Build static executable with GSSAPI support - @wolfgangwalther

### Deprecated

Expand Down
20 changes: 4 additions & 16 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ let
allOverlays.build-toolbox
allOverlays.checked-shell-script
allOverlays.gitignore
(allOverlays.postgresql-default { inherit patches; })
allOverlays.postgresql-libpq
allOverlays.postgresql-legacy
allOverlays.postgresql-future
allOverlays.postgis
Expand All @@ -60,23 +60,11 @@ let
{ name = "postgresql-9.6"; postgresql = pkgs.postgresql_9_6.withPackages (p: [ p.postgis p.pg_safeupdate ]); }
];

patches =
pkgs.callPackage nix/patches { };

# Dynamic derivation for PostgREST
postgrest =
pkgs.haskell.packages."${compiler}".callCabal2nix name src { };

# Functionality that derives a fully static Haskell package based on
# nh2/static-haskell-nix
staticHaskellPackage =
import nix/static-haskell-package.nix { inherit nixpkgs system compiler patches allOverlays; };

# Static executable.
postgrestStatic =
lib.justStaticExecutables (lib.dontCheck (staticHaskellPackage name src).package);

packagesStatic = (staticHaskellPackage name src).survey;
staticHaskellPackage = import nix/static.nix { inherit compiler name pkgs src; };

# Options passed to cabal in dev tools and tests
devCabalOptions =
Expand Down Expand Up @@ -160,8 +148,8 @@ rec {
};
} // pkgs.lib.optionalAttrs pkgs.stdenv.isLinux rec {
# Static executable.
inherit postgrestStatic;
inherit packagesStatic;
inherit (staticHaskellPackage) postgrestStatic;
inherit (staticHaskellPackage) packagesStatic;

# Docker images and loading script.
docker =
Expand Down
9 changes: 0 additions & 9 deletions nix/UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,6 @@ postgrest-nixpkgs-upgrade

```

## Update pinned version of `static-haskell-nix`

We pin [`static-haskell-nix`](https://github.com/nh2/static-haskell-nix) in
[`nix/static-haskell-package.nix`](static-haskell-package.nix). Upgrade the
pinned revision and the tarball hash if necessary. See
[`nix/nixpkgs-upgrade.nix`](nixpkgs-upgrade.nix) for how to get the correct
tarball hash, or just change the hash to an arbitrary value of correct length,
run `nix-build` and use the expected value from the resulting error message.

## Review overlays

Check whether the individual [overlays](overlays) are still required.
Expand Down
65 changes: 65 additions & 0 deletions nix/libpq.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Creating a separate libpq package is is discussed in
# https://github.com/NixOS/nixpkgs/issues/61580, but nixpkgs has not moved
# forward, yet.
# This package is passed to postgresql-libpq (haskell) which needs to be
# cross-compiled to the static build and possibly other architectures as
# as well. To reduce the number of dependencies that need to be built with
# it, this derivation focuses on building the client libraries only. No
# server, no tests.
{ stdenv
, lib
, openssl
, zlib
, libkrb5
, icu
, postgresql
, pkg-config
, tzdata
}:

stdenv.mkDerivation {
pname = "libpq";
inherit (postgresql) src version;

configureFlags = [
"--without-gssapi"
"--without-icu"
"--without-readline"
"--with-gssapi"
"--with-openssl"
"--with-system-tzdata=${tzdata}/share/zoneinfo"
];

nativeBuildInputs = [ pkg-config tzdata ];
buildInputs = [ libkrb5 openssl zlib ];

buildFlags = [ "submake-libpq" "submake-libpgport" ];

installPhase = ''
runHook preInstall

make -C src/bin/pg_config install
make -C src/common install
make -C src/include install
make -C src/interfaces/libpq install
make -C src/port install

rm -rfv $out/share

runHook postInstall
'';

# To avoid linking errors in the static build with gssapi
postInstall = ''
substituteInPlace $out/lib/pkgconfig/libpq.pc\
--replace "Requires.private:" "Requires.private: krb5-gssapi,"
'';

outputs = [ "out" ];

meta = with lib; {
homepage = "https://www.postgresql.org";
description = "Client API library for PostgreSQL";
license = licenses.postgresql;
};
}
2 changes: 1 addition & 1 deletion nix/overlays/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
gitignore = import ./gitignore.nix;
haskell-packages = import ./haskell-packages.nix;
postgis = import ./postgis.nix;
postgresql-default = import ./postgresql-default.nix;
postgresql-libpq = import ./postgresql-libpq.nix;
postgresql-legacy = import ./postgresql-legacy.nix;
postgresql-future = import ./postgresql-future.nix;
slocat = import ./slocat.nix;
Expand Down
9 changes: 6 additions & 3 deletions nix/overlays/haskell-packages.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ compiler, extraOverrides ? (final: prev: { }) }:
{ compiler }:

self: super:
let
Expand Down Expand Up @@ -41,11 +41,14 @@ let
# Marked as broken (?)
fuzzyset = lib.markUnbroken prev.fuzzyset;

postgresql-libpq = lib.dontCheck prev.postgresql-libpq_0_10_0_0;
postgresql-libpq = lib.dontCheck
(prev.postgresql-libpq_0_10_0_0.override {
postgresql = super.libpq;
});

hasql-pool = lib.dontCheck prev.hasql-pool_0_10;

} // extraOverrides final prev;
};
in
{
haskell =
Expand Down
8 changes: 0 additions & 8 deletions nix/overlays/postgresql-default.nix

This file was deleted.

6 changes: 6 additions & 0 deletions nix/overlays/postgresql-libpq.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
self: super:
{
libpq = super.callPackage ../libpq.nix {
postgresql = super.postgresql_16;
};
}
29 changes: 0 additions & 29 deletions nix/patches/default.nix

This file was deleted.

11 changes: 0 additions & 11 deletions nix/patches/postgresql-atexit.patch

This file was deleted.

12 changes: 0 additions & 12 deletions nix/patches/static-haskell-nix-ghc-bignum.patch

This file was deleted.

13 changes: 0 additions & 13 deletions nix/patches/static-haskell-nix-ncurses.patch

This file was deleted.

12 changes: 0 additions & 12 deletions nix/patches/static-haskell-nix-openssl.patch

This file was deleted.

65 changes: 0 additions & 65 deletions nix/static-haskell-package.nix

This file was deleted.

58 changes: 58 additions & 0 deletions nix/static.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{ compiler
, name
, pkgs
, src
}:
let
# This builds a static PostgREST exectuable based on pkgsStatic.
# pkgsStatic is based on musl, so is a kind of cross-compilation.
# We still make this explicit here via pkgsCross, because we need
# to get postgresql/libpq for musl, too.
pkgsCross = pkgs.pkgsCross.musl64;
inherit (pkgsCross) pkgsStatic;
inherit (pkgsStatic.haskell) lib;

packagesStatic =
pkgsStatic.haskell.packages."${compiler}".override (old: {
ghc = pkgsStatic.pkgsBuildHost.haskell.compiler."${compiler}".override {
# Using the bundled libffi generally works better for cross-compiling
libffi = null;
# Building sphinx fails on some platforms
enableDocs = false;
# Cross compiling with native bignum works better than with gmp
enableNativeBignum = true;
};

overrides = pkgs.lib.composeExtensions old.overrides (final: prev: {
postgresql-libpq = (prev.postgresql-libpq.override {
# postgresql doesn't build in the fully static overlay - but the default
# derivation is built with static libraries anyway.
postgresql = pkgsCross.libpq;
}).overrideAttrs (finalAttrs: prevAttrs: {
# Using use-pkg-config flag, because pg_config won't work when cross-compiling
configureFlags = prevAttrs.configureFlags ++ [ "-fuse-pkg-config" ];
# Using pkg-config without pkgsCross, because "pkg-config" is hardcoded in
# postgresql-libpq's Setup.hs. Using pkgsStatic to make pkg-config return the
# static libs for libpq.
nativeBuildInputs = prevAttrs.nativeBuildInputs ++ [ pkgs.pkgsStatic.pkg-config ];

buildInputs = prevAttrs.buildInputs ++ [
(pkgsStatic.libkrb5.overrideAttrs (finalAttrs: prevAttrs: {
# disable keyutils dependency, to avoid linking errors
configureFlags = prevAttrs.configureFlags ++ [ "--without-keyutils" ];
}))
];
});
});
});

makeExecutableStatic = drv:
lib.justStaticExecutables
(lib.appendConfigureFlag drv "--enable-executable-static");

in
{
inherit packagesStatic;

postgrestStatic = makeExecutableStatic (packagesStatic.callCabal2nix name src { });
}
Loading