summaryrefslogtreecommitdiff
path: root/modules/nixfiles/postgresql.nix
blob: 23623af0d379d0ed9c1bbf1984553d7f6bafc47f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
{
  config,
  lib,
  pkgs,
  this,
  ...
}:
with lib; let
  cfg = config.nixfiles.modules.postgresql;
in {
  options.nixfiles.modules.postgresql.enable =
    mkEnableOption "Whether to enable PostgeSQL.";

  config = mkIf cfg.enable {
    hm = {
      home.sessionVariables.PSQLRC = config.hm.xdg.configFile."psqlrc".target;

      xdg.configFile."psqlrc".text = ''
        \set QUIET 1

        \timing
        \x auto
        \pset null '[NULL]'
        \set PROMPT1 '%[%033[1m%]%M %n@%/%R%[%033[0m%]% λ '
        \set PROMPT2 '    … > '
        \set VERBOSITY verbose
        \set HISTCONTROL ignoredups
        \set HISTFILE /dev/null

        \unset QUIET
      '';
    };

    services = {
      postgresql = {
        enable = true;
        package = pkgs.postgresql_14;
        # TODO Test if this is still required.
        authentication = ''
          local all all trust
          host all all 127.0.0.1/32 trust
          host all all ::1/128 trust
        '';
      };

      prometheus.exporters.postgres = {
        enable = true;
        listenAddress = mkDefault this.wireguard.ipv4.address;
        port = mkDefault 9187;
      };
    };
  };
}