Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setuptools: stable file ordering for sdist #105680

Merged
merged 1 commit into from Dec 8, 2020

Conversation

raboof
Copy link
Member

@raboof raboof commented Dec 2, 2020

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 changed the base branch from master to staging December 2, 2020 10:17
@FRidh
Copy link
Member

FRidh commented Dec 2, 2020

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:-}"

@andir
Copy link
Member

andir commented Dec 2, 2020

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
Copy link
Member

FRidh commented Dec 2, 2020

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
Copy link
Member

andir commented Dec 2, 2020

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
Copy link
Member

FRidh commented Dec 2, 2020

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
Copy link
Member

gebner commented Dec 2, 2020

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
Copy link
Contributor

xaverdh commented Dec 2, 2020

And we don't have a good replacement either.

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

@FRidh
Copy link
Member

FRidh commented Dec 2, 2020

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.

@zimbatm zimbatm added this to In progress in R13y via automation Dec 2, 2020
@SuperSandro2000
Copy link
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
Copy link
Member Author

raboof commented Dec 2, 2020

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
Copy link
Member

zimbatm commented Dec 2, 2020

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

@FRidh
Copy link
Member

FRidh commented Dec 2, 2020

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
Copy link
Member Author

raboof commented Dec 3, 2020

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
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 .

@FRidh FRidh merged commit 17c8400 into NixOS:staging Dec 8, 2020
R13y automation moved this from In progress to Done Dec 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
R13y
Done
Development

Successfully merging this pull request may close these issues.

None yet

8 participants