How to load postgreSQL plugins without service module

i have nix-2.0.4 + postgresql-10.4 install on readhat 7 server.
but the directory /nix/store/zzrphwnp8kzv4s5r4z1nqzn8hbnlsm7b-postgresql-10.4/share/extension/ is read-only filesystem, i can’t copy the plugin into it.

i look into the service module solution, it use override to solve it. but i have no root rights, so what’s the right way to do it under this situation.

it seems i can build a postgresqlAnPlugins package, then copy postgres package and extension into it?
how can i implement in stdenv.mkDerivation? can someone offer me an example?

1 Like

This is untested, you can take the expression from the module and save it to a file like this:

with import <nixpkgs> {}:
  pg = postgres
pkgs.buildEnv {
      name = "postgresql-and-plugins-${(builtins.parseDrvName}";
      paths = [ pg pg.lib ];
      buildInputs = [ pkgs.makeWrapper ];
      postBuild =
          mkdir -p $out/bin
          rm $out/bin/{pg_config,postgres,pg_ctl}
          cp --target-directory=$out/bin ${pg}/bin/{postgres,pg_config,pg_ctl}
          wrapProgram $out/bin/postgres --set NIX_PGLIBDIR $out/lib

This can be build with nix-build and in the resulting result directory should be a wrapped postgres.

1 Like

You might be able to write a module with user systemd services to run postgresql as a user without needing privileges with: GitHub - nix-community/home-manager: Manage a user environment using Nix [maintainer=@rycee]

I was investigating the same thing and discovered that there’s a passthru on postgresql called withPackages that lets you do this easily. For example to build a version with cstore_fdw (obviously not what you’d do in production but it demonstrates it):

$ nix-build -E '(import <nixpkgs> {}).postgresql_9_6.withPackages (pkgs: [pkgs.cstore_fdw])'
$ ./result/bin/initdb -D db
$ echo "shared_preload_libraries = 'cstore_fdw'" >> db/postgresql.conf
$ ./result/bin/pg_ctl -D db start -o '-p 9000'
1 Like


i can write service module by extend home-manager with nix-darwin inner support now.

it’s very convenient to extend home-manager to support on mac and linux platform at the same time.