feat(nixos): postgresql: +settings script
This commit is contained in:
@@ -31,9 +31,40 @@ in {
|
|||||||
type = lib.types.attrsOf lib.types.str;
|
type = lib.types.attrsOf lib.types.str;
|
||||||
default = {};
|
default = {};
|
||||||
};
|
};
|
||||||
|
script = lib.mkOption {
|
||||||
|
type = with lib; types.nullOr types.path;
|
||||||
|
default = null;
|
||||||
|
example = lib.literalExpression ''
|
||||||
|
pkgs.writeText "init-sql-script" '''
|
||||||
|
alter user postgres with password 'myPassword';
|
||||||
|
''';'';
|
||||||
|
|
||||||
|
description = ''
|
||||||
|
A file containing SQL statements to execute on stratup or any time you change it.
|
||||||
|
'';
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
config = lib.mkIf cfg.enable {
|
config = lib.mkIf cfg.enable {
|
||||||
|
systemd.services.postgresql-script= lib.mkIf (cfg.script != null) {
|
||||||
|
description = "Some postgresql settings";
|
||||||
|
after = [ "postgresql.service" ];
|
||||||
|
wants = [ "postgresql.service" ];
|
||||||
|
serviceConfig = {
|
||||||
|
Type = "oneshot";
|
||||||
|
ExecStart = "${pkgs.dash}/bin/dash ${pkgs.writeText "sql-script" ''
|
||||||
|
#!/${pkgs.dash}/bin/dash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
alias psql='${cfg.package}/bin/psql -v ON_ERROR_STOP=1 -p "${builtins.toString cfg.port}" -U postgres -d postgres'
|
||||||
|
|
||||||
|
${builtins.readFile cfg.script}
|
||||||
|
''}";
|
||||||
|
};
|
||||||
|
path = [ ];
|
||||||
|
wantedBy = [ "multi-user.target" ];
|
||||||
|
};
|
||||||
systemd.services.postgresql.environment = cfg.environment;
|
systemd.services.postgresql.environment = cfg.environment;
|
||||||
services.postgresql = {
|
services.postgresql = {
|
||||||
settings.shared_preload_libraries =
|
settings.shared_preload_libraries =
|
||||||
|
|||||||
Reference in New Issue
Block a user