Skip to content

Conversation

@chinyeungli
Copy link

@chinyeungli chinyeungli commented Oct 14, 2025

Fixes #339

Generates a Nix expression (default.nix) from the pyproject.toml file that is used to build the Python package for NixOS.

Once the default.nix is generated, one can build/install the package by
using:

Build the package

nix-build default.nix

The above command will create a symlink named result in the current
directory pointing to the build output in the Nix store.
Run the binary directly

./result/bin/dejacode

Signed-off-by: Chin Yeung Li [email protected]

@tdruez
Copy link
Contributor

tdruez commented Oct 29, 2025

@chinyeungli mockldap and funcparserlib were removed in #419
Could you update this branch to remove the workaround related to those libs?

Copy link
Contributor

@tdruez tdruez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$ python build_nix_docker.py
nix-prefetch-url is NOT installed.

The nix-prefetch-url requirement is not documented.

Also, you can remove all references to funcparserlib.

@chinyeungli
Copy link
Author

Yes. I am on it. For some reasons, it's not building at the moment and I am working on it.

- Updated documentation for the installation process
- Added special handling for "python_ldap", which requires specific dependencies when building from source
- Refactored and updated helper functions

Signed-off-by: Chin Yeung Li <[email protected]>
@chinyeungli
Copy link
Author

@tdruez script updated.

Copy link
Contributor

@tdruez tdruez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was able to use the script to generate the Nix package.
Could you add a short section in the script doc on how to run the app from this build?

@chinyeungli
Copy link
Author

@tdruez
one can run the built binary directly with ./result/bin/dejacode

https://github.com/aboutcode-org/dejacode/pull/391/files#diff-c3f471d98a33714e40e5449d317af18dea952c483ac5db9ee41911d01436a08eR68

but it only shows the CLI

$ ./result/bin/dejacode

Type 'dejacode help <subcommand>' for help on a specific subcommand.

Available subcommands:

[django]
    check
    compilemessages
    createcachetable
    dbshell
    diffsettings
    dumpdata
    flush
    inspectdb
    loaddata
    makemessages
    makemigrations
    migrate
    optimizemigration
    runserver
    sendtestemail
    shell
    showmigrations
    sqlflush
    sqlmigrate
    sqlsequencereset
    squashmigrations
    startapp
    startproject
    test
    testserver
Note that only Django core commands are listed as settings are not properly configured (error: Set the SECRET_KEY environment variable).

Should the binary be designed to launch the web server automatically when executed? Similar to what docker compose up does, but without relying on Docker?

@tdruez
Copy link
Contributor

tdruez commented Nov 3, 2025

@chinyeungli I should be able to run the test suite to validate the package.
Although there are missing packages:

$ SECRET_KEY=secret ./result/bin/dejacode test
Traceback (most recent call last):
  File "/nix/store/qpc72vbqazyciaa9ia81gg5d961r2ir3-python3.13-Django-5.2.7/lib/python3.13/site-packages/django/db/backends/postgresql/psycopg_any.py", line 5, in <module>
    from psycopg import ClientCursor, IsolationLevel, adapt, adapters, errors, sql
  File "/nix/store/ykw9fd32pnfpsri98145wacqi2qlwhn2-python3.13-psycopg-3.2.10/lib/python3.13/site-packages/psycopg/__init__.py", line 9, in <module>
    from . import pq  # noqa: F401 import early to stabilize side effects
    ^^^^^^^^^^^^^^^^
  File "/nix/store/ykw9fd32pnfpsri98145wacqi2qlwhn2-python3.13-psycopg-3.2.10/lib/python3.13/site-packages/psycopg/pq/__init__.py", line 116, in <module>
    import_from_libpq()
    ~~~~~~~~~~~~~~~~~^^
  File "/nix/store/ykw9fd32pnfpsri98145wacqi2qlwhn2-python3.13-psycopg-3.2.10/lib/python3.13/site-packages/psycopg/pq/__init__.py", line 108, in import_from_libpq
            raise ImportError(
    ...<4 lines>...
            )
ImportError: no pq wrapper available.
Attempts made:
- couldn't import psycopg 'c' implementation: No module named 'psycopg_c'
- couldn't import psycopg 'binary' implementation: No module named 'psycopg_binary'
- couldn't import psycopg 'python' implementation: libpq library not found

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/nix/store/4r5wwvk1n5rpks6vm1df4nlfhlkxb3j8-dejacode/bin/.dejacode-wrapped", line 9, in <module>
    sys.exit(command_line())
             ~~~~~~~~~~~~^^
  File "/nix/store/4r5wwvk1n5rpks6vm1df4nlfhlkxb3j8-dejacode/lib/python3.13/site-packages/dejacode/__init__.py", line 83, in command_line
    execute_from_command_line(sys.argv)
    ~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
  File "/nix/store/qpc72vbqazyciaa9ia81gg5d961r2ir3-python3.13-Django-5.2.7/lib/python3.13/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
    utility.execute()
    ~~~~~~~~~~~~~~~^^
  File "/nix/store/qpc72vbqazyciaa9ia81gg5d961r2ir3-python3.13-Django-5.2.7/lib/python3.13/site-packages/django/core/management/__init__.py", line 416, in execute
    django.setup()
    ~~~~~~~~~~~~^^
  File "/nix/store/qpc72vbqazyciaa9ia81gg5d961r2ir3-python3.13-Django-5.2.7/lib/python3.13/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
    ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/qpc72vbqazyciaa9ia81gg5d961r2ir3-python3.13-Django-5.2.7/lib/python3.13/site-packages/django/apps/registry.py", line 91, in populate
    app_config = AppConfig.create(entry)
  File "/nix/store/qpc72vbqazyciaa9ia81gg5d961r2ir3-python3.13-Django-5.2.7/lib/python3.13/site-packages/django/apps/config.py", line 123, in create
    mod = import_module(mod_path)
  File "/nix/store/cfapjd2rvqrpry4grb0kljnp8bvnvfxz-python3-3.13.8/lib/python3.13/importlib/__init__.py", line 88, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 1027, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "/nix/store/qpc72vbqazyciaa9ia81gg5d961r2ir3-python3.13-Django-5.2.7/lib/python3.13/site-packages/django/contrib/postgres/apps.py", line 4, in <module>
    from django.db.backends.postgresql.psycopg_any import RANGE_TYPES
  File "/nix/store/qpc72vbqazyciaa9ia81gg5d961r2ir3-python3.13-Django-5.2.7/lib/python3.13/site-packages/django/db/backends/postgresql/psycopg_any.py", line 77, in <module>
    from psycopg2 import errors, extensions, sql  # NOQA
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named 'psycopg2'

@chinyeungli
Copy link
Author

@tdruez I've updated the script and able to run the test with the following steps

Create and configure a PostgreSQL user named dejacode

psql -h localhost -U postgres -c "CREATE USER dejacode; ALTER USER dejacode CREATEDB; GRANT ALL PRIVILEGES ON DATABASE dejacode TO dejacode;" 2>/dev/null || psql -h localhost -U postgres -c "ALTER USER dejacode CREATEDB; GRANT ALL PRIVILEGES ON DATABASE dejacode TO dejacode;"

Sets up environment variables and runs a test

PGPASSWORD="password" PYTHONPATH=/home/user/project/dejacode SECRET_KEY=secret ./result/bin/dejacode test
  • Replace the "password" with the PostgreSQL password
  • Replace the PYTHONPATH with where the sources located

if component.get("packagetype") == "bdist_wheel":
whl_url = component.get("url")
if (
("cp313" not in whl_url and "py3" not in whl_url)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Josemaldonadodiosmasmalo

Comenthm

@Josemaldonadodiosmasmalo

``

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CRAVEX-integration: Packaging for Nix

5 participants