Allow psotgresql database to be switched

This commit is contained in:
niten 2023-06-22 18:06:14 -07:00
parent 93bc54ec67
commit 2720ce9be9
3 changed files with 63 additions and 47 deletions

View File

@ -226,7 +226,8 @@ in {
cp -f ${props-file} ${stateDir}/server.properties cp -f ${props-file} ${stateDir}/server.properties
cp -f ${eula-file} ${stateDir}/eula.txt cp -f ${eula-file} ${stateDir}/eula.txt
mkdir -p ${stateDir}/plugins mkdir -p ${stateDir}/plugins
cp -f ${witchcraft-plugin} ${stateDir}/plugins/witchcraft-plugin.jar # Version not working...
# cp -f ${witchcraft-plugin} ${stateDir}/plugins/witchcraft-plugin.jar
chmod u+w ${stateDir}/server.properties chmod u+w ${stateDir}/server.properties
''; '';

View File

@ -151,6 +151,12 @@ in {
options.fudo.postgresql = with types; { options.fudo.postgresql = with types; {
enable = mkEnableOption "Fudo PostgreSQL Server"; enable = mkEnableOption "Fudo PostgreSQL Server";
package = mkOption {
type = package;
description = "Which package to use for Postgresql server.";
default = pkgs.postgresql_11_gssapi;
};
ssl-private-key = mkOption { ssl-private-key = mkOption {
type = nullOr str; type = nullOr str;
description = "Location of the server SSL private key."; description = "Location of the server SSL private key.";
@ -247,7 +253,7 @@ in {
networking.firewall.allowedTCPPorts = [ 5432 ]; networking.firewall.allowedTCPPorts = [ 5432 ];
environment.systemPackages = with pkgs; [ postgresql_11_gssapi ]; environment.systemPackages = with pkgs; [ cfg.package ];
users.groups = { users.groups = {
${cfg.socket-group} = { members = [ "postgres" ] ++ cfg.local-users; }; ${cfg.socket-group} = { members = [ "postgres" ] ++ cfg.local-users; };
@ -255,7 +261,7 @@ in {
services.postgresql = { services.postgresql = {
enable = true; enable = true;
package = pkgs.postgresql_11_gssapi; package = cfg.package;
enableTCPIP = true; enableTCPIP = true;
ensureDatabases = mapAttrsToList (name: value: name) cfg.databases; ensureDatabases = mapAttrsToList (name: value: name) cfg.databases;
ensureUsers = ((mapAttrsToList (username: attrs: { ensureUsers = ((mapAttrsToList (username: attrs: {

View File

@ -4,47 +4,53 @@ with lib;
let let
cfg = config.informis.cl-gemini; cfg = config.informis.cl-gemini;
feedOpts = { ... }: with types; { feedOpts = { ... }:
options = { with types; {
url = mkOption { options = {
type = str; url = mkOption {
description = "Base URI of the feed, i.e. the URI corresponding to the feed path."; type = str;
example = "gemini://my.server/path/to/feedfiles"; description =
}; "Base URI of the feed, i.e. the URI corresponding to the feed path.";
example = "gemini://my.server/path/to/feedfiles";
};
title = mkOption { title = mkOption {
type = str; type = str;
description = "Title of given feed."; description = "Title of given feed.";
example = "My Fancy Feed"; example = "My Fancy Feed";
}; };
path = mkOption { path = mkOption {
type = str; type = str;
description = "Path to Gemini files making up the feed."; description = "Path to Gemini files making up the feed.";
example = "/path/to/feed"; example = "/path/to/feed";
};
}; };
}; };
};
ensure-certificates = hostname: user: key: cert: pkgs.writeShellScript "ensure-gemini-certificates.sh" '' ensure-certificates = hostname: user: key: cert:
if [[ ! -e ${key} ]]; then pkgs.writeShellScript "ensure-gemini-certificates.sh" ''
TARGET_CERT_DIR=$(${pkgs.coreutils}/bin/dirname ${cert}) if [[ ! -e ${key} ]]; then
TARGET_KEY_DIR=$(${pkgs.coreutils}/bin/dirname ${key}) TARGET_CERT_DIR=$(${pkgs.coreutils}/bin/dirname ${cert})
if [[ ! -d $TARGET_CERT_DIR ]]; then mkdir -p $TARGET_CERT_DIR; fi TARGET_KEY_DIR=$(${pkgs.coreutils}/bin/dirname ${key})
if [[ ! -d $TARGET_KEY_DIR ]]; then mkdir -p $TARGET_KEY_DIR; fi if [[ ! -d $TARGET_CERT_DIR ]]; then mkdir -p $TARGET_CERT_DIR; fi
${pkgs.openssl}/bin/openssl req -new -subj "/CN=.${hostname}" -addext "subjectAltName = DNS:${hostname}, DNS:.${hostname}" -x509 -newkey ec -pkeyopt ec_paramgen_curve:prime256v1 -days 3650 -nodes -out ${cert} -keyout ${key} if [[ ! -d $TARGET_KEY_DIR ]]; then mkdir -p $TARGET_KEY_DIR; fi
${pkgs.coreutils}/bin/chown -R ${user}:nogroup ${cert} ${pkgs.openssl}/bin/openssl req -new -subj "/CN=.${hostname}" -addext "subjectAltName = DNS:${hostname}, DNS:.${hostname}" -x509 -newkey ec -pkeyopt ec_paramgen_curve:prime256v1 -days 3650 -nodes -out ${cert} -keyout ${key}
${pkgs.coreutils}/bin/chown -R ${user}:nogroup ${key} ${pkgs.coreutils}/bin/chown -R ${user}:nogroup ${cert}
${pkgs.coreutils}/bin/chmod 0444 ${cert} ${pkgs.coreutils}/bin/chown -R ${user}:nogroup ${key}
${pkgs.coreutils}/bin/chmod 0400 ${key} ${pkgs.coreutils}/bin/chmod 0444 ${cert}
fi ${pkgs.coreutils}/bin/chmod 0400 ${key}
''; fi
'';
generate-feeds = feeds: generate-feeds = feeds:
let let
feed-strings = mapAttrsToList (feed-name: opts: feed-strings = mapAttrsToList (feed-name: opts:
"(cl-gemini:register-feed :name \"${feed-name}\" :title \"${opts.title}\" :path \"${opts.path}\" :base-uri \"${opts.url}\")") feeds; ''
in pkgs.writeText "gemini-local-feeds.lisp" (concatStringsSep "\n" feed-strings); (cl-gemini:register-feed :name "${feed-name}" :title "${opts.title}" :path "${opts.path}" :base-uri "${opts.url}")'')
feeds;
in pkgs.writeText "gemini-local-feeds.lisp"
(concatStringsSep "\n" feed-strings);
in { in {
options.informis.cl-gemini = with types; { options.informis.cl-gemini = with types; {
@ -58,7 +64,8 @@ in {
hostname = mkOption { hostname = mkOption {
type = str; type = str;
description = "Hostname at which the server is available (for generating the SSL certificate)."; description =
"Hostname at which the server is available (for generating the SSL certificate).";
example = "my.hostname.com"; example = "my.hostname.com";
}; };
@ -108,7 +115,8 @@ in {
feeds = mkOption { feeds = mkOption {
type = attrsOf (submodule feedOpts); type = attrsOf (submodule feedOpts);
description = "Feeds to generate and make available (as eg. /feed/name.xml)."; description =
"Feeds to generate and make available (as eg. /feed/name.xml).";
example = { example = {
diary = { diary = {
title = "My Diary"; title = "My Diary";
@ -116,7 +124,7 @@ in {
url = "gemini://my.host/blog-path/"; url = "gemini://my.host/blog-path/";
}; };
}; };
default = {}; default = { };
}; };
textfiles-archive = mkOption { textfiles-archive = mkOption {
@ -141,10 +149,13 @@ in {
systemd.services = { systemd.services = {
cl-gemini = { cl-gemini = {
description = "cl-gemini Gemini server (https://gemini.circumlunar.space/)"; description =
"cl-gemini Gemini server (https://gemini.circumlunar.space/)";
serviceConfig = { serviceConfig = {
ExecStartPre = "${ensure-certificates cfg.hostname cfg.user cfg.ssl-private-key cfg.ssl-certificate}"; ExecStartPre =
"${ensure-certificates cfg.hostname cfg.user cfg.ssl-private-key
cfg.ssl-certificate}";
ExecStart = "${pkgs.cl-gemini}/bin/launch-server.sh"; ExecStart = "${pkgs.cl-gemini}/bin/launch-server.sh";
Restart = "on-failure"; Restart = "on-failure";
PIDFile = "/run/cl-gemini.$USERNAME.uid"; PIDFile = "/run/cl-gemini.$USERNAME.uid";
@ -152,7 +163,8 @@ in {
}; };
environment = { environment = {
GEMINI_SLYNK_PORT = mkIf (cfg.slynk-port != null) (toString cfg.slynk-port); GEMINI_SLYNK_PORT =
mkIf (cfg.slynk-port != null) (toString cfg.slynk-port);
GEMINI_LISTEN_IP = cfg.server-ip; GEMINI_LISTEN_IP = cfg.server-ip;
GEMINI_PRIVATE_KEY = cfg.ssl-private-key; GEMINI_PRIVATE_KEY = cfg.ssl-private-key;
GEMINI_CERTIFICATE = cfg.ssl-certificate; GEMINI_CERTIFICATE = cfg.ssl-certificate;
@ -161,14 +173,11 @@ in {
GEMINI_TEXTFILES_ROOT = cfg.textfiles-archive; GEMINI_TEXTFILES_ROOT = cfg.textfiles-archive;
GEMINI_FEEDS = "${generate-feeds cfg.feeds}"; GEMINI_FEEDS = "${generate-feeds cfg.feeds}";
CL_SOURCE_REGISTRY = pkgs.lib.lisp.lisp-source-registry pkgs.cl-gemini; CL_SOURCE_REGISTRY =
pkgs.lib.lisp.lisp-source-registry pkgs.cl-gemini;
}; };
path = with pkgs; [ path = with pkgs; [ gcc file getent ];
gcc
file
getent
];
wantedBy = [ "multi-user.target" ]; wantedBy = [ "multi-user.target" ];
}; };