2020-04-24 23:36:52 +00:00
|
|
|
{ lib, pkgs, config, ... } :
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.pgmanage;
|
|
|
|
|
|
|
|
confFile = pkgs.writeTextFile {
|
|
|
|
name = "pgmanage.conf";
|
|
|
|
text = ''
|
|
|
|
connection_file = ${pgmanageConnectionsFile}
|
|
|
|
|
|
|
|
allow_custom_connections = ${builtins.toJSON cfg.allowCustomConnections}
|
|
|
|
|
|
|
|
pgmanage_port = ${toString cfg.port}
|
|
|
|
|
|
|
|
super_only = ${builtins.toJSON cfg.superOnly}
|
|
|
|
|
|
|
|
${optionalString (cfg.loginGroup != null) "login_group = ${cfg.loginGroup}"}
|
|
|
|
|
|
|
|
login_timeout = ${toString cfg.loginTimeout}
|
|
|
|
|
|
|
|
web_root = ${cfg.package}/etc/pgmanage/web_root
|
|
|
|
|
|
|
|
sql_root = ${cfg.sqlRoot}
|
|
|
|
|
|
|
|
${optionalString (cfg.tls != null) ''
|
|
|
|
tls_cert = ${cfg.tls.cert}
|
|
|
|
tls_key = ${cfg.tls.key}
|
|
|
|
''}
|
|
|
|
|
|
|
|
log_level = ${cfg.logLevel}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
pgmanageConnectionsFile = pkgs.writeTextFile {
|
|
|
|
name = "pgmanage-connections.conf";
|
|
|
|
text = concatStringsSep "\n"
|
|
|
|
(mapAttrsToList (name : conn : "${name}: ${conn}") cfg.connections);
|
|
|
|
};
|
|
|
|
|
|
|
|
pgmanage = "pgmanage";
|
|
|
|
|
|
|
|
in {
|
|
|
|
|
|
|
|
options.services.pgmanage = {
|
2022-09-09 14:08:57 +00:00
|
|
|
enable = mkEnableOption (lib.mdDoc "PostgreSQL Administration for the web");
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2024-01-02 11:29:13 +00:00
|
|
|
package = mkPackageOption pkgs "pgmanage" { };
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
connections = mkOption {
|
|
|
|
type = types.attrsOf types.str;
|
|
|
|
default = {};
|
|
|
|
example = {
|
|
|
|
nuc-server = "hostaddr=192.168.0.100 port=5432 dbname=postgres";
|
|
|
|
mini-server = "hostaddr=127.0.0.1 port=5432 dbname=postgres sslmode=require";
|
|
|
|
};
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
pgmanage requires at least one PostgreSQL server be defined.
|
2022-08-12 12:06:08 +00:00
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
Detailed information about PostgreSQL connection strings is available at:
|
2023-11-16 04:20:00 +00:00
|
|
|
<https://www.postgresql.org/docs/current/libpq-connect.html>
|
2022-08-12 12:06:08 +00:00
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
Note that you should not specify your user name or password. That
|
|
|
|
information will be entered on the login screen. If you specify a
|
|
|
|
username or password, it will be removed by pgmanage before attempting to
|
|
|
|
connect to a database.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
allowCustomConnections = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
This tells pgmanage whether or not to allow anyone to use a custom
|
|
|
|
connection from the login screen.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
2022-11-21 17:40:18 +00:00
|
|
|
type = types.port;
|
2020-04-24 23:36:52 +00:00
|
|
|
default = 8080;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
This tells pgmanage what port to listen on for browser requests.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
localOnly = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
This tells pgmanage whether or not to set the listening socket to local
|
|
|
|
addresses only.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
superOnly = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
This tells pgmanage whether or not to only allow super users to
|
|
|
|
login. The recommended value is true and will restrict users who are not
|
|
|
|
super users from logging in to any PostgreSQL instance through
|
|
|
|
pgmanage. Note that a connection will be made to PostgreSQL in order to
|
|
|
|
test if the user is a superuser.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
loginGroup = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
This tells pgmanage to only allow users in a certain PostgreSQL group to
|
|
|
|
login to pgmanage. Note that a connection will be made to PostgreSQL in
|
|
|
|
order to test if the user is a member of the login group.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
loginTimeout = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 3600;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Number of seconds of inactivity before user is automatically logged
|
|
|
|
out.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
sqlRoot = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "/var/lib/pgmanage";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
This tells pgmanage where to put the SQL file history. All tabs are saved
|
|
|
|
to this location so that if you get disconnected from pgmanage you
|
|
|
|
don't lose your work.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
tls = mkOption {
|
|
|
|
type = types.nullOr (types.submodule {
|
|
|
|
options = {
|
|
|
|
cert = mkOption {
|
|
|
|
type = types.str;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "TLS certificate";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
key = mkOption {
|
|
|
|
type = types.str;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "TLS key";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|
|
|
|
default = null;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
These options tell pgmanage where the TLS Certificate and Key files
|
|
|
|
reside. If you use these options then you'll only be able to access
|
|
|
|
pgmanage through a secure TLS connection. These options are only
|
|
|
|
necessary if you wish to connect directly to pgmanage using a secure TLS
|
|
|
|
connection. As an alternative, you can set up pgmanage in a reverse proxy
|
|
|
|
configuration. This allows your web server to terminate the secure
|
|
|
|
connection and pass on the request to pgmanage. You can find help to set
|
|
|
|
up this configuration in:
|
2022-08-12 12:06:08 +00:00
|
|
|
<https://github.com/pgManage/pgManage/blob/master/INSTALL_NGINX.md>
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
logLevel = mkOption {
|
|
|
|
type = types.enum ["error" "warn" "notice" "info"];
|
|
|
|
default = "error";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Verbosity of logs
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
systemd.services.pgmanage = {
|
|
|
|
description = "pgmanage - PostgreSQL Administration for the web";
|
|
|
|
wants = [ "postgresql.service" ];
|
|
|
|
after = [ "postgresql.service" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
serviceConfig = {
|
|
|
|
User = pgmanage;
|
|
|
|
Group = pgmanage;
|
2023-10-09 19:29:22 +00:00
|
|
|
ExecStart = "${cfg.package}/sbin/pgmanage -c ${confFile}" +
|
2020-04-24 23:36:52 +00:00
|
|
|
optionalString cfg.localOnly " --local-only=true";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
users = {
|
|
|
|
users.${pgmanage} = {
|
|
|
|
name = pgmanage;
|
|
|
|
group = pgmanage;
|
|
|
|
home = cfg.sqlRoot;
|
|
|
|
createHome = true;
|
2021-04-15 00:37:46 +00:00
|
|
|
isSystemUser = true;
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
groups.${pgmanage} = {
|
|
|
|
name = pgmanage;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|