Unverified Commit 813e7336 authored by Wolfgang Walther's avatar Wolfgang Walther
Browse files

nixos/pgbackrest: add commands option for specific settings

These settings are documented here:
https://pgbackrest.org/configuration.html

It's useful to be able to define specific configuration for separate
commands, for example for fixing a failing test in the next update.
parent e6f5ebc8
Loading
Loading
Loading
Loading
+52 −1
Original line number Diff line number Diff line
@@ -55,6 +55,9 @@ let
  fullConfig = {
    global = normalize (cfg.settings // flattenWithIndex cfg.repos "repo");
  }
  // lib.mapAttrs' (
    cmd: settings: lib.nameValuePair "global:${cmd}" (normalize settings)
  ) cfg.commands
  // lib.mapAttrs (
    _: cfg': normalize (cfg'.settings // flattenWithIndex cfg'.instances "pg")
  ) cfg.stanzas;
@@ -95,7 +98,6 @@ in
  };

  # TODO: Add enableServer option and corresponding pgBackRest TLS server service.
  # TODO: Allow command-specific options
  # TODO: Write wrapper around pgbackrest to turn --repo=<name> into --repo=<number>
  # The following two are dependent on improvements upstream:
  #   https://github.com/pgbackrest/pgbackrest/issues/2621
@@ -328,6 +330,55 @@ in
        }
      '';
    };

    commands =
      lib.genAttrs
        [
          # List of commands from https://pgbackrest.org/command.html:
          "annotate"
          "archive-get"
          "archive-push"
          "backup"
          "check"
          "expire"
          "help"
          "info"
          "repo-get"
          "repo-ls"
          "restore"
          "server"
          "server-ping"
          "stanza-create"
          "stanza-delete"
          "stanza-upgrade"
          "start"
          "stop"
          "verify"
          "version"
        ]
        (
          command:
          lib.mkOption {
            type = lib.types.submodule {
              freeformType = settingsType;

              # The following options are not fully supported / tested, yet, but point to files with secrets.
              # Users can already set those options, but we'll force non-store paths.
              options.tls-server-cert-file = secretPathOption;
              options.tls-server-key-file = secretPathOption;
            };
            default = { };
            description = ''
              Options for the '${command}' command.

              An attribute set of options as described in:
              <https://pgbackrest.org/configuration.html>

              All globally available options, i.e. all except stanza options, can be used.
              Repository options should be set via [`repos`](#opt-services.pgbackrest.repos) instead.
            '';
          }
        );
  };

  config = lib.mkIf cfg.enable (