summaryrefslogtreecommitdiff
path: root/srv/default.nix
blob: e6216b37b959e418933719970fc9979aefcfd120 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
{
  bash,
  go,
  buildGoModule,
  sqlite,
  writeScript,
  writeText,
  stdenv,

  config,
}: rec {

    init = writeText "mediocre-blog-srv-init" ''

      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.publicURL}"

      # pow
      export MEDIOCRE_BLOG_POW_SECRET="${config.powSecret}"

      # http
      export MEDIOCRE_BLOG_HTTP_PUBLIC_URL="${config.publicURL}"
      export MEDIOCRE_BLOG_HTTP_LISTEN_PROTO="${config.httpListenProto}"
      export MEDIOCRE_BLOG_HTTP_LISTEN_ADDR="${config.httpListenAddr}"
      export MEDIOCRE_BLOG_HTTP_AUTH_USERS='${builtins.toJSON config.httpAuthUsers}'
      export MEDIOCRE_BLOG_HTTP_AUTH_RATELIMIT='${config.httpAuthRatelimit}'
    '';

    build = buildGoModule {
        pname = "mediocre-blog-srv";
        version = "dev";
        src = ./src;
        vendorSha256 = "sha256:1vazrrg8rs9n8x40c9r53h9qnyxw59xkp0aq7jl15fliigk6q0cr";

        # disable tests
        checkPhase = '''';
    };

    bin = writeScript "mediocre-blog-srv-bin" ''
        #!${bash}/bin/bash
        source ${init}
        exec ${build}/bin/mediocre-blog "$@"
    '';

    shell = stdenv.mkDerivation {
        name = "mediocre-blog-srv-shell";
        buildInputs = [ go sqlite ];
        shellHook = ''
          source ${init}

          echo "Loading test data..."
          (cd srv/src/cmd/load-test-data && go run main.go)
        '';
    };
}