Commit 7cee78fc authored by Profpatsch's avatar Profpatsch

containers/postgres: rename variables & remove unused code

parent 17b4666b
......@@ -2,7 +2,7 @@
let
cfg = config.org.techcultivation.deploy.database;
postgresConnectionData = {
connectionData = {
Host = "";
Port = 5432;
DbName = "sangha";
......@@ -14,6 +14,10 @@ let
sanghaDatabaseLocale = "en_US.UTF-8";
# TODO: use pgtune(1) for full deployment setup
# TODO: max_connections & shared_buffers
# set by initdb, should be modifiable
# see https://www.postgresql.org/docs/9.1/static/runtime-config-resource.html
# and https://www.postgresql.org/docs/9.1/static/runtime-config-connection.html
sanghaPostgresConfig =
let
l = sanghaDatabaseLocale;
......@@ -34,18 +38,11 @@ let
lc_time = l;
};
sangha = pkgs.sangha;
sanghaDatabaseInit = with postgresConnectionData;
pkgs.writeText "sangha-create-db.sql" ''
CREATE DATABASE ${DbName};
CREATE USER ${User} WITH PASSWORD '${Password}';
GRANT ALL PRIVILEGES ON DATABASE ${DbName} TO ${User};
'';
localeFiles = pkgs.glibcLocales.override {
locales = [ (sanghaDatabaseLocale + "/UTF-8") ];
allLocales = false;
};
prependPrefix = prefix: drv: pkgs.runCommand "${drv.name}-prefixed" {} ''
new="$out/${prefix}"
mkdir -p $(dirname "$new")
......@@ -58,11 +55,18 @@ let
let sanghaConfig = pkgs.runCommand "sangha.conf" {} ''
# copy sangha configuration with correct connection data
${lib.getBin pkgs.jq}/bin/jq '.Connections.PostgreSQLConnection *= ${
lib.generators.toJSON {} postgresConnectionData
lib.generators.toJSON {} connectionData
}' \
${sangha.src}/config.example.json \
${pkgs.sangha.src}/config.example.json \
> $out
'';
sanghaCreateDb = with connectionData;
pkgs.writeText "sangha-create-db.sql" ''
CREATE DATABASE ${DbName};
CREATE USER ${User} WITH PASSWORD '${Password}';
GRANT ALL PRIVILEGES ON DATABASE ${DbName} TO ${User};
'';
in pkgs.runCommand "sangha-db-template" {
nativeBuildInputs = [ pkgs.postgresql localeFiles ];
passthru = { inherit sanghaConfig; };
......@@ -83,15 +87,15 @@ let
pg_ctl start -w
# init database
psql --file=${sanghaDatabaseInit} --username=postgres
psql --file=${sanghaCreateDb} --username=postgres
# init database tables
# TODO: use command line flag of sangha (buggy)
cp ${sanghaConfig} ./config.json
${lib.getBin sangha}/bin/sangha database init
${lib.getBin pkgs.sangha}/bin/sangha database init
# insert mock data
psql --file=${sangha.src}/mocks/projects.sql --username=postgres sangha
psql --file=${pkgs.sangha.src}/mocks/projects.sql --username=postgres sangha
pg_ctl stop -w
'';
......@@ -101,28 +105,8 @@ in {
enable = lib.mkEnableOption "database container";
buildDockerImage = lib.mkEnableOption "database container docker image";
# TODO: here? naming?
# buildInitScript = lib.mkOption {
# type = with lib.types; lines;
# example = "
# description = ''
# Init scripts to be run when building the database deploy.
# '';
# TODO: max_connections & shared_buffers
# set by initdb, should be modifiable
# see https://www.postgresql.org/docs/9.1/static/runtime-config-resource.html
# and https://www.postgresql.org/docs/9.1/static/runtime-config-connection.html
};
# options.passthru = lib.mkOption {
# type = with lib.types; attrsOf unspecified;
# default = {};
# description = ''
# Free-form attrset to pass stuff through the build.
# '';
# };
options.generated.dockerImages = lib.mkOption {
type = with lib.types; attrsOf package;
default = {};
......@@ -135,10 +119,7 @@ in {
config =
let
nixosConfig = {
# services.postgresql = {
# enable = true;
# initialScript = postgresInit;
# };
# TODO
passthru = postgresInitDatabase;
};
......@@ -158,13 +139,14 @@ in {
Env = [
"PGDATA=${dbDir}"
];
ExposedPorts."${toString postgresConnectionData.Port}/tcp" = {};
ExposedPorts."${toString connectionData.Port}/tcp" = {};
Volumes."${dbDir}" = {};
};
runAsRoot = ''
${pkgs.stdenv.shell}
${shadowSetup}
# some needed system structure
umask 000
mkdir /tmp
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment