1{
2 pkgs,
3 lib,
4 config,
5 ...
6}:
7
8with lib;
9
10let
11 cfg = config.services.vikunja;
12 format = pkgs.formats.yaml { };
13 configFile = format.generate "config.yaml" cfg.settings;
14 useMysql = cfg.database.type == "mysql";
15 usePostgresql = cfg.database.type == "postgres";
16in
17{
18 imports = [
19 (mkRemovedOptionModule [ "services" "vikunja" "setupNginx" ]
20 "services.vikunja no longer supports the automatic set up of a nginx virtual host. Set up your own webserver config with a proxy pass to the vikunja service."
21 )
22 ];
23
24 options.services.vikunja = with lib; {
25 enable = mkEnableOption "vikunja service";
26 package = mkPackageOption pkgs "vikunja" { };
27 environmentFiles = mkOption {
28 type = types.listOf types.path;
29 default = [ ];
30 description = ''
31 List of environment files set in the vikunja systemd service.
32 For example passwords should be set in one of these files.
33 '';
34 };
35 frontendScheme = mkOption {
36 type = types.enum [
37 "http"
38 "https"
39 ];
40 description = ''
41 Whether the site is available via http or https.
42 '';
43 };
44 frontendHostname = mkOption {
45 type = types.str;
46 description = "The Hostname under which the frontend is running.";
47 };
48 port = mkOption {
49 type = types.port;
50 default = 3456;
51 description = "The TCP port exposed by the API.";
52 };
53
54 settings = mkOption {
55 type = format.type;
56 default = { };
57 description = ''
58 Vikunja configuration. Refer to
59 <https://vikunja.io/docs/config-options/>
60 for details on supported values.
61 '';
62 };
63 database = {
64 type = mkOption {
65 type = types.enum [
66 "sqlite"
67 "mysql"
68 "postgres"
69 ];
70 example = "postgres";
71 default = "sqlite";
72 description = "Database engine to use.";
73 };
74 host = mkOption {
75 type = types.str;
76 default = "localhost";
77 description = "Database host address. Can also be a socket.";
78 };
79 user = mkOption {
80 type = types.str;
81 default = "vikunja";
82 description = "Database user.";
83 };
84 database = mkOption {
85 type = types.str;
86 default = "vikunja";
87 description = "Database name.";
88 };
89 path = mkOption {
90 type = types.str;
91 default = "/var/lib/vikunja/vikunja.db";
92 description = "Path to the sqlite3 database file.";
93 };
94 };
95 };
96 config = lib.mkIf cfg.enable {
97 services.vikunja.settings = {
98 database = {
99 inherit (cfg.database)
100 type
101 host
102 user
103 database
104 path
105 ;
106 };
107 service = {
108 interface = ":${toString cfg.port}";
109 frontendurl = "${cfg.frontendScheme}://${cfg.frontendHostname}/";
110 };
111 files = {
112 basepath = "/var/lib/vikunja/files";
113 };
114 };
115
116 systemd.services.vikunja = {
117 description = "vikunja";
118 after =
119 [ "network.target" ]
120 ++ lib.optional usePostgresql "postgresql.service"
121 ++ lib.optional useMysql "mysql.service";
122 wantedBy = [ "multi-user.target" ];
123 path = [ cfg.package ];
124 restartTriggers = [ configFile ];
125
126 serviceConfig = {
127 Type = "simple";
128 DynamicUser = true;
129 StateDirectory = "vikunja";
130 ExecStart = "${cfg.package}/bin/vikunja";
131 Restart = "always";
132 EnvironmentFile = cfg.environmentFiles;
133 };
134 };
135
136 environment.etc."vikunja/config.yaml".source = configFile;
137
138 environment.systemPackages = [
139 cfg.package # for admin `vikunja` CLI
140 ];
141 };
142}