1{ pkgs, lib, ... }:
2{
3 name = "hedgedoc";
4
5 meta.maintainers = [ ];
6 nodes = {
7 hedgedocSqlite =
8 { ... }:
9 {
10 services.hedgedoc.enable = true;
11 };
12
13 hedgedocPostgresWithTCPSocket =
14 { ... }:
15 {
16 systemd.services.hedgedoc.after = [ "postgresql.target" ];
17 services = {
18 hedgedoc = {
19 enable = true;
20 settings.db = {
21 dialect = "postgres";
22 user = "hedgedoc";
23 password = "$DB_PASSWORD";
24 host = "localhost";
25 port = 5432;
26 database = "hedgedocdb";
27 };
28
29 /*
30 Do not use pkgs.writeText for secrets as
31 they will end up in the world-readable Nix store.
32 */
33 environmentFile = pkgs.writeText "hedgedoc-env" ''
34 DB_PASSWORD=snakeoilpassword
35 '';
36 };
37 postgresql = {
38 enable = true;
39 initialScript = pkgs.writeText "pg-init-script.sql" ''
40 CREATE ROLE hedgedoc LOGIN PASSWORD 'snakeoilpassword';
41 CREATE DATABASE hedgedocdb OWNER hedgedoc;
42 '';
43 };
44 };
45 };
46
47 hedgedocPostgresWithUNIXSocket =
48 { ... }:
49 {
50 systemd.services.hedgedoc.after = [ "postgresql.target" ];
51 services = {
52 hedgedoc = {
53 enable = true;
54 settings.db = {
55 dialect = "postgres";
56 user = "hedgedoc";
57 password = "$DB_PASSWORD";
58 host = "/run/postgresql";
59 database = "hedgedocdb";
60 };
61
62 environmentFile = pkgs.writeText "hedgedoc-env" ''
63 DB_PASSWORD=snakeoilpassword
64 '';
65 };
66 postgresql = {
67 enable = true;
68 initialScript = pkgs.writeText "pg-init-script.sql" ''
69 CREATE ROLE hedgedoc LOGIN PASSWORD 'snakeoilpassword';
70 CREATE DATABASE hedgedocdb OWNER hedgedoc;
71 '';
72 };
73 };
74 };
75 };
76
77 testScript = ''
78 start_all()
79
80 with subtest("HedgeDoc sqlite"):
81 hedgedocSqlite.wait_for_unit("hedgedoc.service")
82 hedgedocSqlite.wait_for_open_port(3000)
83 hedgedocSqlite.wait_until_succeeds("curl -sSf http://localhost:3000/new")
84
85 with subtest("HedgeDoc postgres with TCP socket"):
86 hedgedocPostgresWithTCPSocket.wait_for_unit("postgresql.target")
87 hedgedocPostgresWithTCPSocket.wait_for_unit("hedgedoc.service")
88 hedgedocPostgresWithTCPSocket.wait_for_open_port(5432)
89 hedgedocPostgresWithTCPSocket.wait_for_open_port(3000)
90 hedgedocPostgresWithTCPSocket.wait_until_succeeds("curl -sSf http://localhost:3000/new")
91
92 with subtest("HedgeDoc postgres with UNIX socket"):
93 hedgedocPostgresWithUNIXSocket.wait_for_unit("postgresql.target")
94 hedgedocPostgresWithUNIXSocket.wait_for_unit("hedgedoc.service")
95 hedgedocPostgresWithUNIXSocket.wait_for_open_port(5432)
96 hedgedocPostgresWithUNIXSocket.wait_for_open_port(3000)
97 hedgedocPostgresWithUNIXSocket.wait_until_succeeds("curl -sSf http://localhost:3000/new")
98 '';
99}