Using pip in a nix-shell: SOURCE_DATE_EPOCH not helping

Hello,

I’m trying to use pip and a python virtualenv from inside a nix-shell.

My shell.nix file is the following:

{ pkgs ? import <nixpkgs> {} }:
with pkgs;
mkShell {
  buildInputs = [
    python37
    python37Packages.pip
    python37Packages.virtualenv
    python37Packages.setuptools
  ];
  shellHook = ''
      unset SOURCE_DATE_EPOCH
  '';
}

I have been careful to set and check the value of SOURCE_DATE_EPOCH, following Section 15.25.3.3 of the manual. This doesn’t really seem to help, as I’m still getting the error about dates before 1980.

$ nix-shell
[nix-shell:~/src/gspack]$ source .venv/bin/activate
(.venv) [nix-shell:~/src/gspack]$
(.venv) [nix-shell:~/src/gspack]$ pip install -r requirements.txt
...
ValueError: ZIP does not support timestamps before 1980
WARNING: You are using pip version 21.1.3; however, version 21.3.1 is available.
You should consider upgrading via the '/Users/jack/src/gspack/.venv/bin/python -m pip install --upgrade pip' command.
(.venv) [nix-shell:~/src/gspack]$ echo $SOURCE_DATE_EPOCH
# (it's unset)
(.venv) [nix-shell:~/src/gspack]$ 

I’m running MacOS Monterey 12.0.1, on an M1 chip. Any other suggestions? Thank you!

When .zip installers are downloaded with Nix from PyPI they get set a 0 timestamp for reproducibility reasons. Unfortunately in Python37 the zip module cannot deal with that and raises such ValueError. A few solutions:

You can also remove the unset SOURCE_DATE_EPOCH, and add:

ensureNewerSourcesForZipFilesHook

to your nativeBuildInputs to have it set to Jan 1 1980, which is zip file compatible.

thanks! Using python38 fixed it. Not sure why neither the unset SOURCE_DATE_EPOCH nor the ensureNewerSourcesForZipFilesHook fixes were working.

Same issue, I can’t use sphinx to build an epub file because of this issue.

There is an old issue on Github about this: ZIP does not support timestamps before 1980 · Issue #20716 · NixOS/nixpkgs · GitHub

Unfortunately I can’t upgrade to 3.8 (thanks tensorflow/google), and neither ensureNewerSourcesForZipFilesHook or
nset SOURCE_DATE_EPOCH work for me.

However, using a really old 2018 nixpkgs commit does work:

    pkgs = import (builtins.fetchTarball {
        url = "https://github.com/NixOS/nixpkgs/archive/a054d7450768069084142fe597ed2da367813a4a.tar.gz";
    }) {};

    # pkgs.python37Full
    # pkgs.setuptools
    # pkgs.pip
    # pkgs.virtualenv
    # pkgs.wheel

Not sure what change in nixpkgs broke it