buildPythonApplication, cx-freeze and zip files

Hi everyone, myself and a fellow Nix user in our common community are looking into making a package out of the Archipelago game randomizer built in Python. Right now we’re just trying to get it to build and run before un-janking things, but we’ve run into a bit of a roadblock regarding its setup script.

As part of the setup process, Archipelago uses the cx-freeze package to compile the scripts into a .pyc zip file, but right now it is failing with the following trace:

Traceback (most recent call last):
File "/build/source/setup.py", line 609, in <module>
cx_Freeze.setup(
File "/nix/store/szs1zxnlwzxjmv2drhkskxx489nns1vw-python3.11-cx-freeze-6.15.10/lib/python3.11/site-packages/cx_Freeze/__init__.py", line 61, in setup
setuptools.setup(**attrs)
File "/nix/store/y8yq448xka665bqyd5gvdhajqdbsnyys-python3.11-setuptools-68.2.2/lib/python3.11/site-packages/setuptools/__init__.py", line 103, in setup
return distutils.core.setup(**attrs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/nix/store/y8yq448xka665bqyd5gvdhajqdbsnyys-python3.11-setuptools-68.2.2/lib/python3.11/site-packages/setuptools/_distutils/core.py", line 185, in setup
return run_commands(dist)
^^^^^^^^^^^^^^^^^^
File "/nix/store/y8yq448xka665bqyd5gvdhajqdbsnyys-python3.11-setuptools-68.2.2/lib/python3.11/site-packages/setuptools/_distutils/core.py", line 201, in run_commands
dist.run_commands()
File "/nix/store/y8yq448xka665bqyd5gvdhajqdbsnyys-python3.11-setuptools-68.2.2/lib/python3.11/site-packages/setuptools/_distutils/dist.py", line 969, in run_commands
self.run_command(cmd)
File "/nix/store/y8yq448xka665bqyd5gvdhajqdbsnyys-python3.11-setuptools-68.2.2/lib/python3.11/site-packages/setuptools/dist.py", line 989, in run_command
super().run_command(command)
File "/nix/store/y8yq448xka665bqyd5gvdhajqdbsnyys-python3.11-setuptools-68.2.2/lib/python3.11/site-packages/setuptools/_distutils/dist.py", line 988, in run_command
cmd_obj.run()
File "/build/source/setup.py", line 329, in run
super().run()
File "/nix/store/szs1zxnlwzxjmv2drhkskxx489nns1vw-python3.11-cx-freeze-6.15.10/lib/python3.11/site-packages/cx_Freeze/command/build_exe.py", line 280, in run
freezer.freeze()
File "/nix/store/szs1zxnlwzxjmv2drhkskxx489nns1vw-python3.11-cx-freeze-6.15.10/lib/python3.11/site-packages/cx_Freeze/freezer.py", line 698, in freeze
self._write_modules(library_zip, finder)
File "/nix/store/szs1zxnlwzxjmv2drhkskxx489nns1vw-python3.11-cx-freeze-6.15.10/lib/python3.11/site-packages/cx_Freeze/freezer.py", line 645, in _write_modules
zinfo = ZipInfo(target_name + ".pyc", zip_time)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/nix/store/qp5zys77biz7imbk6yy85q5pdv7qk84j-python3-3.11.6/lib/python3.11/zipfile.py", line 390, in __init__
raise ValueError('ZIP does not support timestamps before 1980')
ValueError: ZIP does not support timestamps before 1980

Okay, fair enough - there’s documentation about adjusting SOURCE_DATE_EPOCH to deal with this, so I added unset SOURCE_DATE_EPOCH to our preBuild hook, but strangely enough, it almost seemed that setting (or unsetting) this was being ignored.

I looked a bit deeper into this, and it would seem that making the zip file should work here in the generic builder for Python applications and here for cx-freeze, which is the module that’s actually stopping us, so we’re kind of unsure how to proceed at the moment. Is this something we can resolve in our package, or some bug with the buildPythonApplication helper script?

We are currently using nixpkgs:nixos-23.11 to build.

1 Like

I have the same problem, please tell me if you find a solution

not a great solution but may allow you to build it Using pip in a nix-shell: SOURCE_DATE_EPOCH not helping - #6 by jeff-hykin

Also, have you tried setting the year with ensureNewerSourcesHook? i.e, (ensureNewerSourcesHook { year = "1980"; }) edit: blah! that didn’t work either; sorry