Skip to content

Commit 7c47bed

Browse files
committed
feat: package postgres locally
1 parent 90d602a commit 7c47bed

16 files changed

+637
-6
lines changed

flake.nix

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,30 @@
5353
# pull them from the overlays/ directory automatically, but we don't
5454
# want to have an arbitrary order, since it might matter. being
5555
# explicit is better.
56+
57+
(final: prev: {
58+
libxml2 = final.callPackage ./nix/libxml2.nix { };
59+
postgresql = final.callPackage ./nix/postgresql/default.nix {
60+
inherit (final) lib;
61+
inherit (final) stdenv;
62+
inherit (final) fetchurl;
63+
inherit (final) makeWrapper;
64+
inherit (final) callPackage;
65+
inherit (final) libxml2;
66+
};
67+
})
5668
(import ./nix/overlays/cargo-pgrx-0-11-3.nix)
5769
# (import ./nix/overlays/postgis.nix)
5870
#(import ./nix/overlays/gdal-small.nix)
5971

6072
];
6173
};
62-
74+
75+
postgresql_15 = pkgs.postgresql.postgresql_15;
76+
postgresql_16 = pkgs.postgresql.postgresql_16;
77+
postgresql = pkgs.postgresql.postgresql_15;
6378
sfcgal = pkgs.callPackage ./nix/ext/sfcgal/sfcgal.nix { };
64-
pg_regress = pkgs.callPackage ./nix/ext/pg_regress.nix { };
79+
pg_regress = pkgs.callPackage ./nix/ext/pg_regress.nix { inherit postgresql; };
6580

6681
# Our list of PostgreSQL extensions which come from upstream Nixpkgs.
6782
# These are maintained upstream and can easily be used here just by
@@ -128,7 +143,12 @@
128143
#this var is a convenience setting to import the orioledb patched version of postgresql
129144
postgresql_orioledb_16 = oriole_pkgs.postgresql_orioledb_16;
130145
#postgis_override = pkgs.postgis_override;
146+
# Function to map PostgreSQL versions
147+
getPostgresqlPackage = version:
148+
pkgs.postgresql."postgresql_${version}";
131149

150+
# List of supported PostgreSQL versions
151+
supportedVersions = [ "15" "16" ];
132152
# Create a 'receipt' file for a given postgresql package. This is a way
133153
# of adding a bit of metadata to the package, which can be used by other
134154
# tools to inspect what the contents of the install are: the PSQL
@@ -170,7 +190,7 @@
170190
in map (path: pkgs.callPackage path { inherit postgresql; }) orioledbExtension;
171191

172192
makeOurPostgresPkgs = version:
173-
let postgresql = pkgs."postgresql_${version}";
193+
let postgresql = getPostgresqlPackage version;
174194
in map (path: pkgs.callPackage path { inherit postgresql; }) ourExtensions;
175195

176196
# Create an attrset that contains all the extensions included in a server for the orioledb version of postgresql + extension.
@@ -202,7 +222,7 @@
202222
# basis for building extensions, etc.
203223
makePostgresBin = version:
204224
let
205-
postgresql = pkgs."postgresql_${version}";
225+
postgresql = getPostgresqlPackage version;
206226
upstreamExts = map
207227
(ext: {
208228
name = postgresql.pkgs."${ext}".pname;

nix/ext/pg_regress.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
stdenv.mkDerivation {
77
pname = "pg_regress";
8-
version = postgresql.version;
8+
version = "0.0.1";
99

1010
phases = [ "installPhase" ];
1111

@@ -21,4 +21,4 @@ stdenv.mkDerivation {
2121
platforms = postgresql.meta.platforms;
2222
license = licenses.postgresql;
2323
};
24-
}
24+
}

nix/libxml2.nix

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
{ stdenv
2+
, lib
3+
, fetchurl
4+
, pkg-config
5+
, autoreconfHook
6+
, libintl
7+
, python3
8+
, gettext
9+
, ncurses
10+
, findXMLCatalogs
11+
, libiconv
12+
, pythonSupport ? enableShared &&
13+
(stdenv.hostPlatform == stdenv.buildPlatform || stdenv.hostPlatform.isCygwin || stdenv.hostPlatform.isLinux || stdenv.hostPlatform.isWasi)
14+
, icuSupport ? false
15+
, icu
16+
, enableShared ? !stdenv.hostPlatform.isMinGW && !stdenv.hostPlatform.isStatic
17+
, enableStatic ? !enableShared
18+
, gnome
19+
, testers
20+
, enableHttp ? false
21+
, python ? null # Add this line to accept 'python' as an argument
22+
}:
23+
24+
let
25+
# If 'python' is provided, use it; otherwise use 'python3'
26+
pythonEnv = python3;
27+
in
28+
29+
stdenv.mkDerivation (finalAttrs: {
30+
pname = "libxml2";
31+
version = "2.13.3";
32+
33+
outputs = [ "bin" "dev" "out" "devdoc" ]
34+
++ lib.optional pythonSupport "py"
35+
++ lib.optional (enableStatic && enableShared) "static";
36+
outputMan = "bin";
37+
38+
src = fetchurl {
39+
url = "mirror://gnome/sources/libxml2/${lib.versions.majorMinor finalAttrs.version}/libxml2-${finalAttrs.version}.tar.xz";
40+
hash = "sha256-CAXXwYDPCcqtcWZsekWKdPBBVhpTKQJFTaUEfYOUgTg=";
41+
};
42+
43+
strictDeps = true;
44+
45+
nativeBuildInputs = [
46+
pkg-config
47+
autoreconfHook
48+
];
49+
50+
buildInputs = lib.optionals pythonSupport [
51+
pythonEnv
52+
ncurses
53+
];
54+
55+
propagatedBuildInputs = [
56+
findXMLCatalogs
57+
] ++ lib.optionals stdenv.isDarwin [
58+
libiconv
59+
] ++ lib.optionals icuSupport [
60+
icu
61+
];
62+
63+
configureFlags = [
64+
"--exec-prefix=${placeholder "dev"}"
65+
(lib.enableFeature enableStatic "static")
66+
(lib.enableFeature enableShared "shared")
67+
(lib.withFeature icuSupport "icu")
68+
(lib.withFeature pythonSupport "python")
69+
(lib.optionalString pythonSupport "PYTHON=${pythonEnv.pythonOnBuildForHost.interpreter}")
70+
] ++ lib.optional enableHttp "--with-http";
71+
72+
installFlags = lib.optionals pythonSupport [
73+
"pythondir=\"${placeholder "py"}/${pythonEnv.sitePackages}\""
74+
"pyexecdir=\"${placeholder "py"}/${pythonEnv.sitePackages}\""
75+
];
76+
77+
enableParallelBuilding = true;
78+
79+
doCheck =
80+
(stdenv.hostPlatform == stdenv.buildPlatform) &&
81+
stdenv.hostPlatform.libc != "musl";
82+
preCheck = lib.optional stdenv.isDarwin ''
83+
export DYLD_LIBRARY_PATH="$PWD/.libs:$DYLD_LIBRARY_PATH"
84+
'';
85+
86+
preConfigure = lib.optionalString (lib.versionAtLeast stdenv.hostPlatform.darwinMinVersion "11") ''
87+
MACOSX_DEPLOYMENT_TARGET=10.16
88+
'';
89+
90+
preInstall = lib.optionalString pythonSupport ''
91+
substituteInPlace python/libxml2mod.la --replace-fail "$dev/${pythonEnv.sitePackages}" "$py/${pythonEnv.sitePackages}"
92+
'';
93+
94+
postFixup = ''
95+
moveToOutput bin/xml2-config "$dev"
96+
moveToOutput lib/xml2Conf.sh "$dev"
97+
'' + lib.optionalString (enableStatic && enableShared) ''
98+
moveToOutput lib/libxml2.a "$static"
99+
'';
100+
101+
passthru = {
102+
inherit pythonSupport;
103+
104+
updateScript = gnome.updateScript {
105+
packageName = "libxml2";
106+
versionPolicy = "none";
107+
};
108+
tests = {
109+
pkg-config = testers.hasPkgConfigModules {
110+
package = finalAttrs.finalPackage;
111+
};
112+
};
113+
};
114+
115+
meta = with lib; {
116+
homepage = "https://gitlab.gnome.org/GNOME/libxml2";
117+
description = "XML parsing library for C";
118+
license = licenses.mit;
119+
platforms = platforms.all;
120+
maintainers = with maintainers; [ jtojnar ];
121+
pkgConfigModules = [ "libxml-2.0" ];
122+
};
123+
})

nix/postgresql/15.nix

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import ./generic.nix {
2+
version = "15.8";
3+
hash = "sha256-RANRX5pp7rPv68mPMLjGlhIr/fiV6Ss7I/W452nty2o=";
4+
}

nix/postgresql/16.nix

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import ./generic.nix {
2+
version = "16.4";
3+
hash = "sha256-lxdm1kWqc+k7nvTjvkQgG09FtUdwlbBJElQD+fM4bW8=";
4+
}

nix/postgresql/default.nix

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
self:
2+
let
3+
#adapted from the postgresql nixpkgs package
4+
versions = {
5+
postgresql_15 = ./15.nix;
6+
postgresql_16 = ./16.nix;
7+
};
8+
9+
mkAttributes = jitSupport:
10+
self.lib.mapAttrs' (version: path:
11+
let
12+
attrName = if jitSupport then "${version}_jit" else version;
13+
in
14+
self.lib.nameValuePair attrName (import path {
15+
inherit jitSupport self;
16+
})
17+
) versions;
18+
19+
in
20+
# variations without and with JIT
21+
(mkAttributes false) // (mkAttributes true)

0 commit comments

Comments
 (0)