[Skip to content](#main)

[→](/)

[![Avunu](/brand/avunu-logo.svg)![Avunu](/brand/avunu-logo-light.svg)](/)[Services](/services/)[Consulting](/services/consulting/)[ERP](/services/erp/)[Odoo](/services/erp/odoo/)[ERPNext](/services/erp/erpnext/)[Custom software](/services/custom-software/)[Devices & IoT](/services/devices-iot/)[Websites](/services/websites/)[Infrastructure](/services/infrastructure/)[Partners](/partners/)

[Work](/work/)[Open source](/open-source/)[Knowledge base](/kb/)[About](/about/)

[About Avunu](/about/)[Team](/about/team/)[Insights](/insights/)[Contact](/contact/)

[Client portal](https://erp.avunu.net/projects)[Start a project](/start/)

- [Services](/services/)[Consulting](/services/consulting/)
- [ERP](/services/erp/)
- [Odoo](/services/erp/odoo/)
- [ERPNext](/services/erp/erpnext/)
- [Custom software](/services/custom-software/)
- [Devices & IoT](/services/devices-iot/)
- [Websites](/services/websites/)
- [Infrastructure](/services/infrastructure/)
- [Partners](/partners/)

[Work](/work/)[Open source](/open-source/)[Knowledge base](/kb/)[About](/about/)

- [About Avunu](/about/)
- [Team](/about/team/)
- [Insights](/insights/)
- [Contact](/contact/)

[Client portal](https://erp.avunu.net/projects)[Start a project](/start/)

[Knowledge base](/kb/)[NixOS](/kb/nixos/)Run Odoo as a NixOS service

Search the knowledge basePress/

ESC

Jump to

[Browse the knowledge base](/kb/)[Frappe](/kb/frappe/)[ERPNext](/kb/erpnext/)[Odoo](/kb/odoo/)[WordPress](/kb/wordpress/)[NixOS](/kb/nixos/)[Email](/kb/email/)[Linux](/kb/linux/)[Databases](/kb/databases/)[Containers](/kb/containers/)[Proxmox](/kb/proxmox/)[Git & Dev Tools](/kb/git-and-dev-tools/)

↵select↑↓navigateescclose

Search the knowledge base

[Skip to the article](#kb-article)[NixOS](/kb/nixos/)13 articles

- [Overview](/kb/nixos/)
- [A NixOS micro desktop for family and friends](/kb/nixos/nixos-micro-desktop-for-family-and-friends/)
- [Add OCA modules to an odoo-nix project](/kb/nixos/adding-oca-modules-with-odoo-nix/)
- [Build a Firefox web kiosk USB drive with web_kiosk](/kb/nixos/building-a-web-kiosk-usb-with-web-kiosk/)
- [Build production images with frappe-nix](/kb/nixos/building-production-images-with-frappe-nix/)
- [Mount and sync cloud storage on NixOS with nixos-rclone](/kb/nixos/mounting-cloud-storage-with-nixos-rclone/)
- [Reference architecture for self-hosting business systems on NixOS](/kb/nixos/reference-architecture-for-self-hosting-business-systems/)
- [Run Frappe as a NixOS service](/kb/nixos/running-frappe-as-a-nixos-service/)
- [Run Odoo as a NixOS service](/kb/nixos/running-odoo-as-a-nixos-service/)
- [Run WordPress on FrankenPHP with wordpress-nix](/kb/nixos/wordpress-on-frankenphp-with-wordpress-nix/)
- [Set up a reproducible Frappe development environment with frappe-nix](/kb/nixos/frappe-dev-environment-with-frappe-nix/)
- [Set up an Odoo and OCA development environment with odoo-nix](/kb/nixos/odoo-dev-environment-with-odoo-nix/)
- [Why Nix for business systems](/kb/nixos/why-nix-for-business-systems/)
- [WordPress performance and hardening on Nix](/kb/nixos/wordpress-performance-and-hardening-on-nix/)

Other sections[Frappe](/kb/frappe/)[ERPNext](/kb/erpnext/)[Odoo](/kb/odoo/)[WordPress](/kb/wordpress/)[Email](/kb/email/)[Linux](/kb/linux/)[Databases](/kb/databases/)[Containers](/kb/containers/)[Proxmox](/kb/proxmox/)[Git & Dev Tools](/kb/git-and-dev-tools/)

In NixOS: 13 articles

[Overview](/kb/nixos/)[A NixOS micro desktop for family and friends](/kb/nixos/nixos-micro-desktop-for-family-and-friends/)[Add OCA modules to an odoo-nix project](/kb/nixos/adding-oca-modules-with-odoo-nix/)[Build a Firefox web kiosk USB drive with web_kiosk](/kb/nixos/building-a-web-kiosk-usb-with-web-kiosk/)[Build production images with frappe-nix](/kb/nixos/building-production-images-with-frappe-nix/)[Mount and sync cloud storage on NixOS with nixos-rclone](/kb/nixos/mounting-cloud-storage-with-nixos-rclone/)[Reference architecture for self-hosting business systems on NixOS](/kb/nixos/reference-architecture-for-self-hosting-business-systems/)[Run Frappe as a NixOS service](/kb/nixos/running-frappe-as-a-nixos-service/)[Run Odoo as a NixOS service](/kb/nixos/running-odoo-as-a-nixos-service/)[Run WordPress on FrankenPHP with wordpress-nix](/kb/nixos/wordpress-on-frankenphp-with-wordpress-nix/)[Set up a reproducible Frappe development environment with frappe-nix](/kb/nixos/frappe-dev-environment-with-frappe-nix/)[Set up an Odoo and OCA development environment with odoo-nix](/kb/nixos/odoo-dev-environment-with-odoo-nix/)[Why Nix for business systems](/kb/nixos/why-nix-for-business-systems/)[WordPress performance and hardening on Nix](/kb/nixos/wordpress-performance-and-hardening-on-nix/)

Other sections[Frappe](/kb/frappe/)[ERPNext](/kb/erpnext/)[Odoo](/kb/odoo/)[WordPress](/kb/wordpress/)[Email](/kb/email/)[Linux](/kb/linux/)[Databases](/kb/databases/)[Containers](/kb/containers/)[Proxmox](/kb/proxmox/)[Git & Dev Tools](/kb/git-and-dev-tools/)

NixOSRun Odoo as a NixOS service

Deploy Odoo on NixOS with the odoo-nix services.odoo-nix module, covering PostgreSQL, nginx, secrets, migrations on deploy, backups, restores and logs.

UpdatedOct 5, 2026

Applies toodoo-nix services.odoo-nixOdoo 18.0Odoo 19.0

Tagsnixosodoodeploymentsystemd

Reading time14 min

On this page[What the module sets up](#what-the-module-sets-up)[How secrets stay out of the Nix store](#how-secrets-stay-out-of-the-nix-store)[Deploy the module](#deploy-the-module)[Options you will use most](#options-you-will-use-most)[PostgreSQL](#postgresql)[A local database](#a-local-database)[A remote database](#a-remote-database)[Several databases](#several-databases)[nginx](#nginx)[Socket mode behind a tunnel connector](#socket-mode-behind-a-tunnel-connector)[Migrations on deploy](#migrations-on-deploy)[Tuning the migration](#tuning-the-migration)[Recovering from a failed migration](#recovering-from-a-failed-migration)[Backups and restores](#backups-and-restores)[Running the odoo command on the host](#running-the-odoo-command-on-the-host)[Back up](#back-up)[Restore](#restore)[Logging](#logging)[Fields to filter on](#fields-to-filter-on)[Priorities and request logs](#priorities-and-request-logs)[Other logging options](#other-logging-options)[Upgrading](#upgrading)[Running Odoo in a container](#running-odoo-in-a-container)[Related documents](#related-documents)

This document explains how to run a production Odoo (OCB plus OCA modules) on a NixOS host using the `services.odoo-nix` module from [odoo-nix](https://github.com/Avunu/odoo-nix). Use it when you already have an odoo-nix project flake and want to deploy it, keep its database in step with the code, back it up and read its logs.

The module runs one Odoo instance per host. You can still serve several databases from that instance with a database filter.

## What the module sets up

Enabling the module creates three systemd units, an `odoo` system user, and a state directory.

| Unit                   | Type                  | What it does                                                                                              |
| ---------------------- | --------------------- | --------------------------------------------------------------------------------------------------------- |
| `odoo-init.service`    | oneshot, stays active | Writes the runtime `odoo.conf` and merges in secrets.                                                     |
| `odoo-migrate.service` | oneshot               | Brings the database schema in line with the code before every start of Odoo.                              |
| `odoo.service`         | long running          | Runs `odoo -c /var/lib/odoo/odoo.conf` as the `odoo` user and restarts it after five seconds if it exits. |

Odoo keeps its state in `/var/lib/odoo` (the `stateDir` option). The runtime config is `/var/lib/odoo/odoo.conf` and the data directory, which holds the filestore and the default backup location, is `/var/lib/odoo/data`.

### How secrets stay out of the Nix store

A base `odoo.conf` without secrets is generated into the Nix store. At boot, `odoo-init` copies it to `/var/lib/odoo/odoo.conf` with mode `0600`, then appends `db_password` and `admin_passwd` from the files you point at. The secret values never enter `/nix/store`, and the file is readable only by the `odoo` user.

## Deploy the module

You need a project flake built with odoo-nix. Its `packages.<system>.default` output is the assembled Odoo wrapped with the `odoo` command line tool, and that is what the module expects as `package`.

Warning

Point `package` at `packages.default`, not at the raw `builtOdoo` tree. The raw tree has no `odoo db migrate`, and the module refuses to evaluate with migrations enabled unless you pass the CLI package.

Import the module and configure it in your host's NixOS configuration:

```
<span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">{</span>
<span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">  </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">imports</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E">=</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> [ </span><span style="--shiki-dark:#FFA657;--shiki-light:#953800">odoo-nix</span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E">.</span><span style="--shiki-dark:#FFA657;--shiki-light:#953800">nixosModules</span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E">.</span><span style="--shiki-dark:#FFA657;--shiki-light:#953800">default</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> ];</span>

<span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">  </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">services</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">.</span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">odoo-nix</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E">=</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> {</span>
<span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">    </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">enable</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E">=</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">true</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">;</span>
<span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">    </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">package</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E">=</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#FFA657;--shiki-light:#953800">projectFlake</span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E">.</span><span style="--shiki-dark:#FFA657;--shiki-light:#953800">packages</span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E">.</span><span style="--shiki-dark:#FFA657;--shiki-light:#953800">x86_64-linux</span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E">.</span><span style="--shiki-dark:#FFA657;--shiki-light:#953800">default</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">;</span>
<span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">    </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">dbName</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E">=</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">"acme"</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">;</span>
<span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">    </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">database</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">.</span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">createLocally</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E">=</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">true</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">;</span>
<span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">    </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">adminPasswordFile</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E">=</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">"/run/secrets/odoo-admin"</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">;</span>
<span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">    </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">workers</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E">=</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">4</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">;</span>
<span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">    </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">nginx</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E">=</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> {</span>
<span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">      </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">enable</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E">=</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">true</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">;</span>
<span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">      </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">domain</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E">=</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">"erp.example.com"</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">;</span>
<span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">    };</span>
<span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">  };</span>
<span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">}</span>
```

Then rebuild and check that the units came up:

```
<span style="--shiki-dark:#FFA657;--shiki-light:#953800">sudo</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">nixos-rebuild</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">switch</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">--flake</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">.#</span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E"><</span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">HOST_NAM</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">E</span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E">></span>
<span style="--shiki-dark:#FFA657;--shiki-light:#953800">systemctl</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">status</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">odoo-init</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">odoo-migrate</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">odoo</span>
```

`odoo-migrate` shows as inactive after a successful run, because it is a oneshot unit that does not stay active. That is expected.

### Options you will use most

| Option                 | Default         | Purpose                                                                                                               |
| ---------------------- | --------------- | --------------------------------------------------------------------------------------------------------------------- |
| `package`              | none, required  | The project flake's `packages.default`.                                                                               |
| `dbName`               | `null`          | Pins the instance to one database (sets `db_name` and `dbfilter` to `^<name>$`).                                      |
| `dbFilter`             | `""`            | Explicit `dbfilter` regex for several databases. Overrides the one `dbName` sets.                                     |
| `listDb`               | `false`         | Allows the database manager and database listing.                                                                     |
| `workers`              | `2`             | HTTP worker processes. `0` runs threaded, anything above enables multiprocess mode plus the gevent websocket process. |
| `maxCronThreads`       | `2`             | Cron threads.                                                                                                         |
| `http.port`            | `8069`          | HTTP port.                                                                                                            |
| `http.longpollingPort` | `8072`          | Websocket (gevent) port.                                                                                              |
| `http.interface`       | `127.0.0.1`     | Bind address. Keep it on loopback behind nginx.                                                                       |
| `adminPasswordFile`    | `null`          | File holding the database manager master password.                                                                    |
| `withoutDemo`          | `false`         | Skips demo data for every module.                                                                                     |
| `settings`             | `{ }`           | Extra `[options]` keys for `odoo.conf`. No secrets here, because it lands in the Nix store.                           |
| `extraEnv`             | `{ }`           | Extra environment variables for the Odoo units.                                                                       |
| `stateDir`             | `/var/lib/odoo` | Where the runtime config and data directory live.                                                                     |

Set `adminPasswordFile`. Without it, `odoo-init` writes no `admin_passwd` line at all.

## PostgreSQL

You have two choices: let the module run PostgreSQL on the same host, or point it at a server you manage.

### A local database

With `database.createLocally = true`, the module enables `services.postgresql`, creates the database named by `dbName`, and creates a PostgreSQL role (`database.user`, default `odoo`) with `createdb`. When `database.passwordFile` is unset, Odoo connects over the local unix socket using peer authentication, so there is no password to manage and no `db_host` or `db_port` in the config.

The role is not a superuser. That matters for ownership and for extensions:

If `dbName` matches the role name, the module uses NixOS's `ensureDBOwnership`. If the names differ, it runs `ALTER DATABASE ... OWNER TO` after the database is created, so the Odoo role still owns it.

A module that tries to create an untrusted extension in its install hook will fail as this role. Declare the extension in the module instead: `database.extensions` builds it into the server (for example `ps: [ ps.postgis ]`), and `database.ensureExtensions` runs `CREATE EXTENSION IF NOT EXISTS` for each name in `dbName` as the `postgres` superuser. Both need `createLocally`, and `ensureExtensions` also needs a pinned `dbName`.

The units order themselves after `postgresql.target`, so the migration does not race the role creation.

### A remote database

Leave `createLocally` off and set `database.host`, `database.port` (default `5432`), `database.user` and `database.passwordFile`. The password file is merged into `odoo.conf` by `odoo-init`. The module creates nothing on a remote server, so the role and database must exist before the first start.

### Several databases

Leave `dbName` unset and set `dbFilter` to a regex that matches your databases. Some options need a pinned `dbName` and fail evaluation without one: `update`, `autoInit`, and `database.ensureExtensions`. With no pinned database, migrations run against every database that matches the filter (`--all`).

## nginx

Set `nginx.enable = true` to get a reverse proxy in front of Odoo. The module also turns on Odoo's `proxy_mode` when nginx is enabled. The vhost proxies these paths:

`/` to the HTTP port.

`/websocket` and `/longpolling` to the gevent port, with websocket upgrade handling.

Paths matching `/web/static/` to the HTTP port, with caching and a ten-day `expires`.

You must provide `nginx.domain` (the vhost name) unless you use socket mode. The request body limit is `nginx.clientMaxBodySize`, default `64m`, scoped to this vhost only so other sites on the host keep their own limit.

Note

The module does not enable TLS. In the default TCP mode it forwards `X-Forwarded-Proto` from the scheme nginx sees, so terminate TLS on this nginx with the usual NixOS vhost options (`services.nginx.virtualHosts."erp.example.com"`), or Odoo will build `http` links.

### Socket mode behind a tunnel connector

If a co-located reverse proxy or tunnel connector terminates TLS for you, set `nginx.socketPath` to a unix socket path such as `/run/odoo/nginx.sock`. Then nginx listens on the socket instead of a TCP port, and you no longer need `nginx.domain`.

Socket mode changes three things:

The public scheme is assumed to be `https`, so `X-Forwarded-Proto` is fixed to `https`.

Because a unix socket has no peer address, the client IP is read from the `CF-Connecting-IP` header. Only use this mode when the connector in front of the socket sets that header.

nginx sets its own socket to world-writable, so the socket file does not restrict access. The module creates the containing directory with mode `0770`, owned by the Odoo user and group, and adds the `nginx` user to that group. The directory is the real access control, so the path must sit inside its own directory (not directly in `/run`).

Odoo itself always stays on loopback TCP. Its server layer cannot bind a unix socket.

## Migrations on deploy

The schema follows the code automatically. Odoo only creates columns, loads views and runs migration scripts for modules that are installed or updated, so shipping new module code without an update leaves the database quietly behind the code. `odoo-migrate.service` closes that gap.

It runs before every start of `odoo.service`. Because it has no `RemainAfterExit`, it goes inactive when done, and `odoo.service` both requires it and orders itself after it. In practice:

**A deploy** stops Odoo, migrates exactly the modules whose code or manifest version changed, then starts Odoo. Nothing touches the database mid-update.

**A restart of the same build** (reboot, `systemctl restart odoo`, a crash) costs one database query and changes nothing.

**A restored dump** is migrated on the next start, because the "last migrated by" marker lives in the database and a dump from elsewhere carries a different marker or none.

**A failed migration** is rolled back from its snapshot, and `odoo.service` does not start. Odoo stays down on purpose, because new code on an old schema fails in ways nothing reports.

The unit runs `odoo db migrate` with `--if-needed`, a `dump` snapshot, `--keep` set to your retention and `--rollback`. The first run on a database with no recorded checksums updates every module once to set the baseline, which can take many minutes on a large database.

### Tuning the migration

| Option                      | Default    | Effect                                                                                                              |
| --------------------------- | ---------- | ------------------------------------------------------------------------------------------------------------------- |
| `migrate.enable`            | `true`     | Run the migration before each start.                                                                                |
| `migrate.full`              | `false`    | Update every installed module on each new build, not only changed ones.                                             |
| `migrate.snapshot`          | `true`     | Take a `pg_dump` snapshot first.                                                                                    |
| `migrate.rollbackOnFailure` | `true`     | Restore the snapshot if the update fails. Needs `migrate.snapshot`.                                                 |
| `migrate.snapshotRetention` | `3`        | Snapshots kept per database.                                                                                        |
| `migrate.timeout`           | `infinity` | `TimeoutStartSec` for the unit. Killing a migration part way leaves a half-updated schema for the rollback to undo. |
| `update`                    | `[ ]`      | Modules to update on every deploy even when unchanged. Needs a pinned `dbName`.                                     |
| `autoInit`                  | `false`    | Install `base` into an empty pinned database on first boot.                                                         |

Snapshots live in `/var/lib/odoo/data/backups/<DB_NAME>/premigrate/`, separate from regular backups so retention never prunes a backup you took on purpose. They hold the database only. The filestore is left alone, because attachments are content-addressed and only ever added.

With `autoInit` off, an empty database is skipped and Odoo still starts, which is what you want when you plan to restore a dump into it. With `autoInit` on, the migration unit passes `--provision-if-empty` and installs `base`. The provisioning step also reads a `modules.txt` from its working directory, which is `/var/lib/odoo`, and installs the modules listed there. The module does not create that file for you.

Setting `migrate.enable = false` falls back to the older behavior: `autoInit` installs `base` once and `update` runs `odoo db upgrade` on every start, with no change detection and no snapshot.

### Recovering from a failed migration

Read the log first:

```
<span style="--shiki-dark:#FFA657;--shiki-light:#953800">journalctl</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">-u</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">odoo-migrate.service</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">--no-pager</span>
```

Then fix the code and deploy again, or roll the system back to the previous generation. The database has already been restored from the snapshot, so the previous generation's code matches it.

## Backups and restores

The module does not schedule backups. It ships the `odoo` command with backup and restore subcommands, and you run them yourself or from a timer you define.

### Running the odoo command on the host

The module does not put `odoo` on your PATH. Run it as the `odoo` user (the runtime config is `0600`) and give it the config file. Find the package path in the unit's `ExecStart` line:

```
<span style="--shiki-dark:#FFA657;--shiki-light:#953800">systemctl</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">cat</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">odoo.service</span>
```

Then run commands like this, replacing `<ODOO_PACKAGE>` with the store path from `ExecStart`:

```
<span style="--shiki-dark:#FFA657;--shiki-light:#953800">sudo</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">-u</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">odoo</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E"><</span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">ODOO_PACKAG</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">E</span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E">></span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">/bin/odoo</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">-c</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">/var/lib/odoo/odoo.conf</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">db</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">list</span>
```

`-c` and `-d` are accepted before the subcommand. The backup and restore tools need the PostgreSQL client programs (`pg_dump` and friends) on the PATH of the shell you run from. The systemd units get them automatically, an interactive shell may not.

### Back up

`db backup` writes to `<data_dir>/backups/<DB_NAME>/` by default, which is `/var/lib/odoo/data/backups/<DB_NAME>/` here:

```
<span style="--shiki-dark:#FFA657;--shiki-light:#953800">sudo</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">-u</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">odoo</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E"><</span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">ODOO_PACKAG</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">E</span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E">></span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">/bin/odoo</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">-c</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">/var/lib/odoo/odoo.conf</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">db</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">backup</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E"><</span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">DB_NAM</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">E</span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E">></span>
```

Useful flags:

`--all` backs up every database that matches `dbfilter`.

`--path DIR` changes the destination directory.

`--format zip|dump` picks the format. `zip` (the default) is Odoo's own Database Manager format with the filestore included. `dump` is a plain `pg_dump` custom-format file with no filestore.

`--keep-days N` deletes older backups for that database. The default `0` keeps everything.

Files are named by timestamp (`YYYY_MM_DD_HH_MM_SS.dump.zip`, or `.dump`), with no database name in the file name because the folder carries it. That is the same convention as the OCA `auto_backup` module, so backups from either tool can share a folder.

To back up every database at once without naming them, use `project backup`. It takes the same `--format`, `--path` and `--keep-days` flags and writes each database into its own subfolder:

```
<span style="--shiki-dark:#FFA657;--shiki-light:#953800">sudo</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">-u</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">odoo</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E"><</span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">ODOO_PACKAG</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">E</span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E">></span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">/bin/odoo</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">-c</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">/var/lib/odoo/odoo.conf</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">project</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">backup</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">--keep-days</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">14</span>
```

Warning

The pre-migration snapshot is a database-only dump. A `dump` backup has no filestore either. If you need to recover attachments, keep `zip` backups, and copy them off the host.

### Restore

Stop Odoo first so nothing holds the database open:

```
<span style="--shiki-dark:#FFA657;--shiki-light:#953800">sudo</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">systemctl</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">stop</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">odoo.service</span>
```

Then restore a backup into a database name. `--force` drops the database first if it already exists, and `--neutralize` disables outgoing mail and cron on the restored copy, which you want when restoring production data somewhere else:

```
<span style="--shiki-dark:#FFA657;--shiki-light:#953800">sudo</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">-u</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">odoo</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E"><</span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">ODOO_PACKAG</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">E</span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E">></span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">/bin/odoo</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">-c</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">/var/lib/odoo/odoo.conf</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">db</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">restore</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E"><</span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">DB_NAM</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">E</span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E">></span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E"><</span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">BACKUP_PAT</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">H</span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E">></span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">--force</span>
```

Start Odoo again. The migration unit runs first and brings the restored database up to the code in this build:

```
<span style="--shiki-dark:#FFA657;--shiki-light:#953800">sudo</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">systemctl</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">start</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">odoo.service</span>
```

To restore several databases in one command, repeat `--restore DB PATH` with `project restore`. You name each file explicitly, because there is no latest-backup lookup.

Note

This document does not cover restoring a `premigrate` snapshot by hand. The automatic rollback uses it for you. For manual recovery, restore from a `zip` backup.

## Logging

Everything goes to the journal. There are no log files unless you ask for one.

### Fields to filter on

Every unit the module defines or enables carries two journal fields: `APP_SERVICE`, the role, and `APP_SITE`, the pinned `dbName`. With no pinned `dbName`, `APP_SITE` is omitted.

| `APP_SERVICE` | Unit                                                      |
| ------------- | --------------------------------------------------------- |
| `web`         | `odoo.service`                                            |
| `migrate`     | `odoo-migrate.service`                                    |
| `init`        | `odoo-init.service`                                       |
| `db`          | `postgresql` and `postgresql-setup`, with `createLocally` |
| `nginx`       | `nginx`, with `nginx.enable`                              |

The Odoo units also have fixed `SyslogIdentifier` values: `odoo`, `odoo-migrate` and `odoo-init`. Some queries you will use often:

```
<span style="--shiki-dark:#FFA657;--shiki-light:#953800">journalctl</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">APP_SITE=</span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E"><</span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">DB_NAM</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">E</span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E">></span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">-p</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">warning</span>
<span style="--shiki-dark:#FFA657;--shiki-light:#953800">journalctl</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">APP_SERVICE=migrate</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">APP_SITE=</span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E"><</span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">DB_NAM</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">E</span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E">></span>
<span style="--shiki-dark:#FFA657;--shiki-light:#953800">journalctl</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">-u</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">odoo</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">-f</span>
```

### Priorities and request logs

With `logging.journald` (on by default), Odoo's records reach the journal with their real syslog priority, on every line of a record including tracebacks, so `-p warning` filters correctly. This only applies when `logging.file` is null and `settings` sets neither `logfile` nor `syslog`.

With `logging.accessLog` (on by default and only with `nginx.enable`), nginx writes one JSON object per request to the journal under `SYSLOG_IDENTIFIER=nginx_access`. Fields are `time`, `site`, `method`, `uri`, `status`, `bytes`, `request_time`, `upstream_time`, `remote_addr`, `user_agent` and `referer`:

```
<span style="--shiki-dark:#FFA657;--shiki-light:#953800">journalctl</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">SYSLOG_IDENTIFIER=nginx_access</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">-o</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">cat</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E">|</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#FFA657;--shiki-light:#953800">jq</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">'select(.status >= 500)'</span>
```

### Other logging options

`logging.level` sets the root level (default `info`) and `logging.handlers` takes per-logger overrides such as `werkzeug:WARNING`.

`logging.slowQueryMs` logs PostgreSQL statements that run at least that many milliseconds. It only applies with `createLocally`. Local PostgreSQL log lines are prefixed with database and role.

`logging.file` writes to a file instead. Odoo's file and stderr handlers are mutually exclusive, so the journal then sees almost nothing from Odoo, and the module prints a warning. `logging.rotate` wires up `logrotate` for that file. Prefer the journal under systemd.

## Upgrading

An upgrade is a normal NixOS deploy. Update the code in your project repository (OCB, OCA submodules, your own modules), rebuild the project flake, and switch:

```
<span style="--shiki-dark:#FFA657;--shiki-light:#953800">nix</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">flake</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">update</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E"><</span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">PROJECT_INPU</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">T</span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E">></span>
<span style="--shiki-dark:#FFA657;--shiki-light:#953800">sudo</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">nixos-rebuild</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">switch</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">--flake</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">.#</span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E"><</span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">HOST_NAM</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">E</span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E">></span>
```

When the switch replaces the Odoo unit, systemd stops Odoo, runs `odoo-migrate`, and starts the new build. Check the result with `journalctl APP_SERVICE=migrate APP_SITE=<DB_NAME>`. The migration prints its plan before it runs, so you can see which modules it updates and why.

The `odoo module add` and `odoo project update` commands are for the development shell only. A deployment built into `/nix/store` has no git checkout or `modules.txt`, and they fail with a clear message there.

To roll back a bad release, switch to the previous generation. If the migration had already failed, the database was restored from its snapshot, so the old code still matches it.

## Running Odoo in a container

The same project can build an OCI image. Set `odoo-nix.containers.enable = true` in the project flake to get `packages.<system>.container-odoo`, a single image that runs HTTP workers, gevent and cron. PostgreSQL stays external.

The image builds `/etc/odoo/odoo.conf` at start from environment variables. These are the main variables the entrypoint reads. It also reads `ODOO_LOG_HANDLER` and `ODOO_LOG_DB`, which are left out of the config when unset, and `ODOO_LOG_DB_LEVEL`, which defaults to `warning`.

| Variable                                 | Default                      |
| ---------------------------------------- | ---------------------------- |
| `ODOO_DB_HOST`                           | `db`                         |
| `ODOO_DB_PORT`                           | `5432`                       |
| `ODOO_DB_USER`                           | `odoo`                       |
| `ODOO_DB_NAME`                           | unset (also sets `dbfilter`) |
| `ODOO_HTTP_PORT` / `ODOO_GEVENT_PORT`    | `8069` / `8072`              |
| `ODOO_WORKERS` / `ODOO_MAX_CRON_THREADS` | `2` / `2`                    |
| `ODOO_PROXY_MODE`                        | `True`                       |
| `ODOO_LIST_DB` / `ODOO_WITHOUT_DEMO`     | `False` / `False`            |
| `ODOO_LOG_LEVEL`                         | `info`                       |

Mount the persistent filestore at `/var/lib/odoo/data`. Secrets come from mounted files: `/secrets/db_password`, `/secrets/admin_passwd`, and any `/secrets/*.conf`, which is appended to the config.

Warning

The container does not run migrations on start. Its entrypoint launches Odoo directly. After deploying a new image, run `odoo db migrate <DB_NAME>` yourself inside the container.

The `odoo` command in the image works the same way as on the host, and `ODOO_RC` is already set, so `docker exec <CONTAINER> odoo db backup <DB_NAME>` needs no `-c` flag.

## Related documents

[Odoo Development Environment with odoo-nix](/kb/nixos/odoo-dev-environment-with-odoo-nix/), for creating the project flake this module deploys.

[Adding OCA Modules with odoo-nix](/kb/nixos/adding-oca-modules-with-odoo-nix/), for choosing the modules that go into it.

[Reference Architecture for Self-Hosting Business Systems](/kb/nixos/reference-architecture-for-self-hosting-business-systems/), for running Odoo behind a tunnel on a small fleet of NixOS hosts.

Sources

- [github.com/Avunu/odoo-nix](https://github.com/Avunu/odoo-nix)
- [github.com/Avunu/odoo-nix/blob/main/modules/nixos.nix](https://github.com/Avunu/odoo-nix/blob/main/modules/nixos.nix)
- [github.com/Avunu/odoo-nix/blob/main/modules/containers.nix](https://github.com/Avunu/odoo-nix/blob/main/modules/containers.nix)

Need help with NixOS?

Our notes can take you a long way, but sometimes you'd rather have someone who's done it before.

[Managed infrastructure](/services/infrastructure/)

[← PreviousRun Frappe as a NixOS service](/kb/nixos/running-frappe-as-a-nixos-service/)[Next →Run WordPress on FrankenPHP with wordpress-nix](/kb/nixos/wordpress-on-frankenphp-with-wordpress-nix/)

CC0This article is in the public domain ([CC0 1.0](https://creativecommons.org/publicdomain/zero/1.0/)), code samples included. Use it however helps you.

On this page

- [What the module sets up](#what-the-module-sets-up)
- [How secrets stay out of the Nix store](#how-secrets-stay-out-of-the-nix-store)
- [Deploy the module](#deploy-the-module)
- [Options you will use most](#options-you-will-use-most)
- [PostgreSQL](#postgresql)
- [A local database](#a-local-database)
- [A remote database](#a-remote-database)
- [Several databases](#several-databases)
- [nginx](#nginx)
- [Socket mode behind a tunnel connector](#socket-mode-behind-a-tunnel-connector)
- [Migrations on deploy](#migrations-on-deploy)
- [Tuning the migration](#tuning-the-migration)
- [Recovering from a failed migration](#recovering-from-a-failed-migration)
- [Backups and restores](#backups-and-restores)
- [Running the odoo command on the host](#running-the-odoo-command-on-the-host)
- [Back up](#back-up)
- [Restore](#restore)
- [Logging](#logging)
- [Fields to filter on](#fields-to-filter-on)
- [Priorities and request logs](#priorities-and-request-logs)
- [Other logging options](#other-logging-options)
- [Upgrading](#upgrading)
- [Running Odoo in a container](#running-odoo-in-a-container)
- [Related documents](#related-documents)

[Back to top↑](#top)

Services

- [ERP implementation](/services/erp/)
- [Odoo](/services/erp/odoo/)
- [ERPNext](/services/erp/erpnext/)
- [Custom software](/services/custom-software/)
- [Devices & IoT](/services/devices-iot/)
- [Websites](/services/websites/)
- [Infrastructure](/services/infrastructure/)

Resources

- [Our work](/work/)
- [Open source](/open-source/)
- [Knowledge base](/kb/)
- [Insights](/insights/)

Company

- [About](/about/)
- [Team](/about/team/)
- [Partners](/partners/)
- [Contact](/contact/)

Clients

- [Project portal](https://erp.avunu.net/projects)
- [Invoices](https://erp.avunu.net/)
- [Support](https://erp.avunu.net/)

[![Avunu](/brand/avunu-logo-light.svg)](/)[\<av-icon data-jx-static>\<svg viewBox="0 0 24 24" width="20" height="20" fill="currentColor" stroke="none" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false">\<path d="M20.400 20.500h-3.600v-5.600c0-1.300 0-3-1.800-3s-2.100 1.400-2.100 2.900v5.700H9.400V9h3.400v1.600c.5-.9 1.600-1.900 3.400-1.900 3.600 0 4.300 2.400 4.300 5.500v6.300zM5.300 7.400a2.100 2.100 0 1 1 0-4.100 2.100 2.100 0 0 1 0 4.100zm1.800 13.100H3.600V9h3.500v11.500zM22.200 0H1.800C.8 0 0 .8 0 1.700v20.600c0 .9.800 1.700 1.800 1.700h20.400c1 0 1.800-.8 1.800-1.700V1.700C24 .8 23.200 0 22.200 0z">\</path>\</svg>\</av-icon>](https://www.linkedin.com/company/avunu)[\<av-icon data-jx-static>\<svg viewBox="0 0 24 24" width="20" height="20" fill="currentColor" stroke="none" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false">\<path d="M12 .3a12 12 0 0 0-3.8 23.4c.6.1.8-.3.8-.6v-2c-3.3.7-4-1.6-4-1.6-.6-1.4-1.4-1.8-1.4-1.8-1-.7.1-.7.1-.7 1.2.1 1.8 1.2 1.8 1.2 1 1.8 2.8 1.3 3.5 1 .1-.8.4-1.3.7-1.6-2.7-.3-5.5-1.3-5.5-5.9 0-1.3.5-2.4 1.2-3.2-.1-.3-.5-1.5.1-3.2 0 0 1-.3 3.3 1.2a11.500 11.500 0 0 1 6 0c2.300-1.500 3.300-1.200 3.300-1.200.6 1.700.2 2.900.1 3.200.8.8 1.200 1.900 1.200 3.200 0 4.600-2.800 5.600-5.500 5.900.4.400.8 1.100.8 2.200v3.300c0 .3.2.7.8.6A12 12 0 0 0 12 .3">\</path>\</svg>\</av-icon>](https://github.com/Avunu)[Client portal](https://erp.avunu.net/projects)[Start a project](/start/)

Avunu LLC · 948 East Philadelphia Street, York, PA 17403 · (717) 814-8540Knowledge base articles are in the public domain[Privacy](/privacy/)[Terms](/terms/)
