tweag / nix-hour

Questions for the weekly Nix Hour
MIT License
78 stars 3 forks source link

Adding an extension for Postgres #10

Closed idontgetoutmuch closed 10 months ago

idontgetoutmuch commented 1 year ago

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 https://github.com/NixOS/nixpkgs/pull/208250.

I have several questions:

{ 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 commented 1 year ago

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

infinisil commented 10 months ago

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