summaryrefslogtreecommitdiff
path: root/srv/default.nix
blob: bc828a0a653ccb23314f4e6741437f6dc82fb5b1 (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
{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 {
        pname = "mediocre-blog-srv";
        version = "dev";
        src = ./.;
        vendorSha256 = "02szg1lisfjk8pk9pflbyv97ykg9362r4fhd0w0p2a7c81kf9b8y";

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

    bin = pkgs.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} "$@"
    '';

    shell = pkgs.stdenv.mkDerivation {
        name = "mediocre-blog-srv-shell";
        buildInputs = [ pkgs.go runScript runMailingListCLIScript ];
    };

}