pkgs/development/compilers/llvm: use makeScopeWithSplicing#445668
pkgs/development/compilers/llvm: use makeScopeWithSplicing#445668emilazy merged 7 commits intoNixOS:masterfrom
Conversation
b0d2561 to
ce403c5
Compare
|
Ran into a problem. darwin's This happens on this rebased version, it also was happening on the original. No eval error must be because in that version nothing was calling .override on the default version of # PR 436350's override missing for darwin
$ nix eval github:nixos/nixpkgs/acd183d2efb23f3877c448feec7d76bf6125b5dd#legacyPackages.aarch64-darwin.llvmPackages.override
# but it's present for the other versions
$ nix eval github:nixos/nixpkgs/acd183d2efb23f3877c448feec7d76bf6125b5dd#legacyPackages.aarch64-darwin.llvmPackages_20.override
{ __functionArgs = { bootBintools = true; bootBintoolsNoLibc = true; buildPackages = false; callPackage = false; generateSplicesForMkScope = false; lib = false; llvmVersions = true; patchesFn = true; pkgs = false; recurseIntoAttrs = false; stdenv = false; stdenvAdapters = false; targetPackages = false; }; __functor = «lambda __functor @ /nix/store/ny1zr85wfp3yishpwfpqhh3dpnslrl6g-source/lib/trivial.nix:989:17»; }For 0 rebuilds we probably need to make darwin stdenv's There must be some mechanism that allows this to work for |
This comment was marked as resolved.
This comment was marked as resolved.
84fead3 to
5795c43
Compare
5795c43 to
c9a1329
Compare
| // lib.optionalAttrs (super.stdenv.targetPlatform == localSystem) { | ||
| inherit (prevStage.llvmPackages) clang; | ||
| } |
There was a problem hiding this comment.
if we don't remove these 3 lines it fixes llvmPackages.clang rebuilding + various other packages like casadi
but will cause ~1k additional rebuilds elsewhere eg all php packages, which seems to be down to llvmPackages.stdenv.cc becoming different
I don't understand how replacing just the clang attr with an attrset merge // outside the overrideScope call can cause llvm scope's stdenv attr to change so I'm probably badly misunderstanding something going on here.
with clang inherited from prevStage here llvmPackages.stdenv.cc, php etc are different. llvmPackages. prefix only, stdenv.cc is always not a rebuild:
nix-diff (nix derivation show github:nixos/nixpkgs/staging-next#legacyPackages.aarch64-darwin.llvmPackages.stdenv.cc | jq -r 'keys[0]') (nix derivation show .#legacyPackages.aarch64-darwin.llvmPackages.stdenv.cc | jq -r 'keys[0]')
with clang not inherited from prevStage here llvmPackages.clang, casadi etc are different:
nix-diff (nix derivation show github:nixos/nixpkgs/staging-next#legacyPackages.aarch64-darwin.llvmPackages.clang | jq -r 'keys[0]') (nix derivation show .#legacyPackages.aarch64-darwin.llvmPackages.clang | jq -r 'keys[0]')
There was a problem hiding this comment.
See https://github.com/NixOS/nixpkgs/pull/445668/files#r2450184270, but that appears to eliminate rebuilds on Darwin.
There was a problem hiding this comment.
With that applied we're back to php* rebuilds. :c
There was a problem hiding this comment.
That’s really strange because nix-diff showed no differences for me. 😞
There was a problem hiding this comment.
I think I have a real solution. This results in no differences for php and for casadi.
diff --git a/pkgs/stdenv/darwin/default.nix b/pkgs/stdenv/darwin/default.nix
index dc8ac58328..f7c5262acc 100644
--- a/pkgs/stdenv/darwin/default.nix
+++ b/pkgs/stdenv/darwin/default.nix
@@ -1245,9 +1245,6 @@
// {
inherit (super."llvmPackages_${llvmVersion}") llvm-manpages;
}
- // lib.optionalAttrs (super.stdenv.targetPlatform == localSystem) {
- inherit (prevStage.llvmPackages) systemLibcxxClang;
- }
))
// {
inherit (super."llvmPackages_${llvmVersion}") override;
@@ -1284,7 +1281,24 @@
assert prevStage.libiconv == prevStage.darwin.libiconv;
{
- inherit (prevStage) config overlays stdenv;
+ inherit (prevStage) config overlays;
+ # This should be done in the `overrideScope` above, but it causes rebuilds.
+ # TODO: Move it there once https://github.com/NixOS/nixpkgs/pull/445668 is merged.
+ stdenv = prevStage.stdenv // {
+ overrides =
+ self: super:
+ (prevStage.stdenv.overrides self super)
+ // lib.optionalAttrs (super.stdenv.targetPlatform == localSystem) (
+ let
+ llvmVersion = lib.versions.major prevStage.llvmPackages.release_version;
+ in
+ {
+ "llvmPackages_${llvmVersion}" = prevStage."llvmPackages_${llvmVersion}" // {
+ inherit (prevStage) clang;
+ };
+ }
+ );
+ };
}
)
]There was a problem hiding this comment.
Running nixpkgs-review with this patch results in only one rebuild: flang_21.
There was a problem hiding this comment.
Yay! Down to zero rebuilds now.
stdenv mess to get it there was not fun, thanks for helping out.
32ad466 to
e25cbd0
Compare
A workaround is to adjust |
I've messed around with a patch for exposing |
e25cbd0 to
c0d5980
Compare
98df9c2 to
a7b9179
Compare
emilazy
left a comment
There was a problem hiding this comment.
Thanks for picking this up, and for @RossComputerGuy for the original PR. I am very glad to see rebuilds down to zero and that exposing all the ways in which things were screwy before :)
I think there is one important change we should make around how this works with cross, and I’d like to understand what we’re going to do about llvmPackages.override in the Darwin stdenv, but this looks like a big improvement to me in general and I hope we can merge this very soon.
| # AMD has a separate MLIR impl which we package under rocmPackages.rocmlir | ||
| # It would be an error to rely on the original mlir package from this scope | ||
| mlir = null; |
There was a problem hiding this comment.
This wasn’t here previously; is it related to rebuild avoidance?
There was a problem hiding this comment.
Newly introduced, to me it made sense to include with introducing overrideScope usage here as it doesn't cause a rebuild. Without overrideScope there wasn't a way to enforce this.
| )) | ||
| // { | ||
| inherit (super.llvmPackages) override; | ||
| }; |
There was a problem hiding this comment.
I think I lost track of what the plan is with these. This will mean that llvmPackages.override { } will produce super.llvmPackages, without the overrides from this stage. That may be required for rebuild avoidance, of course, but do we know what we’re going to do for eating the rebuilds? It seems quite important for the final llvmPackages.override after the bootstrap to behave correctly, and to correctly override the overridden scope.
I guess this is an existing problem – clang != (llvmPackages.override { }).stdenv on Darwin right now, which is quite distressing. But we really ought to fix that, so I’m just checking if we know how we’re going to. @ShamrockLee’s proposal for a general solution to composable overrides seems sound, and I’ve spent an inordinate amount of time thinking about how this stuff should look lately myself. But we should have a short‐term solution for llvmPackages at least, when we’re switching over how that scope is assembled.
I think that llvmPackages = callPackage (lib.mirrorFunctionArgs llvmPackages.override (args: (llvmPackages.override args).overrideScope …)); might work, at the expense of being quite horrendous – although AIUI @Artturin says you should always use callPackage in overlays anyway for splicing reasons, so maybe it would actually be good?? I suppose this is analogous to the way overrideResult works, which would more directly be llvmPackages = lib.makeOverridable (lib.mirrorFunctionArgs llvmPackages.override (args: (llvmPackages.override args).overrideScope …)). I frankly have no clue which one would be better and hope one of the people I just pinged has a better idea :)
We could abstract this into an overrideLlvmPackages function in this file. This is certainly a problem we need to solve more generally, for overriding LLVM to work well, let alone many other cases where our overrides system falls down. Motivation to keep working on my related grant plans…
There was a problem hiding this comment.
I feel okay about this plan for now.
There was a problem hiding this comment.
although AIUI @Artturin says you should always use callPackage in overlays anyway for splicing reasons, so maybe it would actually be good??
Is there discussion elsewhere about this to follow?
There was a problem hiding this comment.
I forget where I read @Artturin saying this, I’m afraid. But it’s because of final.callPackage having access to the spliced packages but final not.
a7b9179 to
116de78
Compare
d62525a to
addf5a4
Compare
Co-authored-by: Luna Nova <[email protected]> Co-authored-by: Emily <[email protected]>
Uses new overrideScope feature to override base LLVM packages without risking leaking incorrect non-overridden packages from the base LLVM version. To achieve no rebuilds or new attrs: - Explicit list of packages to expose in an inherit instead of the entire scope - Noting where workarounds for lack of overrideScope should be removed in a followup such as re-attaching a replaceVars patch or disabling separate tblgen package, but are kept for now to avoid a rebuild To avoid a large formatting diff a small helper has been introduced that allows an overrideScope call with a single arg, convincing nixfmt not to indent the scope body further.
- Setting recurseForDerivations again post overrideScope - Hackily propagating initial value llvmPackages.override
This was used in 4b07aea to get what was actually a *host* LLVM in practice, when the `buildHost` LLVM package set was included in the `callPackage` scope used for libraries. It should no longer be necessary and is now quite confusing.
addf5a4 to
2d6ca40
Compare
|
Thanks @emilazy, that looks great*! I can prep followup changes that drop the rebuild avoidance introduced here. *skipping over some consequences of past decisions that maybe do not look great |
Rebase of @RossComputerGuy's PR #436350 + ROCm scope usage & rebuild avoidance + darwin rebuild avoidance.
Things done
.overridetrying to disappear from darwin default llvmPackages?nixpkgs/pkgs/build-support/build-mozilla-mach/default.nix
Lines 207 to 214 in 2458def
overridefunction that discards all of the stdenv overrides, because that's what happened in the pastAdd a 👍 reaction to pull requests you find important.