Since I recently switch to nixos and I’m working with odoo for a project, I had to update my debianesk habits and take what nixos has probably best to offer: an ultra-customized and optimized development environment using nix-shell.
This comes at the cost of extra readings and code, but the result offer a great flexibility. Now with 2 simple files I’m can load the whole environment and its dependencies just by cd
‘ing in my project’s folder.
Beforehand, one needs to setup Direnv as described in the nix-shell doc.
Then, the following shell.nix
file will suffice to load the whole environment when entering its folder:
{ pkgs ? import {} }: pkgs.mkShell { name = "odoo-env"; buildInputs = with pkgs; [ python3 xclip openldap cyrus_sasl postgresql ]; src = null; shellHook = '' # Allow the use of wheels. SOURCE_DATE_EPOCH=$(date +%s) VENV=.venv if test ! -d $VENV; then python -m venv $VENV source $VENV/bin/activate pip install -r requirements.txt fi source $VENV/bin/activate export PYTHONPATH=`pwd`/$VENV/${pkgs.python.sitePackages}/:$PYTHONPATH # export LD_LIBRARY_PATH=${with pkgs; lib.makeLibraryPath [ libGL xorg.libX11 xorg.libXext xorg.libXrender stdenv.cc.cc mtdev ]} ''; }
{ pkgs ? import {} }: pkgs.mkShell { name = "odoo-env"; buildInputs = with pkgs; [ python3 xclip openldap cyrus_sasl postgresql ]; src = null; shellHook = '' # Allow the use of wheels. SOURCE_DATE_EPOCH=$(date +%s) VENV=.venv if test ! -d $VENV; then python -m venv $VENV source $VENV/bin/activate pip install -r requirements.txt fi source $VENV/bin/activate export PYTHONPATH=`pwd`/$VENV/${pkgs.python.sitePackages}/:$PYTHONPATH # export LD_LIBRARY_PATH=${with pkgs; lib.makeLibraryPath [ libGL xorg.libX11 xorg.libXext xorg.libXrender stdenv.cc.cc mtdev ]} ''; }
Just a note about odoo’s dependencies on nixos. I haven’t been able to install proprely pyldap 2.4.28
which is the required version for odoo 12. Instead I installed the version 3.0.0
which seems to do just fine with odoo 12 as well. To do so, I updated the requirements.txt
file and changed this line
pyldap==2.4.28; sys_platform != 'win32'
with the appropriate version
pyldap==3; sys_platform != 'win32'