101 lines
2.5 KiB
Nix
101 lines
2.5 KiB
Nix
{ pkgs, ... }:
|
|
let
|
|
postgresql = pkgs.postgresql.overrideAttrs (oldAttrs: {
|
|
patches = oldAttrs.patches or [ ] ++ [ ../postgresql/allow-root.patch ];
|
|
});
|
|
|
|
# https://github.com/NixOS/nixpkgs/blob/master/pkgs/servers/sql/postgresql/generic.nix
|
|
postgresqlVectorchord =
|
|
let
|
|
installedExtensions = with postgresql.pkgs; [
|
|
pgvector
|
|
vectorchord
|
|
];
|
|
|
|
finalPackage = pkgs.buildEnv {
|
|
name = "${postgresql.pname}-vectorchord";
|
|
|
|
paths = installedExtensions ++ [
|
|
postgresql
|
|
postgresql.man
|
|
];
|
|
|
|
pathsToLink = [
|
|
"/"
|
|
"/bin"
|
|
"/share/postgresql/extension"
|
|
"/share/postgresql/timezonesets"
|
|
"/share/postgresql/tsearch_data"
|
|
];
|
|
|
|
nativeBuildInputs = with pkgs; [ makeBinaryWrapper ];
|
|
|
|
postBuild =
|
|
let
|
|
args = pkgs.lib.concatMap (ext: ext.wrapperArgs or [ ]) installedExtensions;
|
|
in
|
|
''
|
|
wrapProgram "$out/bin/postgres" ${pkgs.lib.concatStringsSep " " args}
|
|
'';
|
|
|
|
passthru = {
|
|
inherit installedExtensions;
|
|
inherit (postgresql) pkgs psqlSchema version;
|
|
|
|
pg_config = postgresql.pg_config.override {
|
|
outputs = {
|
|
out = finalPackage;
|
|
man = finalPackage;
|
|
};
|
|
};
|
|
};
|
|
};
|
|
in
|
|
finalPackage;
|
|
|
|
entrypoint = pkgs.writeTextFile {
|
|
name = "entrypoint";
|
|
executable = true;
|
|
destination = "/bin/entrypoint";
|
|
text = builtins.readFile ../postgresql/entrypoint.sh;
|
|
};
|
|
|
|
init = pkgs.writeTextDir "/etc/postgresql/init.sh" (builtins.readFile ./init.sh);
|
|
in
|
|
pkgs.dockerTools.buildImage {
|
|
name = "postgresql-vectorchord";
|
|
fromImage = pkgs.docker-image-base;
|
|
|
|
copyToRoot = pkgs.buildEnv {
|
|
name = "root";
|
|
paths = [
|
|
entrypoint
|
|
postgresqlVectorchord
|
|
init
|
|
];
|
|
pathsToLink = [
|
|
"/bin"
|
|
"/lib"
|
|
"/share"
|
|
];
|
|
};
|
|
|
|
runAsRoot = ''
|
|
mkdir -p /etc/postgresql /run/postgresql
|
|
cp ${postgresql}/share/postgresql/postgresql.conf.sample /etc/postgresql/postgresql.conf
|
|
${pkgs.gnused}/bin/sed -ri "s!^#?(listen_addresses)\s*=\s*\S+.*!\1 = '*'!" /etc/postgresql/postgresql.conf
|
|
${pkgs.gnused}/bin/sed -ri "s/^#shared_preload_libraries = '''/shared_preload_libraries = 'vchord'/" /etc/postgresql/postgresql.conf
|
|
'';
|
|
|
|
config = {
|
|
Entrypoint = [ "entrypoint" ];
|
|
ExposedPorts = {
|
|
"5432/tcp" = { };
|
|
};
|
|
WorkingDir = "/var/lib/postgresql";
|
|
Volumes = {
|
|
"/var/lib/postgresql/data" = { };
|
|
};
|
|
};
|
|
}
|