Use envvars to configure srv
This commit is contained in:
parent
5c247b6f29
commit
39ad0e614f
@ -5,7 +5,7 @@
|
|||||||
powSecret = "ssshhh";
|
powSecret = "ssshhh";
|
||||||
mlSMTPAddr = "";
|
mlSMTPAddr = "";
|
||||||
mlSMTPAuth = "";
|
mlSMTPAuth = "";
|
||||||
publicURL = "http://localhost:4000";
|
mlPublicURL = "http://localhost:4000";
|
||||||
listenProto = "tcp";
|
listenProto = "tcp";
|
||||||
listenAddr = ":4000";
|
listenAddr = ":4000";
|
||||||
|
|
||||||
|
@ -23,11 +23,13 @@
|
|||||||
|
|
||||||
static = (import ./static) { inherit pkgs; };
|
static = (import ./static) { inherit pkgs; };
|
||||||
|
|
||||||
srv = (import ./srv) {
|
srv = pkgs.callPackage (import ./srv) {
|
||||||
inherit pkgs config;
|
inherit config;
|
||||||
staticBuild=static.build;
|
staticBuild=static.build;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
srvBin = srv.bin;
|
||||||
|
|
||||||
redisCfg = pkgs.writeText "mediocre-blog-redisCfg" ''
|
redisCfg = pkgs.writeText "mediocre-blog-redisCfg" ''
|
||||||
port 0
|
port 0
|
||||||
unixsocket ${config.redisListenPath}
|
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 = [
|
config,
|
||||||
"-ml-smtp-addr=${config.mlSMTPAddr}"
|
staticBuild,
|
||||||
"-ml-smtp-auth='${config.mlSMTPAuth}'"
|
}: rec {
|
||||||
"-data-dir=${config.dataDir}"
|
|
||||||
"-public-url=${config.publicURL}"
|
|
||||||
];
|
|
||||||
|
|
||||||
opts = mailingListOpts ++ [
|
env = ''
|
||||||
"-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}" ]
|
|
||||||
);
|
|
||||||
|
|
||||||
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";
|
pname = "mediocre-blog-srv";
|
||||||
version = "dev";
|
version = "dev";
|
||||||
src = ./.;
|
src = ./.;
|
||||||
@ -29,24 +46,17 @@
|
|||||||
checkPhase = '''';
|
checkPhase = '''';
|
||||||
};
|
};
|
||||||
|
|
||||||
bin = pkgs.writeScript "mediocre-blog-srv-bin" ''
|
bin = writeScript "mediocre-blog-srv-bin" ''
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
mkdir -p "${config.dataDir}"
|
mkdir -p "${config.dataDir}"
|
||||||
exec ${build}/bin/mediocre-blog ${toString opts}
|
source ${env}
|
||||||
|
exec ${build}/bin/mediocre-blog
|
||||||
'';
|
'';
|
||||||
|
|
||||||
runScript = pkgs.writeScriptBin "run-mediocre-blog" ''
|
shell = stdenv.mkDerivation {
|
||||||
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 {
|
|
||||||
name = "mediocre-blog-srv-shell";
|
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.
|
// SetupCfg implement the cfg.Cfger interface.
|
||||||
func (p *Params) SetupCfg(cfg *cfg.Cfg) {
|
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 {
|
cfg.OnInit(func(ctx context.Context) error {
|
||||||
var err error
|
var err error
|
||||||
|
Loading…
Reference in New Issue
Block a user