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