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

Adding an extension for Postgres #10

Closed
idontgetoutmuch opened this issue Jan 4, 2023 · 2 comments
Closed

Adding an extension for Postgres #10

idontgetoutmuch opened this issue Jan 4, 2023 · 2 comments

Comments

@idontgetoutmuch
Copy link
Member

idontgetoutmuch commented Jan 4, 2023

I think I answered my own question but it may still be of interest - I wanted to add audits to a postgres server but the https://github.com/pgaudit/pgaudit extension wasn’t available so I wrote this NixOS/nixpkgs#208250.

I have several questions:

  • It wasn’t clear to me which arguments(?) were needed to build the package other than running the nix and getting an error. Even then it wasn’t obvious I needed kerberos: error: Function called without required argument "krb" at /Users/dom/nixpkgs/pkgs/servers/sql/postgresql/ext/pgaudit.nix:1, did you mean "arb", "grb" or "k3b"?

  • https://github.com/NixOS/nixpkgs/pull/208250/files#diff-b14917f724238c95c3cbc09f6d71504d240da722d61661acfd00a2f146f128d1R21 I didn’t add this at first but corrected the error. How would I know to add it?

  • The PR always asks for lots of information and I have no idea how to answer. I think I should have named my PR or my commit message differently at least but which one?

  • I seem to have to have my own copy of nixpkgs to test the PR. Obviously I need that at the end but do I really have to build everything when I am just experimenting? Is there a way of testing my derivation(?) with my current set of packages?

  • I am testing / using my derivation as below but is this a good way of using it? Caveat: I know little about postgres.

{ nixpkgs ? import <nixpkgs> { } }:

nixpkgs.stdenv.mkDerivation {
  name = "test pgaudit";

  buildInputs = [
    nixpkgs.libintlOrEmpty
    (nixpkgs.postgresql_13.withPackages (p: [ p.pgaudit ]))
    nixpkgs.darwin.apple_sdk.frameworks.Cocoa
  ];

  postgresConf =
  nixpkgs.writeText "postgresql.conf"
    ''
      # Add Custom Settings
      logging_collector = on
      log_directory = 'pg_log'
      shared_preload_libraries = 'pgaudit'
    '';

  # ENV Variables
  PGDATA = "${toString ./.}/.pg";

  # Post Shell Hook
  shellHook = ''
    echo "Using ${nixpkgs.postgresql_13.name}."

    # Setup: other env variables
    export PGHOST="$PGDATA"
    # Setup: DB
    [ ! -d $PGDATA ] && pg_ctl initdb -o "-U postgres" && cat "$postgresConf" >> $PGDATA/postgresql.conf
    pg_ctl -o "-p 5555 -k $PGDATA" start
    alias fin="pg_ctl stop && exit"
    alias pg="psql -p 5555 -U postgres"
  '';
}
@infinisil
Copy link
Member

We looked at some of these questions in Nix Hour #21 :)

@infinisil
Copy link
Member

Closing for now, let me know if you have questions that aren't addressed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants