summaryrefslogtreecommitdiff
path: root/srv
diff options
context:
space:
mode:
authorBrian Picciano <mediocregopher@gmail.com>2022-05-05 20:57:17 -0600
committerBrian Picciano <mediocregopher@gmail.com>2022-05-05 20:57:17 -0600
commit39ad0e614f6c97595710b4d8f535b41f0d83aa0e (patch)
tree6774b7a817b771b6d88562c66398f6e671123804 /srv
parent5c247b6f2907e8c4da5a66fa2192fcba95e100f2 (diff)
Use envvars to configure srv
Diffstat (limited to 'srv')
-rw-r--r--srv/.gitignore1
-rw-r--r--srv/default.nix82
-rw-r--r--srv/mailinglist/mailinglist.go2
3 files changed, 47 insertions, 38 deletions
diff --git a/srv/.gitignore b/srv/.gitignore
deleted file mode 100644
index a43632f..0000000
--- a/srv/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-mailinglist.sqlite3
diff --git a/srv/default.nix b/srv/default.nix
index bc828a0..3037fd7 100644
--- a/srv/default.nix
+++ b/srv/default.nix
@@ -1,25 +1,42 @@
-{pkgs, config, staticBuild}: rec {
-
- mailingListOpts = [
- "-ml-smtp-addr=${config.mlSMTPAddr}"
- "-ml-smtp-auth='${config.mlSMTPAuth}'"
- "-data-dir=${config.dataDir}"
- "-public-url=${config.publicURL}"
- ];
-
- 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}" ]
- );
-
- build = pkgs.buildGoModule {
+{
+ buildGoModule,
+ writeScript,
+ writeScriptBin,
+ stdenv,
+
+ config,
+ staticBuild,
+}: rec {
+
+ env = ''
+
+ 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}
- '';
-
- 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} "$@"
+ source ${env}
+ exec ${build}/bin/mediocre-blog
'';
- shell = pkgs.stdenv.mkDerivation {
+ shell = stdenv.mkDerivation {
name = "mediocre-blog-srv-shell";
- buildInputs = [ pkgs.go runScript runMailingListCLIScript ];
+ shellHook = ''
+ source ${env}
+ '';
};
-
}
diff --git a/srv/mailinglist/mailinglist.go b/srv/mailinglist/mailinglist.go
index 60c1174..fc6e014 100644
--- a/srv/mailinglist/mailinglist.go
+++ b/srv/mailinglist/mailinglist.go
@@ -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