-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
pkgs/top-level: make package sets composable (platform override approach) #380342
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
Closed
wolfgangwalther
wants to merge
7
commits into
NixOS:master
from
wolfgangwalther:compose-package-sets-3
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
27606dd
pkgs/top-level: rewrite some outdated comments
wolfgangwalther dd9e0ff
pkgs/top-level/stage: refactor moving more generic package sets to th…
wolfgangwalther 9ebbec3
pkgs/top-level: refactor mkPkgs
wolfgangwalther 46c5e9d
pkgs/test/top-level: add tests for package set composability
wolfgangwalther acbabb9
pkgs/top-level: make package sets composable
wolfgangwalther 2451254
pkgs/top-level: refactor mkHybridPkgs
wolfgangwalther 3d17de9
pkgs/top-level: fix composing "native cross" package sets
wolfgangwalther File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| # run like this: | ||
| # nix-build pkgs/test/top-level/stage.nix | ||
| { | ||
| localSystem ? { | ||
| system = builtins.currentSystem; | ||
| }, | ||
| }: | ||
|
|
||
| with import ../../top-level { inherit localSystem; }; | ||
|
|
||
| let | ||
| # To silence platform specific evaluation errors | ||
| discardEvaluationErrors = e: (builtins.tryEval e).success -> e; | ||
wolfgangwalther marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| # Basic test for idempotency of the package set, i.e: | ||
| # Applying the same package set twice should work and | ||
| # not change anything. | ||
| isIdempotent = set: discardEvaluationErrors (pkgs.${set}.stdenv == pkgs.${set}.${set}.stdenv); | ||
|
|
||
| # Some package sets should be noops in certain circumstances. | ||
| # This is very similar to the idempotency test, but not going | ||
| # via the super' overlay. | ||
| isNoop = | ||
| parent: child: | ||
| discardEvaluationErrors ( | ||
| (lib.getAttrFromPath parent pkgs).stdenv == (lib.getAttrFromPath parent pkgs).${child}.stdenv | ||
| ); | ||
|
|
||
| allMuslExamples = builtins.attrNames ( | ||
| lib.filterAttrs (_: system: lib.hasSuffix "-musl" system.config) lib.systems.examples | ||
| ); | ||
|
|
||
| allLLVMExamples = builtins.attrNames ( | ||
| lib.filterAttrs (_: system: system.useLLVM or false) lib.systems.examples | ||
| ); | ||
|
|
||
| # A package set should only change specific configuration, but needs | ||
| # to keep all other configuration from previous layers in place. | ||
| # Each package set has one or more key characteristics for which we | ||
| # test here. Those should be kept, even when applying the "set" package | ||
| # set. | ||
| isComposable = | ||
| set: | ||
| lib.all discardEvaluationErrors ( | ||
| [ | ||
| (pkgsCross.ppc64-musl.${set}.stdenv.hostPlatform.gcc.abi == "elfv2") | ||
| (pkgs.pkgsLLVM.${set}.stdenv.hostPlatform.useLLVM) | ||
| (pkgs.pkgsArocc.${set}.stdenv.hostPlatform.useArocc) | ||
| (pkgs.pkgsZig.${set}.stdenv.hostPlatform.useZig) | ||
| (pkgs.pkgsLinux.${set}.stdenv.buildPlatform.isLinux) | ||
| (pkgs.pkgsStatic.${set}.stdenv.hostPlatform.isStatic) | ||
| (pkgs.pkgsi686Linux.${set}.stdenv.hostPlatform.isx86_32) | ||
| (pkgs.pkgsx86_64Darwin.${set}.stdenv.hostPlatform.isx86_64) | ||
| (builtins.elem "trivialautovarinit" pkgs.pkgsExtraHardening.${set}.stdenv.cc.defaultHardeningFlags) | ||
| ] # Can't compose two different libcs... | ||
| ++ lib.optionals (!builtins.elem set [ "pkgsLLVMLibc" ]) [ | ||
| (pkgsCross.mingwW64.${set}.stdenv.hostPlatform.config == "x86_64-w64-mingw32") | ||
| (pkgsCross.mingwW64.${set}.stdenv.hostPlatform.libc == "msvcrt") | ||
| (pkgs.pkgsMusl.${set}.stdenv.hostPlatform.isMusl) | ||
| ] | ||
| ++ | ||
| lib.optionals | ||
| ( | ||
| !builtins.elem set [ | ||
| "pkgsMusl" | ||
| "pkgsStatic" | ||
| ] | ||
| ) | ||
| [ | ||
| (pkgs.pkgsLLVMLibc.${set}.stdenv.hostPlatform.isLLVMLibc) | ||
| ] | ||
| ); | ||
| in | ||
|
|
||
| # Appends same defaultHardeningFlags again on each .pkgsExtraHardening - thus not idempotent. | ||
| # assert isIdempotent "pkgsExtraHardening"; | ||
| # TODO: Remove the isDarwin condition, which currently results in infinite recursion. | ||
| # Also see https://github.com/NixOS/nixpkgs/pull/330567#discussion_r1894653309 | ||
| assert (stdenv.hostPlatform.isDarwin || isIdempotent "pkgsLLVM"); | ||
| # TODO: This currently results in infinite recursion, even on Linux | ||
| # assert isIdempotent "pkgsLLVMLibc"; | ||
| assert isIdempotent "pkgsArocc"; | ||
| assert isIdempotent "pkgsZig"; | ||
| assert isIdempotent "pkgsLinux"; | ||
| assert isIdempotent "pkgsMusl"; | ||
| assert isIdempotent "pkgsStatic"; | ||
| assert isIdempotent "pkgsi686Linux"; | ||
| assert isIdempotent "pkgsx86_64Darwin"; | ||
|
|
||
| assert isNoop [ "pkgsStatic" ] "pkgsMusl"; | ||
| assert lib.all (sys: isNoop [ "pkgsCross" sys ] "pkgsMusl") allMuslExamples; | ||
| # This will fail on all systems which are not handled in pkgs/os-specific/bsd/openbsd/pkgs/mkDerivation.nix, | ||
| # for example armv6l-linux, powerpc64le-linux, riscv64-linux | ||
| assert lib.all (sys: isNoop [ "pkgsCross" sys ] "pkgsLLVM") allLLVMExamples; | ||
|
|
||
| assert isComposable "pkgsExtraHardening"; | ||
| assert isComposable "pkgsLLVM"; | ||
| # TODO: Results in infinite recursion | ||
| # assert isComposable "pkgsLLVMLibc"; | ||
| assert isComposable "pkgsArocc"; | ||
| assert isComposable "pkgsZig"; | ||
| assert isComposable "pkgsMusl"; | ||
| assert isComposable "pkgsStatic"; | ||
| assert isComposable "pkgsi686Linux"; | ||
|
|
||
| # Special cases regarding buildPlatform vs hostPlatform | ||
| assert discardEvaluationErrors (pkgsCross.gnu64.pkgsMusl.stdenv.hostPlatform.isMusl); | ||
| assert discardEvaluationErrors (pkgsCross.gnu64.pkgsi686Linux.stdenv.hostPlatform.isx86_32); | ||
| assert discardEvaluationErrors (pkgsCross.mingwW64.pkgsLinux.stdenv.hostPlatform.isLinux); | ||
| assert discardEvaluationErrors ( | ||
| pkgsCross.aarch64-darwin.pkgsx86_64Darwin.stdenv.hostPlatform.isx86_64 | ||
| ); | ||
|
|
||
| # pkgsCross should keep upper cross settings | ||
| assert discardEvaluationErrors ( | ||
| with pkgsStatic.pkgsCross.gnu64.stdenv.hostPlatform; isGnu && isStatic | ||
| ); | ||
| assert discardEvaluationErrors ( | ||
| with pkgsLLVM.pkgsCross.musl64.stdenv.hostPlatform; isMusl && useLLVM | ||
| ); | ||
|
|
||
| emptyFile | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
Does this work as intended when chained?
E.g.
Using
lib.pipeIn the above example, the "original"
allArgsis{ system = "x86_64-linux"; }, so:The first time
.overrideis used, I belive you'd get{ system = "x86_64-linux"; } // { foo = true; },while the second time I think you'd get
{ system = "x86_64-linux"; } // { bar = true; }.Notice that the
fooattr is lost on subsequent uses of.override. If.overridewas used a third time,barwould also be missing.EDIT: actually, I think I oversimplified this in my head. Since
overrideusually isn't part ofallArgs, I believe it should chain correctly. At lease, up until the point when an elaborated system is supplied tooverride.I think I'll need to experiment in the repl to verify my thought process 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.
I'd think so, too - because I have quite a few tests chaining things (which is the whole point of this PR!), so I assume it does work correctly.