How to load postgreSQL plugins without service module


#1

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?


#2

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

with import <nixpkgs> {}:
let
  pg = postgres
in
pkgs.buildEnv {
      name = "postgresql-and-plugins-${(builtins.parseDrvName pg.name).version}";
      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.


#3

You might be able to write a module with user systemd services to run postgresql as a user without needing privileges with: https://github.com/rycee/home-manager