at master 3.0 kB view raw
1{ 2 config, 3 lib, 4 pkgs, 5 ... 6}: 7let 8 cfg = config.services.corteza; 9in 10{ 11 options.services.corteza = { 12 enable = lib.mkEnableOption "Corteza, a low-code platform"; 13 package = lib.mkPackageOption pkgs "corteza" { }; 14 15 address = lib.mkOption { 16 type = lib.types.str; 17 default = "0.0.0.0"; 18 description = '' 19 IP for the HTTP server. 20 ''; 21 }; 22 port = lib.mkOption { 23 type = lib.types.port; 24 default = 80; 25 description = '' 26 Port for the HTTP server. 27 ''; 28 }; 29 openFirewall = lib.mkOption { 30 type = lib.types.bool; 31 default = false; 32 example = true; 33 description = "Whether to open ports in the firewall."; 34 }; 35 36 user = lib.mkOption { 37 type = lib.types.str; 38 default = "corteza"; 39 description = "The user to run Corteza under."; 40 }; 41 42 group = lib.mkOption { 43 type = lib.types.str; 44 default = "corteza"; 45 description = "The group to run Corteza under."; 46 }; 47 48 settings = lib.mkOption { 49 type = lib.types.submodule { 50 freeformType = lib.types.attrsOf lib.types.str; 51 options = { 52 HTTP_WEBAPP_ENABLED = lib.mkEnableOption "webapps" // { 53 default = true; 54 apply = toString; 55 }; 56 }; 57 }; 58 default = { }; 59 description = '' 60 Configuration for Corteza, will be passed as environment variables. 61 See <https://docs.cortezaproject.org/corteza-docs/2024.9/devops-guide/references/configuration/server.html>. 62 ''; 63 }; 64 }; 65 66 config = lib.mkIf cfg.enable { 67 assertions = [ 68 { 69 assertion = !cfg.settings ? HTTP_ADDR; 70 message = "Use `services.corteza.address` and `services.corteza.port` instead."; 71 } 72 ]; 73 74 warnings = lib.optional (!cfg.settings ? DB_DSN) '' 75 A database connection string is not set. 76 Corteza will create a temporary SQLite database in memory, but it will not persist data. 77 For production use, set `services.corteza.settings.DB_DSN`. 78 ''; 79 80 networking.firewall.allowedTCPPorts = lib.mkIf cfg.openFirewall [ cfg.port ]; 81 82 systemd.services.corteza = { 83 description = "Corteza"; 84 documentation = [ "https://docs.cortezaproject.org/" ]; 85 after = [ "network-online.target" ]; 86 wants = [ "network-online.target" ]; 87 wantedBy = [ "multi-user.target" ]; 88 environment = { 89 HTTP_WEBAPP_BASE_DIR = "./webapp"; 90 HTTP_ADDR = "${cfg.address}:${toString cfg.port}"; 91 } 92 // cfg.settings; 93 path = [ pkgs.dart-sass ]; 94 serviceConfig = { 95 WorkingDirectory = cfg.package; 96 User = cfg.user; 97 Group = cfg.group; 98 ExecStart = "${lib.getExe cfg.package} serve-api"; 99 }; 100 }; 101 102 users = { 103 groups.${cfg.group} = { }; 104 users.${cfg.user} = { 105 inherit (cfg) group; 106 isSystemUser = true; 107 }; 108 }; 109 }; 110 111 meta.maintainers = with lib.maintainers; [ 112 prince213 113 ]; 114}