This repository provides a Nix flake-based development environment for Odoo 18, ensuring a reproducible and consistent setup across different machines. It includes all necessary system dependencies, Python packages, and frontend compilation tools (like sassc, less, and rtlcss) to get Odoo running smoothly on NixOS.
It is assumed you have already cloned the Odoo 18 source code into the odoo/ directory.
git clone -b 18 https://github.com/odoo/odoo.git
This project uses a Nix flake to provide a reproducible development environment. It includes:
- Python 3.12 and its packages (from
odoo-requirements.txt) - PostgreSQL 16 (managed by Nix)
- Frontend compilation tools:
nodejs,less,rtlcss,sassc, andlibsass. justcommand runner for simplified development workflows.
To activate the development environment, run:
nix developThis will drop you into a shell with all the necessary system and Python dependencies, and ensure the frontend compilation tools are available.
Ensure your PostgreSQL user has create permissions, then create a new database for this project.
createdb odoo-devHere's a typical development flow when working with Odoo:
-
Environment Setup (One-time/Initial):
- Clone the Odoo source.
- Enter your Nix development shell:
nix develop. - Create your Odoo database:
createdb odoo-dev(if not already done).
-
Start the Development Server:
- Use the
just runcommand:just run. - This starts Odoo, connecting to your
odoo-devdatabase. For most changes, you'll keep this server running.
- Use the
-
Make Code Changes:
- Python (
.pyfiles): Modify models, business logic, controllers, etc. After saving, Odoo's server usually needs to be restarted for these changes to take effect. - XML (
.xmlfiles): Modify views, menus, security rules, data records. If--dev=allis enabled (which it is injust run), many XML changes (especially views) will hot-reload without a server restart. - Static Assets (
.scss,.js,.css, images): Modify frontend styles or JavaScript. With--dev=all, these changes should also hot-reload in your browser.
- Python (
-
Update/Install Modules (When Necessary):
- If you've added new fields, changed Python model definitions significantly, or added new modules, you'll need to update the relevant module(s).
- Update:
just update <module_name>(e.g.,just update my_moduleorjust update all). This will apply the structural changes to the database. After an update, you'll need to restart yourjust runserver. - Install:
just install <new_module_name>. This is for adding entirely new modules to your database.
-
Testing:
- Run tests for specific modules:
just test <module_name>(e.g.,just test my_moduleorjust test all).
- Run tests for specific modules:
-
Debugging:
- For Python code, you can use a debugger (like
pdbor integrate with VS Code's debugger). - For frontend issues, use your browser's developer tools.
- For database interaction,
just shellprovides an interactive Python shell connected to your Odoo environment.
- For Python code, you can use a debugger (like
This project uses just to simplify common Odoo development commands. Make sure you are in the nix develop shell before running these commands.
-
Initialize the database (first time only):
just init
This command prepares the database for the first time by creating it and installing the
basemodule. -
Start the Odoo server:
just run
You can pass additional
odoo-binarguments directly:just run --xmlrpc-port=8070 --log-level=debug
-
Update Odoo modules:
just update base,web # or to update all modules: just update all -
Install Odoo modules:
just install my_module
-
Launch Odoo shell:
just shell
-
Run tests for Odoo modules:
just test my_module # or to run tests for all modules: just test all
-
Scaffold a new Odoo module:
just scaffold my_new_module
This will create the basic module structure in
custom_addons/my_new_module.
-
Reset the database:
just reset
This will completely wipe the database and re-initialize it. Use with caution.
-
Check database status:
just status
This shows if the database exists and lists some of its tables.
-
Restart the PostgreSQL server:
just db-restart
This restarts the PostgreSQL instance managed by the Nix shell.
-
Kill database connections:
just db-kill
This forcibly terminates all active connections to the Odoo database, which can be useful if the server is stuck.
Once started, access your Odoo instance at:
- URL:
http://localhost:8069 - Database:
odoo-dev - Default Admin:
admin/admin
To perform a clean start (e.g., after major changes or if assets are corrupted), you can:
- Stop Odoo.
- Drop the PostgreSQL database:
dropdb odoo-dev(or usepsqlifdropdbis not in PATH).
The project includes VS Code settings for optimal development experience:
{
"python.analysis.extraPaths": [
"./odoo",
"./custom_addons"
]
}