nixos/services.pgmanage: remove with lib;

This commit is contained in:
Felix Buehler 2024-08-27 20:43:01 +02:00
parent 6bbc3df0dd
commit 18c0ca5714

View File

@ -1,7 +1,4 @@
{ lib, pkgs, config, ... } : { lib, pkgs, config, ... } :
with lib;
let let
cfg = config.services.pgmanage; cfg = config.services.pgmanage;
@ -16,7 +13,7 @@ let
super_only = ${builtins.toJSON cfg.superOnly} super_only = ${builtins.toJSON cfg.superOnly}
${optionalString (cfg.loginGroup != null) "login_group = ${cfg.loginGroup}"} ${lib.optionalString (cfg.loginGroup != null) "login_group = ${cfg.loginGroup}"}
login_timeout = ${toString cfg.loginTimeout} login_timeout = ${toString cfg.loginTimeout}
@ -24,7 +21,7 @@ let
sql_root = ${cfg.sqlRoot} sql_root = ${cfg.sqlRoot}
${optionalString (cfg.tls != null) '' ${lib.optionalString (cfg.tls != null) ''
tls_cert = ${cfg.tls.cert} tls_cert = ${cfg.tls.cert}
tls_key = ${cfg.tls.key} tls_key = ${cfg.tls.key}
''} ''}
@ -35,8 +32,8 @@ let
pgmanageConnectionsFile = pkgs.writeTextFile { pgmanageConnectionsFile = pkgs.writeTextFile {
name = "pgmanage-connections.conf"; name = "pgmanage-connections.conf";
text = concatStringsSep "\n" text = lib.concatStringsSep "\n"
(mapAttrsToList (name : conn : "${name}: ${conn}") cfg.connections); (lib.mapAttrsToList (name : conn : "${name}: ${conn}") cfg.connections);
}; };
pgmanage = "pgmanage"; pgmanage = "pgmanage";
@ -44,12 +41,12 @@ let
in { in {
options.services.pgmanage = { options.services.pgmanage = {
enable = mkEnableOption "PostgreSQL Administration for the web"; enable = lib.mkEnableOption "PostgreSQL Administration for the web";
package = mkPackageOption pkgs "pgmanage" { }; package = lib.mkPackageOption pkgs "pgmanage" { };
connections = mkOption { connections = lib.mkOption {
type = types.attrsOf types.str; type = lib.types.attrsOf lib.types.str;
default = {}; default = {};
example = { example = {
nuc-server = "hostaddr=192.168.0.100 port=5432 dbname=postgres"; nuc-server = "hostaddr=192.168.0.100 port=5432 dbname=postgres";
@ -68,8 +65,8 @@ in {
''; '';
}; };
allowCustomConnections = mkOption { allowCustomConnections = lib.mkOption {
type = types.bool; type = lib.types.bool;
default = false; default = false;
description = '' description = ''
This tells pgmanage whether or not to allow anyone to use a custom This tells pgmanage whether or not to allow anyone to use a custom
@ -77,16 +74,16 @@ in {
''; '';
}; };
port = mkOption { port = lib.mkOption {
type = types.port; type = lib.types.port;
default = 8080; default = 8080;
description = '' description = ''
This tells pgmanage what port to listen on for browser requests. This tells pgmanage what port to listen on for browser requests.
''; '';
}; };
localOnly = mkOption { localOnly = lib.mkOption {
type = types.bool; type = lib.types.bool;
default = true; default = true;
description = '' description = ''
This tells pgmanage whether or not to set the listening socket to local This tells pgmanage whether or not to set the listening socket to local
@ -94,8 +91,8 @@ in {
''; '';
}; };
superOnly = mkOption { superOnly = lib.mkOption {
type = types.bool; type = lib.types.bool;
default = true; default = true;
description = '' description = ''
This tells pgmanage whether or not to only allow super users to This tells pgmanage whether or not to only allow super users to
@ -106,8 +103,8 @@ in {
''; '';
}; };
loginGroup = mkOption { loginGroup = lib.mkOption {
type = types.nullOr types.str; type = lib.types.nullOr lib.types.str;
default = null; default = null;
description = '' description = ''
This tells pgmanage to only allow users in a certain PostgreSQL group to This tells pgmanage to only allow users in a certain PostgreSQL group to
@ -116,8 +113,8 @@ in {
''; '';
}; };
loginTimeout = mkOption { loginTimeout = lib.mkOption {
type = types.int; type = lib.types.int;
default = 3600; default = 3600;
description = '' description = ''
Number of seconds of inactivity before user is automatically logged Number of seconds of inactivity before user is automatically logged
@ -125,8 +122,8 @@ in {
''; '';
}; };
sqlRoot = mkOption { sqlRoot = lib.mkOption {
type = types.str; type = lib.types.str;
default = "/var/lib/pgmanage"; default = "/var/lib/pgmanage";
description = '' description = ''
This tells pgmanage where to put the SQL file history. All tabs are saved This tells pgmanage where to put the SQL file history. All tabs are saved
@ -135,15 +132,15 @@ in {
''; '';
}; };
tls = mkOption { tls = lib.mkOption {
type = types.nullOr (types.submodule { type = lib.types.nullOr (lib.types.submodule {
options = { options = {
cert = mkOption { cert = lib.mkOption {
type = types.str; type = lib.types.str;
description = "TLS certificate"; description = "TLS certificate";
}; };
key = mkOption { key = lib.mkOption {
type = types.str; type = lib.types.str;
description = "TLS key"; description = "TLS key";
}; };
}; };
@ -162,8 +159,8 @@ in {
''; '';
}; };
logLevel = mkOption { logLevel = lib.mkOption {
type = types.enum ["error" "warn" "notice" "info"]; type = lib.types.enum ["error" "warn" "notice" "info"];
default = "error"; default = "error";
description = '' description = ''
Verbosity of logs Verbosity of logs
@ -171,7 +168,7 @@ in {
}; };
}; };
config = mkIf cfg.enable { config = lib.mkIf cfg.enable {
systemd.services.pgmanage = { systemd.services.pgmanage = {
description = "pgmanage - PostgreSQL Administration for the web"; description = "pgmanage - PostgreSQL Administration for the web";
wants = [ "postgresql.service" ]; wants = [ "postgresql.service" ];
@ -181,7 +178,7 @@ in {
User = pgmanage; User = pgmanage;
Group = pgmanage; Group = pgmanage;
ExecStart = "${cfg.package}/sbin/pgmanage -c ${confFile}" + ExecStart = "${cfg.package}/sbin/pgmanage -c ${confFile}" +
optionalString cfg.localOnly " --local-only=true"; lib.optionalString cfg.localOnly " --local-only=true";
}; };
}; };
users = { users = {