Skip to content

Polytropos nix helpers

lib.mkOdooVenv

Create a Python virtual environment for Odoo development.

Example

mkOdooVenv {
  pkgs = nixpkgs.legacyPackages.x86_64-linux;
  workspaceRoot = ./.;
}
=> <derivation>

Type

mkOdooVenv :: {pkgs, ...} -> Derivation

Arguments

addonsPaths : Paths to Odoo addons to include in the virtual environment (default: []). Use only for non-packaged addons.

extraBinaries : Extra binaries to include in the virtual environment (default: []).

pkgs : Nixpkgs instance

pname : Name for the virtual environment (default: "venv")

projectName : Project name from pyproject.toml (default: read from workspaceRoot/pyproject.toml)

python : Python interpreter to use (default: pkgs.python3)

spec : Package specification for the virtual environment (default: {${projectName} = [];})

workspaceRoot : Path to the workspace root

Returns

A Python virtual environment derivation with Odoo packages

Notes

  • Uses uv2nix to load the workspace and create the environment
  • The returned derivation has passthru attributes: pythonSet, spec, workspace

lib.filterAddons

Filter addons from a Python set (those starting with ADDON_PREFIX).

Type

filterAddons :: AttrSet -> AttrSet

Arguments

set : The Python set to filter

Returns

A subset of the input set containing only addons

lib.mkVenvAddonTest

Create a test command for a virtual environment and addon.

Arguments

pkgs : Nixpkgs instance

venv : Virtual environment to test

addonsPaths : Paths to Odoo addons to include in the virtual environment (default: []). Use only for non-packaged addons.

addon : Addon derivation to test (must be within the venv)

lib.mkVenvTests

Create tests for all Odoo addons in a virtual environment.

Arguments

pkgs : Nixpkgs instance

venv : Virtual environment to test

addonsPaths : Paths to Odoo addons to include in the virtual environment (default: [])

lib.addonName

Convert a Python package name to an Odoo addon name.

Type

addonName :: String -> String

Arguments

pkgName : Package name (e.g., "odoo-addon-example-module")

Returns

Addon name (e.g., "example_module")

Example

addonName "odoo-addon-my-module"
=> "my_module"

Notes

  • Mirrors Python's polytropos.build.manifest.addon_name function

lib.getLastAttrByPrefix

Get the value of the last attribute that starts with the given prefix. Attributes are sorted by name before selection.

Type

getLastAttrByPrefix :: String -> AttrSet -> Any

Arguments

prefix : Prefix to search for set : Set of attributes to search in

Returns

The value of the lexicographically last attribute starting with the prefix, or throws if no match is found.

Example

getLastAttrByPrefix "one" { one17 = "seventeen"; one18 = "eighteen"; }
=> "eighteen"

lib.buildReleaseVersion

Build a release version string from an Odoo release string.

Type

buildReleaseVersion :: String -> String

Arguments

odooRelease : Odoo release string (e.g., "17.0.20250506")

Returns

Release version string (e.g., "17.0")

Notes

  • Odoo release string is split into major and minor parts
  • Result is a string with major and minor parts joined by a dot

lib.mkPolytroposOverride

Build an override to provide a fully functional Polytropos package to a Python package set.

The previous package set should already contain Polytropos defined, just without the required fixtures.

Type

mkPolytroposOverride :: pkgs -> Override

Arguments

pkgs : Nixpkgs instance

Example

Following upstream docs:

{pkgs, polytropos}:
(
  let
    python = let
      packageOverrides = polytropos.lib.mkPolytroposOverride pkgs;
    in
      pkgs.python3.override { inherit packageOverrides; };
  in
    python.withPackages (ps: [ ps.polytropos ])
).env

lib.mkAddonsOverride

Build an override with common Odoo addon fixtures for a Python package set.

Type

mkAddonsOverride :: pkgs -> Override

Arguments

pkgs : Nixpkgs instance

Example

Follow upstream docs:

{pkgs, polytropos}:
(
  let
    python = let
      packageOverrides = polytropos.lib.mkAddonsOverride pkgs;
    in
      pkgs.python3.override { inherit packageOverrides; };
  in
    python.withPackages (ps: [ ps.polytropos ])
).env