-
-
Notifications
You must be signed in to change notification settings - Fork 15.5k
Make __DATE__/__TIME__ deterministic when NIX_ENFORCE_PURITY=1 #51510
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
Conversation
# When enforcing purity, pretend gcc can't find the current date and | ||
# time | ||
if [[ "${NIX_ENFORCE_PURITY:-}" = 1 ]]; then | ||
extraAfter=(-D__DATE__=\"???-??-????\" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you mean?
extraAfter=(-D__DATE__=\"???-??-????\" | |
extraAfter=(-D__DATE__=\"??-??-????\" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you know what debian is doing here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It appears that there has been a patch to gcc (since 2016) to allow using SOURCE_DATE_EPOCH
https://wiki.debian.org/ReproducibleBuilds/TimestampsFromCPPMacros.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some packages (e.g. pycrypto) do already have SOURCE_DATE_EPOCH
defined, though it would be preferable to do this globally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is
nixpkgs/pkgs/stdenv/generic/setup.sh
Lines 244 to 249 in 33b9aa4
# Set a fallback default value for SOURCE_DATE_EPOCH, used by some | |
# build tools to provide a deterministic substitute for the "current" | |
# time. Note that 1 = 1970-01-01 00:00:01. We don't use 0 because it | |
# confuses some applications. | |
export SOURCE_DATE_EPOCH | |
: ${SOURCE_DATE_EPOCH:=1} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But why we need these macros then, when the environment variable is already exported?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a packages ignores environment variables, we are likely detecting this because cc wrapper will also not find libraries and headers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose since the SOURCE_DATE_EPOCH
is only supported for gcc >=7.x, but not so for earlier versions, and so I have to modify it to be enabled only for early gcc's.
if [[ "${NIX_ENFORCE_PURITY:-}" = 1 ]]; then | ||
extraAfter=(-D__DATE__=\"???-??-????\" | ||
-D__TIME__=\"??:??:??\" | ||
-Wno-builtin-macro-redefined |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mhm. Can this hit us somewhere else?
I don't think setting an invalid date is the right thing to do. We should use |
|
Wait, the early versions have already been patched as well, so this fix is obsolete:
|
@rht I have updated my comment to reflect your investigation in this PR, thank you :) |
Extracted from 3dba999.
See #2281. This is the gcc stuff in the list made by @Ekleog in #2281 (comment), excluding the PGO commit.
Motivation for this change
Things done
sandbox
innix.conf
on non-NixOS)nix-shell -p nox --run "nox-review wip"
./result/bin/
)nix path-info -S
before and after)