Use envvars to configure srv
This commit is contained in:
parent
5c247b6f29
commit
39ad0e614f
@ -5,7 +5,7 @@
|
||||
powSecret = "ssshhh";
|
||||
mlSMTPAddr = "";
|
||||
mlSMTPAuth = "";
|
||||
publicURL = "http://localhost:4000";
|
||||
mlPublicURL = "http://localhost:4000";
|
||||
listenProto = "tcp";
|
||||
listenAddr = ":4000";
|
||||
|
||||
|
@ -23,11 +23,13 @@
|
||||
|
||||
static = (import ./static) { inherit pkgs; };
|
||||
|
||||
srv = (import ./srv) {
|
||||
inherit pkgs config;
|
||||
srv = pkgs.callPackage (import ./srv) {
|
||||
inherit config;
|
||||
staticBuild=static.build;
|
||||
};
|
||||
|
||||
srvBin = srv.bin;
|
||||
|
||||
redisCfg = pkgs.writeText "mediocre-blog-redisCfg" ''
|
||||
port 0
|
||||
unixsocket ${config.redisListenPath}
|
||||
|
1
srv/.gitignore
vendored
1
srv/.gitignore
vendored
@ -1 +0,0 @@
|
||||
mailinglist.sqlite3
|
@ -1,25 +1,42 @@
|
||||
{pkgs, config, staticBuild}: rec {
|
||||
{
|
||||
buildGoModule,
|
||||
writeScript,
|
||||
writeScriptBin,
|
||||
stdenv,
|
||||
|
||||
mailingListOpts = [
|
||||
"-ml-smtp-addr=${config.mlSMTPAddr}"
|
||||
"-ml-smtp-auth='${config.mlSMTPAuth}'"
|
||||
"-data-dir=${config.dataDir}"
|
||||
"-public-url=${config.publicURL}"
|
||||
];
|
||||
config,
|
||||
staticBuild,
|
||||
}: rec {
|
||||
|
||||
opts = mailingListOpts ++ [
|
||||
"-pow-secret=${config.powSecret}"
|
||||
"-listen-proto=${config.listenProto}"
|
||||
"-listen-addr=${config.listenAddr}"
|
||||
"-redis-proto=unix"
|
||||
"-redis-addr=${config.redisListenPath}"
|
||||
] ++ (
|
||||
if config.staticProxyURL == ""
|
||||
then [ "-static-dir=${staticBuild}" ]
|
||||
else [ "-static-proxy-url=${config.staticProxyURL}" ]
|
||||
);
|
||||
env = ''
|
||||
|
||||
build = pkgs.buildGoModule {
|
||||
export MEDIOCRE_BLOG_DATA_DIR=${config.dataDir}
|
||||
|
||||
# mailing list
|
||||
export MEDIOCRE_BLOG_ML_SMTP_ADDR=${config.mlSMTPAddr}
|
||||
export MEDIOCRE_BLOG_ML_SMTP_AUTH='${config.mlSMTPAuth}'
|
||||
export MEDIOCRE_BLOG_ML_PUBLIC_URL=${config.mlPublicURL}
|
||||
|
||||
# redis
|
||||
export MEDIOCRE_BLOG_REDIS_PROTO=unix
|
||||
export MEDIOCRE_BLOG_REDIS_ADDR=${config.redisListenPath}
|
||||
|
||||
# pow
|
||||
export MEDIOCRE_BLOG_POW_SECRET=${config.powSecret}
|
||||
|
||||
# static proxy
|
||||
if [ "${config.staticProxyURL}" == "" ]; then
|
||||
export MEDIOCRE_BLOG_STATIC_DIR=${staticBuild}
|
||||
else
|
||||
export MEDIOCRE_BLOG_STATIC_URL=${config.staticProxyURL}
|
||||
fi
|
||||
|
||||
# listening
|
||||
export MEDIOCRE_BLOG_LISTEN_PROTO=${config.listenProto}
|
||||
export MEDIOCRE_BLOG_LISTEN_ADDR=${config.listenAddr}
|
||||
'';
|
||||
|
||||
build = buildGoModule {
|
||||
pname = "mediocre-blog-srv";
|
||||
version = "dev";
|
||||
src = ./.;
|
||||
@ -29,24 +46,17 @@
|
||||
checkPhase = '''';
|
||||
};
|
||||
|
||||
bin = pkgs.writeScript "mediocre-blog-srv-bin" ''
|
||||
bin = writeScript "mediocre-blog-srv-bin" ''
|
||||
#!/bin/sh
|
||||
mkdir -p "${config.dataDir}"
|
||||
exec ${build}/bin/mediocre-blog ${toString opts}
|
||||
source ${env}
|
||||
exec ${build}/bin/mediocre-blog
|
||||
'';
|
||||
|
||||
runScript = pkgs.writeScriptBin "run-mediocre-blog" ''
|
||||
mkdir -p "${config.dataDir}"
|
||||
go run ./cmd/mediocre-blog/main.go ${toString opts}
|
||||
'';
|
||||
|
||||
runMailingListCLIScript = pkgs.writeScriptBin "run-mailinglist-cli" ''
|
||||
go run ./cmd/mailinglist-cli/main.go ${toString mailingListOpts} "$@"
|
||||
'';
|
||||
|
||||
shell = pkgs.stdenv.mkDerivation {
|
||||
shell = stdenv.mkDerivation {
|
||||
name = "mediocre-blog-srv-shell";
|
||||
buildInputs = [ pkgs.go runScript runMailingListCLIScript ];
|
||||
shellHook = ''
|
||||
source ${env}
|
||||
'';
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ type Params struct {
|
||||
|
||||
// SetupCfg implement the cfg.Cfger interface.
|
||||
func (p *Params) SetupCfg(cfg *cfg.Cfg) {
|
||||
publicURLStr := cfg.String("public-url", "http://localhost:4000", "URL this service is accessible at")
|
||||
publicURLStr := cfg.String("ml-public-url", "http://localhost:4000", "URL this service is accessible at")
|
||||
|
||||
cfg.OnInit(func(ctx context.Context) error {
|
||||
var err error
|
||||
|
Loading…
Reference in New Issue
Block a user