From c721b7dfe9811b3f9ba5423e9a2bff1454d62fe0 Mon Sep 17 00:00:00 2001 From: Sizhe Zhao Date: Tue, 24 Jun 2025 18:54:39 +0800 Subject: [PATCH] nixos/corteza: init --- nixos/modules/module-list.nix | 1 + .../modules/services/development/corteza.nix | 113 ++++++++++++++++++ 2 files changed, 114 insertions(+) create mode 100644 nixos/modules/services/development/corteza.nix diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index 5eb40adc5647..a297dfc96d5d 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -579,6 +579,7 @@ ./services/development/athens.nix ./services/development/blackfire.nix ./services/development/bloop.nix + ./services/development/corteza.nix ./services/development/distccd.nix ./services/development/gemstash.nix ./services/development/hoogle.nix diff --git a/nixos/modules/services/development/corteza.nix b/nixos/modules/services/development/corteza.nix new file mode 100644 index 000000000000..2f3e8abd0b68 --- /dev/null +++ b/nixos/modules/services/development/corteza.nix @@ -0,0 +1,113 @@ +{ + config, + lib, + pkgs, + ... +}: +let + cfg = config.services.corteza; +in +{ + options.services.corteza = { + enable = lib.mkEnableOption "Corteza, a low-code platform"; + package = lib.mkPackageOption pkgs "corteza" { }; + + address = lib.mkOption { + type = lib.types.str; + default = "0.0.0.0"; + description = '' + IP for the HTTP server. + ''; + }; + port = lib.mkOption { + type = lib.types.port; + default = 80; + description = '' + Port for the HTTP server. + ''; + }; + openFirewall = lib.mkOption { + type = lib.types.bool; + default = false; + example = true; + description = "Whether to open ports in the firewall."; + }; + + user = lib.mkOption { + type = lib.types.str; + default = "corteza"; + description = "The user to run Corteza under."; + }; + + group = lib.mkOption { + type = lib.types.str; + default = "corteza"; + description = "The group to run Corteza under."; + }; + + settings = lib.mkOption { + type = lib.types.submodule { + freeformType = lib.types.attrsOf lib.types.str; + options = { + HTTP_WEBAPP_ENABLED = lib.mkEnableOption "webapps" // { + default = true; + apply = toString; + }; + }; + }; + default = { }; + description = '' + Configuration for Corteza, will be passed as environment variables. + See . + ''; + }; + }; + + config = lib.mkIf cfg.enable { + assertions = [ + { + assertion = !cfg.settings ? HTTP_ADDR; + message = "Use `services.corteza.address` and `services.corteza.port` instead."; + } + ]; + + warnings = lib.optional (!cfg.settings ? DB_DSN) '' + A database connection string is not set. + Corteza will create a temporary SQLite database in memory, but it will not persist data. + For production use, set `services.corteza.settings.DB_DSN`. + ''; + + networking.firewall.allowedTCPPorts = lib.mkIf cfg.openFirewall [ cfg.port ]; + + systemd.services.corteza = { + description = "Corteza"; + documentation = [ "https://docs.cortezaproject.org/" ]; + after = [ "network-online.target" ]; + wants = [ "network-online.target" ]; + wantedBy = [ "multi-user.target" ]; + environment = { + HTTP_WEBAPP_BASE_DIR = "./webapp"; + HTTP_ADDR = "${cfg.address}:${toString cfg.port}"; + } // cfg.settings; + path = [ pkgs.dart-sass ]; + serviceConfig = { + WorkingDirectory = cfg.package; + User = cfg.user; + Group = cfg.group; + ExecStart = "${lib.getExe cfg.package} serve-api"; + }; + }; + + users = { + groups.${cfg.group} = { }; + users.${cfg.user} = { + inherit (cfg) group; + isSystemUser = true; + }; + }; + }; + + meta.maintainers = with lib.maintainers; [ + prince213 + ]; +}