Skip to content

Conversation

@chinyeungli
Copy link
Contributor

@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 tli@nexb.com

Signed-off-by: Chin Yeung Li <tli@nexb.com>
Signed-off-by: Chin Yeung Li <tli@nexb.com>
Signed-off-by: Chin Yeung Li <tli@nexb.com>
 - Added --generate and --test options
 - Updated code structure/comments

Signed-off-by: Chin Yeung Li <tli@nexb.com>
@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
Contributor 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 <tli@nexb.com>
@chinyeungli
Copy link
Contributor 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
Contributor 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'

…at runtime #339

Signed-off-by: Chin Yeung Li <tli@nexb.com>
@chinyeungli
Copy link
Contributor 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

Signed-off-by: Chin Yeung Li <tli@nexb.com>
…lity #339

Signed-off-by: Chin Yeung Li <tli@nexb.com>
Signed-off-by: Chin Yeung Li <tli@nexb.com>
Signed-off-by: Chin Yeung Li <tli@nexb.com>
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'm still getting the psycopg2 module error on Ubuntu 22.04.5 LTS:

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/dzjq5n06jjk826yjxjgvlhxzs36vnwf7-dejacode/bin/.dejacode-wrapped", line 9, in <module>
    sys.exit(command_line())
             ~~~~~~~~~~~~^^
  File "/nix/store/dzjq5n06jjk826yjxjgvlhxzs36vnwf7-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'

 - Better error handling
 - Reduce the hardcoded code

Signed-off-by: Chin Yeung Li <tli@nexb.com>
Signed-off-by: Chin Yeung Li <tli@nexb.com>
@chinyeungli
Copy link
Contributor Author

@tdruez
e016700 should resolve the psycopg2 issue

The script no longer requires setting PYTHONPATH to run tests. However, you still need to initialize the database user with:

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;"

Then run the tests using:

PGPASSWORD="your_password" SECRET_KEY=secret ./result/bin/dejacode test

Make sure to replace "your_password" with the actual password for the dejacode user.

@tdruez
Copy link
Contributor

tdruez commented Nov 24, 2025

@chinyeungli I can generate the default.nix file alright, but I'm getting the following error during the nix-build default.nix.

Note that I use the latest Nix Docker image for the build.

docker run -it -v "$(pwd)":/dejacode nixos/nix:latest bash
nix-build /dejacode/default.nix

Using: default.nix.zip

Executing pythonRemoveTestsDir
Finished executing pythonRemoveTestsDir
ERROR: noBrokenSymlinks: the symlink /nix/store/015kx8dvr448ykzynkm4nh43sp1bhqqr-dejacode/src/bin/python points to a missing target: /nix/store/015kx8dvr448ykzynkm4nh43sp1bhqqr-dejacode/src/bin/python3.13
ERROR: noBrokenSymlinks: the symlink /nix/store/015kx8dvr448ykzynkm4nh43sp1bhqqr-dejacode/src/bin/python3 points to a missing target: /nix/store/015kx8dvr448ykzynkm4nh43sp1bhqqr-dejacode/src/bin/python3.13
ERROR: noBrokenSymlinks: found 2 dangling symlinks, 0 reflexive symlinks and 0 unreadable symlinks
error: Cannot build '/nix/store/wfp4sk4nnrhbkai5mh4fkgnl8wpqhvkw-dejacode.drv'.
       Reason: builder failed with exit code 1.
       Output paths:
         /nix/store/015kx8dvr448ykzynkm4nh43sp1bhqqr-dejacode
         /nix/store/4nb8k3rpw30m44397a8yyznzxqpgvzg7-dejacode-dist

The following changes to the postInstall section seem to fix the build:

postInstall = ''
  # Create source directory like RPM does (for source access)
  mkdir -p $out/src
  
  # Copy source files, dereferencing symlinks to avoid broken links
  cp -rL ${./.}/* $out/src/ 2>/dev/null || true
  
  # Remove build artifacts from source copy
  rm -rf $out/src/dist $out/src/build $out/src/result $out/src/default.nix 2>/dev/null || true
  
  # Remove any bin directories that might contain symlinks
  rm -rf $out/src/bin 2>/dev/null || true

  # Wrap the dejacode executable to set up the runtime environment
  wrapProgram $out/bin/dejacode \
    --set PYTHONPATH "$out/src:$out/${pythonWithOverlay.sitePackages}" \
    --set LD_LIBRARY_PATH "${pkgs.postgresql.lib}/lib:$LD_LIBRARY_PATH" \
    --run "cd $out/src"
'';

But I'm still getting the ModuleNotFoundError: No module named 'psycopg2' error.

@chinyeungli
Copy link
Contributor Author

Interesting. I don't have the issue on my WSL2

I ran docker run -it -v "$(pwd)":/dejacode nixos/nix:latest bash and then cd dejacode and then run nix-build default.nix

Successfully built dejacode-5.4.1-py3-none-any.whl
Finished creating a wheel...
Finished executing pypaBuildPhase
Running phase: pythonRuntimeDepsCheckHook
Executing pythonRuntimeDepsCheck
Checking runtime dependencies for dejacode-5.4.1-py3-none-any.whl
Finished executing pythonRuntimeDepsCheck
Running phase: installPhase
Executing pypaInstallPhase
Successfully installed dejacode-5.4.1-py3-none-any.whl
Finished executing pypaInstallPhase
Running phase: pythonOutputDistPhase
Executing pythonOutputDistPhase
Finished executing pythonOutputDistPhase
Running phase: fixupPhase
shrinking RPATHs of ELF executables and libraries in /nix/store/05m25iz0aallmrmkn61mnfqpxbns218c-dejacode
checking for references to /nix/var/nix/builds/nix-9-1223434824/ in /nix/store/05m25iz0aallmrmkn61mnfqpxbns218c-dejacode...
patching script interpreter paths in /nix/store/05m25iz0aallmrmkn61mnfqpxbns218c-dejacode
/nix/store/05m25iz0aallmrmkn61mnfqpxbns218c-dejacode/src/manage.py: interpreter directive changed from "#!/usr/bin/env python" to "/nix/store/1ki8jq5sax0hm1sqbw0jk6qnqpy417zx-python3-3.13.5/bin/python"
/nix/store/05m25iz0aallmrmkn61mnfqpxbns218c-dejacode/src/dist/rpmbuild/SOURCES/python3-dejacode-5.4.1/manage.py: interpreter directive changed from "#!/usr/bin/env python" to "/nix/store/1ki8jq5sax0hm1sqbw0jk6qnqpy417zx-python3-3.13.5/bin/python"
/nix/store/05m25iz0aallmrmkn61mnfqpxbns218c-dejacode/src/dist/rpmbuild/SOURCES/python3-dejacode-5.4.1/.venv/bin/pip3.13: interpreter directive changed from "#!/home/thomas/vscode/dejacode/.venv/bin/python3.13" to "/nix/store/1ki8jq5sax0hm1sqbw0jk6qnqpy417zx-python3-3.13.5/bin/python3.13"
/nix/store/05m25iz0aallmrmkn61mnfqpxbns218c-dejacode/src/dist/rpmbuild/SOURCES/python3-dejacode-5.4.1/.venv/bin/pip: interpreter directive changed from "#!/home/thomas/vscode/dejacode/.venv/bin/python3.13" to "/nix/store/1ki8jq5sax0hm1sqbw0jk6qnqpy417zx-python3-3.13.5/bin/python3.13"
/nix/store/05m25iz0aallmrmkn61mnfqpxbns218c-dejacode/src/dist/rpmbuild/SOURCES/python3-dejacode-5.4.1/.venv/bin/pip3: interpreter directive changed from "#!/home/thomas/vscode/dejacode/.venv/bin/python3.13" to "/nix/store/1ki8jq5sax0hm1sqbw0jk6qnqpy417zx-python3-3.13.5/bin/python3.13"
stripping (with command strip and flags -S -p) in  /nix/store/05m25iz0aallmrmkn61mnfqpxbns218c-dejacode/lib /nix/store/05m25iz0aallmrmkn61mnfqpxbns218c-dejacode/bin
shrinking RPATHs of ELF executables and libraries in /nix/store/jxfkc78mkxbhid8q63jyhwi18b3a2mfx-dejacode-dist
checking for references to /nix/var/nix/builds/nix-9-1223434824/ in /nix/store/jxfkc78mkxbhid8q63jyhwi18b3a2mfx-dejacode-dist...
patching script interpreter paths in /nix/store/jxfkc78mkxbhid8q63jyhwi18b3a2mfx-dejacode-dist
/nix/store/jxfkc78mkxbhid8q63jyhwi18b3a2mfx-dejacode-dist/rpmbuild/SOURCES/python3-dejacode-5.4.1/manage.py: interpreter directive changed from "#!/usr/bin/env python" to "/nix/store/1ki8jq5sax0hm1sqbw0jk6qnqpy417zx-python3-3.13.5/bin/python"
/nix/store/jxfkc78mkxbhid8q63jyhwi18b3a2mfx-dejacode-dist/rpmbuild/SOURCES/python3-dejacode-5.4.1/.venv/bin/pip3.13: interpreter directive changed from "#!/home/thomas/vscode/dejacode/.venv/bin/python3.13" to "/nix/store/1ki8jq5sax0hm1sqbw0jk6qnqpy417zx-python3-3.13.5/bin/python3.13"
/nix/store/jxfkc78mkxbhid8q63jyhwi18b3a2mfx-dejacode-dist/rpmbuild/SOURCES/python3-dejacode-5.4.1/.venv/bin/pip: interpreter directive changed from "#!/home/thomas/vscode/dejacode/.venv/bin/python3.13" to "/nix/store/1ki8jq5sax0hm1sqbw0jk6qnqpy417zx-python3-3.13.5/bin/python3.13"
/nix/store/jxfkc78mkxbhid8q63jyhwi18b3a2mfx-dejacode-dist/rpmbuild/SOURCES/python3-dejacode-5.4.1/.venv/bin/pip3: interpreter directive changed from "#!/home/thomas/vscode/dejacode/.venv/bin/python3.13" to "/nix/store/1ki8jq5sax0hm1sqbw0jk6qnqpy417zx-python3-3.13.5/bin/python3.13"
Rewriting #!/nix/store/1ki8jq5sax0hm1sqbw0jk6qnqpy417zx-python3-3.13.5/bin/python3.13 to #!/nix/store/1ki8jq5sax0hm1sqbw0jk6qnqpy417zx-python3-3.13.5
wrapping `/nix/store/05m25iz0aallmrmkn61mnfqpxbns218c-dejacode/bin/.dejacode-wrapped'...
Rewriting #! /nix/store/cfqbabpc7xwg8akbcchqbq3cai6qq2vs-bash-5.2p37/bin/bash -e to #!/nix/store/1ki8jq5sax0hm1sqbw0jk6qnqpy417zx-python3-3.13.5
Executing pythonRemoveTestsDir
Finished executing pythonRemoveTestsDir
Running phase: pythonCatchConflictsPhase
Running phase: pythonRemoveBinBytecodePhase
Running phase: pythonImportsCheckPhase
Executing pythonImportsCheckPhase
/nix/store/05m25iz0aallmrmkn61mnfqpxbns218c-dejacode
bash-5.2#

I will try to figure out the issue

@chinyeungli
Copy link
Contributor Author

@tdruez I've updated the code and the test should run with the following setup after the nix-build default.nix

nix-env -iA nixpkgs.postgresql nixpkgs.busybox && \
mkdir -p /home/postgres /tmp/pgdata /tmp/pgrun && \
busybox adduser -D -h /home/postgres -s /bin/sh postgres && \
chown -R postgres:postgres /home/postgres /tmp/pgdata /tmp/pgrun && \
su -s /bin/sh postgres -c 'initdb -D /tmp/pgdata' && \
su -s /bin/sh postgres -c 'pg_ctl -D /tmp/pgdata -o "-p 5432 -k /tmp/pgrun" -l /tmp/pg.log start' && \
su -s /bin/sh postgres -c 'createuser -s -h /tmp/pgrun -p 5432 dejacode' && \
su -s /bin/sh postgres -c 'createdb -h /tmp/pgrun -p 5432 dejacode' && \
su -s /bin/sh postgres -c "psql -h /tmp/pgrun -p 5432 -d postgres" <<< "ALTER USER dejacode WITH PASSWORD 'dejacode';" 

export DATABASE_URL=postgres://dejacode:dejacode@127.0.0.1:5432/dejacode

SECRET_KEY=secret ./result/bin/dejacode test

@tdruez
Copy link
Contributor

tdruez commented Nov 26, 2025

@chinyeungli Everything went smoothly with the latest changes:

1. Generate the default.nix file

cd dejacode/
python3 -m venv .venv
source .venv/bin/activate
pip install toml requests
python etc/scripts/build_nix_docker.py

2. Build DejaCode Nix package

Using the latest Nix Docker image for the build.

$ docker run -it -v "$(pwd)":/dejacode nixos/nix:latest bash
nix-build /dejacode/default.nix

Results:

[...]
Successfully built dejacode-5.4.1-py3-none-any.whl
Finished creating a wheel...
Finished executing pypaBuildPhase
Running phase: pythonRuntimeDepsCheckHook
[...]
Executing pythonImportsCheckPhase
/nix/store/ifh8wizixw5dlqggn578ndgjzrphha53-dejacode

3. Run the tests

nix-env -iA nixpkgs.postgresql nixpkgs.busybox && \
mkdir -p /home/postgres /tmp/pgdata /tmp/pgrun && \
busybox adduser -D -h /home/postgres -s /bin/sh postgres && \
chown -R postgres:postgres /home/postgres /tmp/pgdata /tmp/pgrun && \
su -s /bin/sh postgres -c 'initdb -D /tmp/pgdata' && \
su -s /bin/sh postgres -c 'pg_ctl -D /tmp/pgdata -o "-p 5432 -k /tmp/pgrun" -l /tmp/pg.log start' && \
su -s /bin/sh postgres -c 'createuser -s -h /tmp/pgrun -p 5432 dejacode' && \
su -s /bin/sh postgres -c 'createdb -h /tmp/pgrun -p 5432 dejacode' && \
su -s /bin/sh postgres -c "psql -h /tmp/pgrun -p 5432 -d postgres" <<< "ALTER USER dejacode WITH PASSWORD 'dejacode';" 

export DATABASE_URL=postgres://dejacode:dejacode@127.0.0.1:5432/dejacode
SECRET_KEY=secret ./result/bin/dejacode test

Results:

bash-5.2# SECRET_KEY=secret ./result/bin/dejacode test
Found 1749 test(s).
Creating test database for alias 'default'...
System check identified no issues (0 silenced).
......................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................ssssssssssss...................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................

----------------------------------------------------------------------
Ran 1749 tests in 165.479s

SUCCESS (skipped=12)

@tdruez tdruez merged commit 7d97658 into main Nov 26, 2025
4 checks passed
@tdruez tdruez deleted the 339_packaging_for_nix branch November 26, 2025 05:06
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

4 participants