8 cfg = config.services.odoo;
9 format = pkgs.formats.ini { };
14 enable = lib.mkEnableOption "odoo, an open source ERP and CRM system";
16 package = lib.mkPackageOption pkgs "odoo" { };
18 addons = lib.mkOption {
19 type = with lib.types; listOf package;
21 example = lib.literalExpression "[ pkgs.odoo_enterprise ]";
22 description = "Odoo addons.";
25 autoInit = lib.mkEnableOption "automatically initialize the DB";
27 autoInitExtraFlags = lib.mkOption {
28 type = with lib.types; listOf str;
31 lib.literalExpression # nix
33 [ "--without-demo=all" ]
35 description = "Extra flags passed to odoo when run for the first time by autoInit";
38 settings = lib.mkOption {
42 Odoo configuration settings. For more details see <https://www.odoo.com/documentation/15.0/administration/install/deploy.html>
44 example = lib.literalExpression ''
52 domain = lib.mkOption {
53 type = with lib.types; nullOr str;
54 description = "Domain to host Odoo with nginx";
60 config = lib.mkIf (cfg.enable) (
62 cfgFile = format.generate "odoo.cfg" cfg.settings;
65 services.nginx = lib.mkIf (cfg.domain != null) {
68 "127.0.0.1:8069" = { };
72 "127.0.0.1:8072" = { };
76 virtualHosts."${cfg.domain}" = {
78 proxy_read_timeout 720s;
79 proxy_connect_timeout 720s;
80 proxy_send_timeout 720s;
82 proxy_set_header X-Forwarded-Host $host;
83 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
84 proxy_set_header X-Forwarded-Proto $scheme;
85 proxy_set_header X-Real-IP $remote_addr;
90 proxyPass = "http://odoochat";
94 proxyPass = "http://odoo";
103 services.odoo.settings.options =
105 data_dir = "/var/lib/private/odoo/data";
106 proxy_mode = cfg.domain != null;
108 // (lib.optionalAttrs (cfg.addons != [ ]) {
109 addons_path = lib.concatMapStringsSep "," lib.escapeShellArg cfg.addons;
116 users.groups.odoo = { };
118 systemd.services.odoo = {
119 wantedBy = [ "multi-user.target" ];
126 path = [ config.services.postgresql.package ];
128 requires = [ "postgresql.service" ];
131 ExecStart = "${cfg.package}/bin/odoo";
132 ExecStartPre = pkgs.writeShellScript "odoo-start-pre.sh" (
136 cd "$STATE_DIRECTORY"
138 # Auto-migrate old deployments
139 if [[ -d .local/share/Odoo ]]; then
140 echo "pre-start: migrating state directory from $STATE_DIRECTORY/.local/share/Odoo to $STATE_DIRECTORY/data"
141 mv .local/share/Odoo ./data
146 + (lib.optionalString cfg.autoInit ''
147 echo "pre-start: auto-init"
148 INITIALIZED="${cfg.settings.options.data_dir}/.odoo.initialized"
149 if [ ! -e "$INITIALIZED" ]; then
150 ${cfg.package}/bin/odoo --init=INIT --database=odoo --db_user=odoo --stop-after-init ${lib.concatStringsSep " " cfg.autoInitExtraFlags}
154 + "echo pre-start: OK"
158 StateDirectory = "odoo";
165 services.postgresql = {
168 ensureDatabases = [ "odoo" ];
172 ensureDBOwnership = true;