Skip to content

setuptools: stable file ordering for sdist - #105680

Merged
FRidh merged 1 commit into
NixOS:stagingfrom
raboof:setuptools-reproducible-file-ordering
Dec 8, 2020
Merged

FRidh merged 1 commit into
NixOS:stagingfrom
raboof:setuptools-reproducible-file-ordering

Conversation

@raboof

@raboof raboof commented Dec 2, 2020

Copy link
Copy Markdown
Member
Motivation for this change

We already re-pack the source distribution to make the
timestamps consistent, but the result is still not
entirely stable because by default tar does not sort
the files in the archive deterministically. This PR
makes sure the entries are sorted by name.

#105502

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

We already re-pack the source distribution to make the
timestamps consistent, but the result is still not
entirely stable because by default tar does not sort
the files in the archive deterministically. This PR
makes sure the entries are sorted by name.

NixOS#105502
@raboof raboof added the 6.topic: reproducible builds Run nix-build twice and get the same result. label Dec 2, 2020
@raboof
raboof changed the base branch from master to staging December 2, 2020 10:17
@ofborg ofborg Bot added the 6.topic: python Python is a high-level, general-purpose programming language. label Dec 2, 2020
@FRidh

FRidh commented Dec 2, 2020

Copy link
Copy Markdown
Member

I wonder whether we should have a setup hook for gnutar that exports these options by default using TAR_OPTIONS.

TAR_OPTIONS="--mtime="@$SOURCE_DATE_EPOCH" --sort=name ${TAR_OPTIONS:-}"

@ofborg ofborg Bot added 10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-darwin: 5001+ This PR causes many rebuilds on Darwin and must target the staging branches. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-linux: 5001+ This PR causes many rebuilds on Linux and must target the staging branches. labels Dec 2, 2020
@andir

andir commented Dec 2, 2020

Copy link
Copy Markdown
Member

I wonder whether we should have a setup hook for gnutar that exports these options by default using TAR_OPTIONS.

TAR_OPTIONS="--mtime="@$SOURCE_DATE_EPOCH" --sort=name ${TAR_OPTIONS:-}"

I think that might be a good idea if we encounter this a few more times on the r13y journey. Right now it is the only place we've seen that being required?

@FRidh

FRidh commented Dec 2, 2020

Copy link
Copy Markdown
Member

I think that might be a good idea if we encounter this a few more times on the r13y journey. Right now it is the only place we've seen that being required?

Using grep shows we use it for

  • NixOS system tarball
  • bazel packages
  • docker tools
  • kernel headers
  • bootstrap tools

We don't tar so often, however, if I would use tar in a nix-build, I would want it to be reproducible.

@andir

andir commented Dec 2, 2020

Copy link
Copy Markdown
Member

I think that might be a good idea if we encounter this a few more times on the r13y journey. Right now it is the only place we've seen that being required?

Using grep shows we use it for

* NixOS system tarball

* bazel packages

* docker tools

* kernel headers

* bootstrap tools

We don't tar so often, however, if I would use tar in a nix-build, I would want it to be reproducible.

Ok, then that might be warranted. :)

@FRidh

FRidh commented Dec 2, 2020 •

Copy link
Copy Markdown
Member

Note however that adding the hook to gnutar will make it work like this as well when using nix-shell -p. Now, I don't think that is a problem because nix-shell is meant to be reproducing a build environment, but given so many people (ab)use nix-shell with the idea they can just get the tools they want, and ignore they're in a build environment, it could be problematic.

@FRidh FRidh added this to the 21.03 milestone Dec 2, 2020
@gebner

gebner commented Dec 2, 2020

Copy link
Copy Markdown
Member

Note however that adding the hook to gnutar will make it work like this as well when using nix-shell -p. Now, I don't think that is a problem because nix-shell is meant to be reproducing a build environment, but given so many people (ab)use nix-shell with the idea they can just get the tools they want, and ignore they're in a build environment, it could be problematic.

You may call it "abuse", but this is definitely an extremely common usage of nix-shell and is prominently featured in the documentation. And we don't have a good replacement either.

@xaverdh

xaverdh commented Dec 2, 2020

Copy link
Copy Markdown
Contributor

And we don't have a good replacement either.

Well this is what nix shell will be for, right?

@FRidh

FRidh commented Dec 2, 2020

Copy link
Copy Markdown
Member

You may call it "abuse", but this is definitely an extremely common usage of nix-shell and is prominently featured in the documentation. And we don't have a good replacement either.

I am aware of that, and it is why I mentioned it. It is also the reason why issues related to hooks are opened; many don't seem to get that nix-shell gives the build environment. Documenting this prominently on the website in my opinion shows how big the problem is and makes it only worse. Too much pragmatism there. Unfortunately, we need to consider it.

And we don't have a good replacement either.

Well this is what nix shell will be for, right?

Which is why I suppose we would have to wait for the release of nix before we can introduce the hook.

@SuperSandro2000

Copy link
Copy Markdown
Member

Is there any downside to sorting archives by name by default? Do people rely on file sorting in archives? That sounds a bit like a hack.

@raboof

raboof commented Dec 2, 2020

Copy link
Copy Markdown
Member Author

Is there any downside to sorting archives by name by default? Do people rely on file sorting in archives? That sounds a bit like a hack.

I agree I don't expect people to rely on the ordering. I'm less sure about the mtime, though.

@zimbatm

zimbatm commented Dec 2, 2020

Copy link
Copy Markdown
Member

SOURCE_DATE_EPOCH is not set in the nix-shell environment so we could rely on that to conditionally activate both flags.

@FRidh

FRidh commented Dec 2, 2020 •

Copy link
Copy Markdown
Member

SOURCE_DATE_EPOCH is not set in the nix-shell environment so we could rely on that to conditionally activate both flags.

Then IN_NIX_SHELL is better I think. Ugly though. With these kind of hacks it makes more sense to make the whole setuphook machinery optional when IN_NIX_SHELL, which of course defies the point when you want a build environment.

@raboof

raboof commented Dec 3, 2020

Copy link
Copy Markdown
Member Author

I like the idea of adding a gnutar setup hook, but since it appears it's not trivial to decide what that should look like exactly, perhaps we should merge this as-is and create a new issue for the more general solution?

@doronbehar

Copy link
Copy Markdown
Contributor

Hey, don't know what this PR is all about, but setuptools needs an update: https://github.com/pypa/setuptools/releases

python.pkg.pikepdf is currently broken and it can also be updated, but that requires wheel >= 0.35 which is not yet updated (see #105974 ). setuptools>=50 is also required for pikepdf.

I've updated it anyway with sed -i to setup.py in #105977 .

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

Labels

6.topic: python Python is a high-level, general-purpose programming language. 6.topic: reproducible builds Run nix-build twice and get the same result. 10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-darwin: 5001+ This PR causes many rebuilds on Darwin and must target the staging branches. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-linux: 5001+ This PR causes many rebuilds on Linux and must target the staging branches.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants