summaryrefslogtreecommitdiffstats
path: root/nixos/modules/services/finance
diff options
context:
space:
mode:
authorMaciej Krüger <mkg20001@gmail.com>2021-11-02 01:45:19 +0100
committerMaciej Krüger <mkg20001@gmail.com>2021-11-03 03:52:41 +0100
commitabc90b4851451e65088da82d7a105d0b01b45e8b (patch)
tree4ba7b7f27e6e549e8da6a06186c77975e14912d4 /nixos/modules/services/finance
parent4a753cd83393a3618d97ec1ef09dbc516886023d (diff)
nixos/odoo: init
Diffstat (limited to 'nixos/modules/services/finance')
-rw-r--r--nixos/modules/services/finance/odoo.nix122
1 files changed, 122 insertions, 0 deletions
diff --git a/nixos/modules/services/finance/odoo.nix b/nixos/modules/services/finance/odoo.nix
new file mode 100644
index 000000000000..3fcb2b3966a5
--- /dev/null
+++ b/nixos/modules/services/finance/odoo.nix
@@ -0,0 +1,122 @@
+{ config, pkgs, lib, ... }:
+
+with lib;
+
+let
+ cfg = config.services.odoo;
+ format = pkgs.formats.ini {};
+in
+{
+ options = {
+ services.odoo = {
+ enable = mkEnableOption "odoo";
+
+ package = mkOption {
+ type = types.package;
+ default = pkgs.odoo;
+ defaultText = literalExpression "pkgs.odoo";
+ description = "Odoo package to use.";
+ };
+
+ addons = mkOption {
+ type = with types; listOf package;
+ default = [];
+ example = literalExpression "[ pkgs.odoo_enterprise ]";
+ description = "Odoo addons";
+ };
+
+ settings = mkOption {
+ type = format.type;
+ default = {};
+ description = ''
+ Odoo configuration settings. For more details see https://www.odoo.com/documentation/15.0/administration/install/deploy.html
+ '';
+ };
+
+ domain = mkOption {
+ type = with types; nullOr str;
+ description = "Domain to host Odoo with nginx";
+ default = null;
+ };
+ };
+ };
+
+ config = mkIf (cfg.enable) (let
+ cfgFile = format.generate "odoo.cfg" cfg.settings;
+ in {
+ services.nginx = mkIf (cfg.domain != null) {
+ upstreams = {
+ odoo.servers = {
+ "127.0.0.1:8069" = {};
+ };
+
+ odoochat.servers = {
+ "127.0.0.1:8072" = {};
+ };
+ };
+
+ virtualHosts."${cfg.domain}" = {
+ extraConfig = ''
+ proxy_read_timeout 720s;
+ proxy_connect_timeout 720s;
+ proxy_send_timeout 720s;
+
+ proxy_set_header X-Forwarded-Host $host;
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+ proxy_set_header X-Forwarded-Proto $scheme;
+ proxy_set_header X-Real-IP $remote_addr;
+ '';
+
+ locations = {
+ "/longpolling" = {
+ proxyPass = "http://odoochat";
+ };
+
+ "/" = {
+ proxyPass = "http://odoo";
+ extraConfig = ''
+ proxy_redirect off;
+ '';
+ };
+ };
+ };
+ };
+
+ services.odoo.settings.options = {
+ proxy_mode = cfg.domain != null;
+ };
+
+ users.users.odoo = {
+ isSystemUser = true;
+ group = "odoo";
+ };
+ users.groups.odoo = {};
+
+ systemd.services.odoo = {
+ wantedBy = [ "multi-user.target" ];
+ after = [ "network.target" "postgresql.service" ];
+
+ # pg_dump
+ path = [ config.services.postgresql.package ];
+
+ requires = [ "postgresql.service" ];
+ script = "HOME=$STATE_DIRECTORY ${cfg.package}/bin/odoo ${optionalString (cfg.addons != []) "--addons-path=${concatMapStringsSep "," escapeShellArg cfg.addons}"} -c ${cfgFile}";
+
+ serviceConfig = {
+ DynamicUser = true;
+ User = "odoo";
+ StateDirectory = "odoo";
+ };
+ };
+
+ services.postgresql = {
+ enable = true;
+
+ ensureUsers = [{
+ name = "odoo";
+ ensurePermissions = { "DATABASE odoo" = "ALL PRIVILEGES"; };
+ }];
+ ensureDatabases = [ "odoo" ];
+ };
+ });
+}