blob: 8b89df7497c6dfbe2927f4e862b517878457ad24 (
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
{ lib, pkgs, unstablePkgs, auxiliaryPkgs, ... }:
let
inherit (pkgs) dockerTools;
inherit (auxiliaryPkgs) common;
inherit (unstablePkgs) fedifetcher;
akkomaLocalPort = "1111";
akkomaDir = "/srv/akkoma";
akkoma = unstablePkgs.akkoma.overrideAttrs {
patches = [ ./docker-entrypoint.patch ];
postInstall = ''
cp docker-entrypoint.sh $out/docker-entrypoint.sh
'';
};
akkomaImage = dockerTools.buildLayeredImage {
name = "akkoma";
tag = akkoma.version;
fromImage = common.alpine.base;
contents = with unstablePkgs; [
exiftool imagemagick ffmpeg_7-headless postgresql elixir
] ++ [ akkoma ];
extraCommands = ''
mkdir -p opt/akkoma
'';
};
fedifetcherScript = pkgs.writeShellScriptBin "fedifetcher-script.sh" ''
fedifetcher -c /etc/fedifetcher/config.json &>> /var/log/fedifetcher.log
'';
fedifetcherCron = pkgs.writeText "fedifetcher-cron" ''
0 */3 * * * /bin/fedifetcher-script.sh
'';
fedifetcherEntry = pkgs.writeShellScriptBin "fedifetcher-entry.sh" ''
crond -b -l 0 -L /var/log/crond.log
touch /var/log/fedifetcher.log
tail -f /var/log/fedifetcher.log
'';
fedifetcherImage = dockerTools.buildLayeredImage {
name = "fedifetcher";
tag = fedifetcher.version;
fromImage = common.alpine.base;
contents = [ pkgs.bash fedifetcher fedifetcherEntry fedifetcherScript ];
extraCommands = ''
mkdir -p etc/crontabs
cat ${fedifetcherCron} > etc/crontabs/root
'';
};
in
{
virtualisation.oci-containers.containers = {
akkoma = {
imageFile = akkomaImage;
image = "akkoma:${akkoma.version}";
ports = [ "127.0.0.1:${akkomaLocalPort}:4000"];
volumes = [
"${akkomaDir}/data:/var/lib/akkoma"
"${akkomaDir}/config:/opt/akkoma/config"
];
# TODO: remove redundant variables
environment = {
"RUNTIME_DIRECTORY" = "/opt/akkoma";
"AKKOMA_CONFIG_PATH" = "/opt/akkoma/config/config.exs";
"RELEASE_COOKIE" = "99ff9ca022574585269e737cdc4fa28b";
"RELEASE_NAME" = "akkoma";
"MIX_ENV" = "prod";
"DB_NAME" = "akkoma";
"DB_USER" = "akkoma";
"DB_PASS" = "akkoma";
"DB_HOST" = "db";
};
entrypoint = "${akkoma}/docker-entrypoint.sh";
workdir = "${akkoma}";
extraOptions = [
"--network-alias=akkoma"
"--network=akkoma"
];
};
akkoma-db = {
inherit (common.postgres14) image imageFile;
volumes = [ "${akkomaDir}/pgdata:/var/lib/postgresql/data" ];
environment = {
"POSTGRES_DB" = "akkoma";
"POSTGRES_USER" = "akkoma";
"POSTGRES_PASSWORD" = "akkoma";
};
extraOptions = [
"--network-alias=db"
"--network=akkoma"
];
};
akkoma-fedifetcher = {
imageFile = fedifetcherImage;
image = "fedifetcher:${fedifetcher.version}";
volumes = [
"${akkomaDir}/fedifetcher:/opt/fedifetcher"
"${akkomaDir}/fedifetcher.json:/etc/fedifetcher/config.json"
];
entrypoint = "/bin/fedifetcher-entry.sh";
extraOptions = [
"--network-alias=db"
"--network=akkoma"
];
};
};
# systemd configuration to combine containers.
# mostly condensed from compose2nix output.
# TODO: make this automatic!!
systemd = let
root = "docker-akkoma-root";
network = "docker-akkoma-network";
containerService = {
serviceConfig = {
Restart = lib.mkOverride 90 "always";
RestartMaxDelaySec = lib.mkOverride 90 "1m";
RestartSec = lib.mkOverride 90 "100ms";
RestartSteps = lib.mkOverride 90 9;
};
after = [ "${network}.service" ]; requires = [ "${network}.service" ];
partOf = [ "${root}.target" ]; wantedBy = [ "${root}.target" ];
};
in {
services = {
"docker-akkoma" = containerService;
"docker-akkoma-db" = containerService;
"docker-akkoma-fedifetcher" = containerService;
"${network}" = {
path = [ pkgs.docker ];
serviceConfig = {
Type = "oneshot";
RemainAfterExit = true;
ExecStop = "docker network rm -f akkoma";
};
script = ''
docker network inspect akkoma || docker network create akkoma --driver=bridge
'';
partOf = [ "${root}.target" ]; wantedBy = [ "${root}.target" ];
};
};
targets = {
"${root}" = { wantedBy = [ "multi-user.target" ]; };
};
};
}
|