summaryrefslogtreecommitdiff
path: root/default.nix
blob: a713f8a1f08a47793f616c01bb690f2b16fa4f4b (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
let
    utils = (import ./nix) {};
    pkgs = utils.pkgs;
    system = utils.system;
in
    {config ? ./config.nix}: rec {
        config = (import ./config.nix);

        static = (import ./static).build;

        srv = (import ./srv).build;
        srvBin = pkgs.writeScript "mediocregopher-mediocre-blog-srvBin" ''
            #!/bin/sh
            exec ${srv}/bin/mediocre-blog \
                -pow-secret   "${config.powSecret}" \
                -ml-smtp-addr "${config.mlSMTPAddr}" \
                -ml-smtp-auth "${config.mlSMTPAuth}" \
                -data-dir     "${config.dataDir}" \
                -public-url   "${config.publicURL}" \
                -static-dir   "${static}" \
                -listen-proto "${config.listenProto}" \
                -listen-addr  "${config.listenAddr}"
        '';

        redisCfg = pkgs.writeText "mediocregopher-mediocre-blog-redisCfg" ''
            port 0
            unixsocket ${config.redisListenPath}
            daemonize no
            loglevel notice
            logfile ""
            appendonly yes
            appendfilename "appendonly.aof"
            dir ${config.dataDir}/redis
        '';

        redisBin = pkgs.writeScript "mediocregopher-mediocre-blog-redisBin" ''
            #!/bin/sh
            mkdir -p ${config.dataDir}/redis
            exec ${pkgs.redis}/bin/redis-server ${redisCfg}
        '';

        circusCfg = pkgs.writeText "mediocregopher-mediocre-blog-circusCfg" ''
            [circus]
            endpoint = tcp://127.0.0.1:0
            pubsub_endpoint = tcp://127.0.0.1:0

            [watcher:srv]
            cmd = ${srvBin}
            numprocesses = 1

            [watcher:redis]
            cmd = ${redisBin}
            numprocesses = 1
        '';

        circusBin = pkgs.writeScript "mediocregopher-mediocre-blog-circusBin" ''
            exec ${pkgs.circus}/bin/circusd ${circusCfg}
        '';

        service = pkgs.writeText "mediocregopher-mediocre-blog" ''
            [Unit]
            Description=mediocregopher mediocre blog
            Requires=network.target
            After=network.target

            [Service]
            Restart=always
            RestartSec=1s
            User=mediocregopher
            ExecStart=${circusBin}

            [Install]
            WantedBy=multi-user.target
        '';

        install = pkgs.writeScript "mediocregopher-mediocre-blog" ''
                set -e -x

                sudo cp ${service} /etc/systemd/system/mediocregopher-mediocre-blog.service
                sudo systemctl daemon-reload
                sudo systemctl enable mediocregopher-mediocre-blog.service
                sudo systemctl restart mediocregopher-mediocre-blog.service
        '';
    }