Merge pull request #327729 from zimbatm/odoo-fixes

odoo fixes
This commit is contained in:
Jonas Chevalier
2024-07-19 12:35:03 +02:00
committed by GitHub
3 changed files with 48 additions and 14 deletions
+44 -2
View File
@@ -20,6 +20,17 @@ in
description = "Odoo addons.";
};
autoInit = mkEnableOption "automatically initialize the DB";
autoInitExtraFlags = mkOption {
type = with types; listOf str;
default = [ ];
example = literalExpression /*nix*/ ''
[ "--without-demo=all" ]
'';
description = "Extra flags passed to odoo when run for the first time by autoInit";
};
settings = mkOption {
type = format.type;
default = {};
@@ -84,8 +95,11 @@ in
};
services.odoo.settings.options = {
data_dir = "/var/lib/private/odoo/data";
proxy_mode = cfg.domain != null;
};
} // (lib.optionalAttrs (cfg.addons != []) {
addons_path = concatMapStringsSep "," escapeShellArg cfg.addons;
});
users.users.odoo = {
isSystemUser = true;
@@ -101,12 +115,40 @@ in
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 = {
ExecStart = "${cfg.package}/bin/odoo";
ExecStartPre = pkgs.writeShellScript "odoo-start-pre.sh" (
''
set -euo pipefail
cd "$STATE_DIRECTORY"
# Auto-migrate old deployments
if [[ -d .local/share/Odoo ]]; then
echo "pre-start: migrating state directory from $STATE_DIRECTORY/.local/share/Odoo to $STATE_DIRECTORY/data"
mv .local/share/Odoo ./data
rmdir .local/share
rmdir .local
fi
''
+ (lib.optionalString cfg.autoInit
''
echo "pre-start: auto-init"
INITIALIZED="${cfg.settings.options.data_dir}/.odoo.initialized"
if [ ! -e "$INITIALIZED" ]; then
${cfg.package}/bin/odoo --init=INIT --database=odoo --db_user=odoo --stop-after-init ${concatStringsSep " " cfg.autoInitExtraFlags}
touch "$INITIALIZED"
fi
'')
+ "echo pre-start: OK"
);
DynamicUser = true;
User = "odoo";
StateDirectory = "odoo";
Environment = [
"ODOO_RC=${cfgFile}"
];
};
};
+2 -12
View File
@@ -12,20 +12,10 @@ import ./make-test-python.nix ({ pkgs, lib, package ? pkgs.odoo, ...} : {
services.odoo = {
enable = true;
package = package;
autoInit = true;
autoInitExtraFlags = [ "--without-demo=all" ];
domain = "localhost";
};
# odoo does not automatically initialize its database,
# even if passing what _should_ be the equivalent of these options:
# settings = {
# options = {
# database = "odoo";
# init = "base";
# };
# };
systemd.services.odoo.preStart = ''
HOME=$STATE_DIRECTORY ${package}/bin/odoo -d odoo -i base --stop-after-init --without-demo all
'';
};
};
+2
View File
@@ -52,12 +52,14 @@ in python.pkgs.buildPythonApplication rec {
docutils-0_17 # sphinx has a docutils requirement >= 18
ebaysdk
freezegun
geoip2
gevent
greenlet
idna
jinja2
libsass
lxml
lxml-html-clean
markupsafe
num2words
ofxparse