diff options
author | Brian Picciano <mediocregopher@gmail.com> | 2022-05-05 20:57:17 -0600 |
---|---|---|
committer | Brian Picciano <mediocregopher@gmail.com> | 2022-05-05 20:57:17 -0600 |
commit | 39ad0e614f6c97595710b4d8f535b41f0d83aa0e (patch) | |
tree | 6774b7a817b771b6d88562c66398f6e671123804 | |
parent | 5c247b6f2907e8c4da5a66fa2192fcba95e100f2 (diff) |
Use envvars to configure srv
-rw-r--r-- | config.nix | 2 | ||||
-rw-r--r-- | default.nix | 6 | ||||
-rw-r--r-- | srv/.gitignore | 1 | ||||
-rw-r--r-- | srv/default.nix | 82 | ||||
-rw-r--r-- | srv/mailinglist/mailinglist.go | 2 |
5 files changed, 52 insertions, 41 deletions
@@ -5,7 +5,7 @@ powSecret = "ssshhh"; mlSMTPAddr = ""; mlSMTPAuth = ""; - publicURL = "http://localhost:4000"; + mlPublicURL = "http://localhost:4000"; listenProto = "tcp"; listenAddr = ":4000"; diff --git a/default.nix b/default.nix index 6e06c43..bb9d8f8 100644 --- a/default.nix +++ b/default.nix @@ -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} 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 |