gnutar: Make reproducible by default #43

Merged
Irenes merged 2 commits from RossSmyth/labs:wrapTar into main 2025-10-28 02:25:33 +00:00
Contributor

Sometimes reproducibility is a concern when tarring and untarring. This should mitigate it.

Sometimes reproducibility is a concern when tarring and untarring. This should mitigate it.
RossSmyth added 1 commit 2025-10-22 18:41:34 +00:00
Author
Contributor

I'm putting this in labs first. If it works well I'll probably add it to foundation as well.

I'm putting this in labs first. If it works well I'll probably add it to foundation as well.
Author
Contributor

It builds stage3 GCC but fails to build stage4 GCC with this patch

It builds stage3 GCC but fails to build stage4 GCC with this patch
RossSmyth force-pushed wrapTar from ee06186de6 to d3e5c10ab3 2025-10-23 18:00:42 +00:00 Compare
Author
Contributor

Tested with
nom build -f tidepool packages.foundation.gcc.latest.packages.x86_64-linux.x86_64-linux.package
and it built successfully.

Tested with `nom build -f tidepool packages.foundation.gcc.latest.packages.x86_64-linux.x86_64-linux.package` and it built successfully.
Irenes reviewed 2025-10-23 23:10:32 +00:00
@ -111,0 +113,4 @@
# to provide a deterministic substitute for the "current" time. Note that
# 315532800 = 1980-01-01 12:00:00. We use this date because python's wheel
# implementation uses zip archive and zip does not support dates going back to
# 1970.
Owner

Nice approach, this for sure seems like something we should do. @jakehamilton any thoughts on the choice of date?

Sorry to be picking about wording, but is this midnight or noon? It sounds like you're saying it's noon; I can imagine reasons for that choice but would like to be explicit about it.

Also I'd like to better understand the relevance of the zip format; I didn't realize gnutar did zip? Is the concern that files we extract, are then going to be compressed by zip as part of a later, non-gnutar build phase? If that's all it is, I feel like it would be better to deal with that concern in the wheel build process and use 0 as the default time for gnutar, but it's for sure up for discussion.

Nice approach, this for sure seems like something we should do. @jakehamilton any thoughts on the choice of date? Sorry to be picking about wording, but is this midnight or noon? It sounds like you're saying it's noon; I can imagine reasons for that choice but would like to be explicit about it. Also I'd like to better understand the relevance of the zip format; I didn't realize gnutar did zip? Is the concern that files we extract, are then going to be compressed by zip as part of a later, non-gnutar build phase? If that's all it is, I feel like it would be better to deal with that concern in the wheel build process and use 0 as the default time for gnutar, but it's for sure up for discussion.
Author
Contributor

Hm, I copied this from SOURCE_DATE_EPOCH in Nixpkgs, but this isn't applicable to gnutar

Note on the epoch var:
https://reproducible-builds.org/specs/source-date-epoch/
https://reproducible-builds.org/docs/source-date-epoch/

This is only relevant if that var is set, and nix-shell is used with Python.

Hm, I copied this from SOURCE_DATE_EPOCH in Nixpkgs, but this isn't applicable to gnutar Note on the epoch var: https://reproducible-builds.org/specs/source-date-epoch/ https://reproducible-builds.org/docs/source-date-epoch/ This is only relevant if that var is set, and nix-shell is used with Python.
Owner

Thanks - most of my questions above no longer apply per the latest changes, but please put that "docs" link in a comment somewhere. It does an amazing job of explaining and contextualizing everything, and I think it will be very helpful for future readers to know about it. Also that's really cool that a spec for this exists.

Thanks - most of my questions above no longer apply per the latest changes, but please put that "docs" link in a comment somewhere. It does an amazing job of explaining and contextualizing everything, and I think it will be very helpful for future readers to know about it. Also that's really cool that a spec for this exists.
RossSmyth marked this conversation as resolved
Member
Hydra seems happy: https://hydra.aux-cache.dev/jobset/aux-prs/labs-pr43
RossSmyth force-pushed wrapTar from d3e5c10ab3 to d0e1fb6709 2025-10-24 17:27:10 +00:00 Compare
Author
Contributor

I changed it based upon feedback on Matrix so that it uses a hook rather than a wrapper. This is so that the same derivation can be used by end-users and in builds.

I do not think using TAR_OPTIONS would be supported by all build system since some do not inherit all environment variables, I am mainly thinking of Meson. But PATH should almost always be inherited.

I changed it based upon feedback on Matrix so that it uses a hook rather than a wrapper. This is so that the same derivation can be used by end-users and in builds. I do not think using `TAR_OPTIONS` would be supported by all build system since some do not inherit all environment variables, I am mainly thinking of Meson. But PATH should almost always be inherited.
Author
Contributor

Hm I'm not sure if this hook is doing anything because it is wrong, but I was able to build packages with it fine.

Hm I'm not sure if this hook is doing anything because it is wrong, but I was able to build packages with it fine.
RossSmyth reviewed 2025-10-24 17:48:20 +00:00
@ -87,0 +96,4 @@
cat << EOF > "$tar_wrap_dir/tar"
#!${packages.foundation.bash.versions."5.2.15-bootstrap".package}/bin/bash
TAR_OPTIONS="--mtime=@1 --owner=0 --group=0 --numeric-owner --sort=name" "$tar_out/bin/.tar" "\$@"
Author
Contributor

There is nothing at /bin/.tar but I was able to build GCC and such

There is nothing at `/bin/.tar` but I was able to build GCC and such
RossSmyth marked this conversation as resolved
Author
Contributor

Ok found the issue. Needed to passthru the hooks too.

Ok found the issue. Needed to passthru the hooks too.
RossSmyth force-pushed wrapTar from d0e1fb6709 to bda09169f6 2025-10-24 17:56:21 +00:00 Compare
vlinkz reviewed 2025-10-25 01:53:45 +00:00
vlinkz left a comment
Owner

We should also probably add this wrapper hook to bootstrap too

We should also probably add this wrapper hook to bootstrap too
@ -87,0 +92,4 @@
# We want to ensure we prepend to PATH so our wrapper is picked first.
"aux:wrap:tar" = lib.dag.entry.before [ "unpack" ] ''
tar_wrap_dir=$(mktemp -d)
tar_out=${packages.foundation.gnutar.versions."1.35-stage1".package}
Owner

Should probably be config.package to ensure we're pointing to this instance of the gnutar package

Should probably be `config.package` to ensure we're pointing to this instance of the gnutar package
Author
Contributor

Yeah I asked on matrix if packages have a fixed-point arg as I was unaware of config.package before.

Yeah I asked on matrix if packages have a fixed-point arg as I was unaware of `config.package` before.
RossSmyth marked this conversation as resolved
@ -87,0 +95,4 @@
tar_out=${packages.foundation.gnutar.versions."1.35-stage1".package}
cat << EOF > "$tar_wrap_dir/tar"
#!${packages.foundation.bash.versions."5.2.15-bootstrap".package}/bin/bash
Owner

Going to test it out, but this should probably be added to deps.host and then use config.deps.bash here instead to ensure we have the right platform set

Going to test it out, but this should probably be added to `deps.host` and then use `config.deps.bash` here instead to ensure we have the right platform set
Author
Contributor

Ok! I wasn't sure how to specify "use a bash that runs on host"

Ok! I wasn't sure how to specify "use a bash that runs on host"
RossSmyth marked this conversation as resolved
RossSmyth force-pushed wrapTar from bda09169f6 to 5847179532 2025-10-25 16:30:39 +00:00 Compare
RossSmyth force-pushed wrapTar from 5847179532 to f716dbd347 2025-10-25 16:32:26 +00:00 Compare
Member

Rebuilt on hydra, still looks OK: https://hydra.aux-cache.dev/jobset/aux-prs/labs-pr43

Rebuilt on hydra, still looks OK: https://hydra.aux-cache.dev/jobset/aux-prs/labs-pr43
Owner

good, yeah, it being a hook sounds like the right way to do it, to me. thanks for incorporating the comment I asked for. I'm merging it :)

good, yeah, it being a hook sounds like the right way to do it, to me. thanks for incorporating the comment I asked for. I'm merging it :)
Irenes merged commit 551bbc60de into main 2025-10-28 02:25:33 +00:00
RossSmyth deleted branch wrapTar 2025-10-28 03:15:24 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
4 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: auxolotl/labs#43
No description provided.