mirror of
https://github.com/LnL7/nix-darwin.git
synced 2025-03-05 08:17:01 +00:00
postgresql: init service
This commit is contained in:
parent
2eec909faf
commit
acd0fee357
2 changed files with 85 additions and 0 deletions
|
@ -44,6 +44,7 @@ let
|
|||
./modules/services/mopidy.nix
|
||||
./modules/services/nix-daemon.nix
|
||||
./modules/services/nix-gc.nix
|
||||
./modules/services/postgresql
|
||||
./modules/programs/bash.nix
|
||||
./modules/programs/fish.nix
|
||||
./modules/programs/man.nix
|
||||
|
|
84
modules/services/postgresql/default.nix
Normal file
84
modules/services/postgresql/default.nix
Normal file
|
@ -0,0 +1,84 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
let
|
||||
cfg = config.services.postgresql;
|
||||
|
||||
configFile = pkgs.writeText "postgresql.conf"
|
||||
''
|
||||
log_destination = 'stderr'
|
||||
port = ${toString cfg.port}
|
||||
${cfg.extraConfig}
|
||||
'';
|
||||
in
|
||||
|
||||
{
|
||||
options = {
|
||||
services.postgresql = {
|
||||
enable = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = ''Whether to run PostgreSQL.'';
|
||||
};
|
||||
|
||||
package = mkOption {
|
||||
type = types.package;
|
||||
default = pkgs.postgresql96;
|
||||
defaultText = "pkgs.postgresql96";
|
||||
description = ''PostgreSQL package to use.'';
|
||||
};
|
||||
|
||||
port = mkOption {
|
||||
type = types.int;
|
||||
default = 5432;
|
||||
description = ''The port on which PostgreSQL listens.'';
|
||||
};
|
||||
|
||||
dataDir = mkOption {
|
||||
type = types.path;
|
||||
default = "/var/lib/postgresql";
|
||||
example = "/var/lib/postgresql/9.6";
|
||||
description = ''Data directory for PostgreSQL.'';
|
||||
};
|
||||
|
||||
enableTCPIP = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = ''
|
||||
Whether PostgreSQL should listen on all network interfaces.
|
||||
If disabled, the database can only be accessed via its Unix
|
||||
domain socket or via TCP connections to localhost.
|
||||
'';
|
||||
};
|
||||
|
||||
extraConfig = mkOption {
|
||||
type = types.lines;
|
||||
default = "";
|
||||
description = "Additional text to be appended to <filename>postgresql.conf</filename>.";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
|
||||
environment.systemPackages = [ cfg.package ];
|
||||
|
||||
launchd.user.agents.postgresql =
|
||||
{ path = [ cfg.package ];
|
||||
script = ''
|
||||
# Initialise the database.
|
||||
if ! test -e ${cfg.dataDir}/PG_VERSION; then
|
||||
initdb -U postgres -D ${cfg.dataDir}
|
||||
fi
|
||||
ln -sfn ${configFile} ${cfg.dataDir}/postgresql.conf
|
||||
|
||||
exec ${cfg.package}/bin/postgres -D ${cfg.dataDir} ${optionalString cfg.enableTCPIP "-i"}
|
||||
'';
|
||||
|
||||
serviceConfig.KeepAlive = true;
|
||||
serviceConfig.RunAtLoad = true;
|
||||
};
|
||||
|
||||
};
|
||||
}
|
Loading…
Add table
Reference in a new issue