-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
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
pkgs/top-level: make package sets composable #303849
base: master
Are you sure you want to change the base?
Changes from all commits
51b6128
8fb07de
6e63885
593e29b
df621d8
9fbe356
7230b01
631102a
7a9cb10
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,104 @@ | ||||||||||||||||||
# 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; | ||||||||||||||||||
|
||||||||||||||||||
# 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); | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
However, I think you do want to check more:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm.. according to the test failures I got during development, I assumed the outPath changes when host or build platform change. Is that not correct? I tried adding the hostPlatform & buildPlatform checks. Instead of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems to support the idea that those platforms should affect stdenv's outpath: nixpkgs/pkgs/stdenv/generic/default.nix Line 167 in 48d5c5f
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For now, I made the Edit: I reverted the change to use outPath, because nixfmt then requires it to be split across two lines awkwardly. This'd be a net-negative for readability. |
||||||||||||||||||
|
||||||||||||||||||
# 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: | ||||||||||||||||||
discardEvaluationErrors ( | ||||||||||||||||||
pkgsCross.mingwW64.${set}.stdenv.hostPlatform.config == "x86_64-w64-mingw32" | ||||||||||||||||||
) | ||||||||||||||||||
&& discardEvaluationErrors (pkgsCross.mingwW64.${set}.stdenv.hostPlatform.libc == "msvcrt") | ||||||||||||||||||
&& discardEvaluationErrors (pkgsCross.ppc64-musl.${set}.stdenv.hostPlatform.gcc.abi == "elfv2") | ||||||||||||||||||
&& discardEvaluationErrors ( | ||||||||||||||||||
builtins.elem "trivialautovarinit" pkgs.pkgsExtraHardening.${set}.stdenv.cc.defaultHardeningFlags | ||||||||||||||||||
) | ||||||||||||||||||
&& discardEvaluationErrors (pkgs.pkgsLLVM.${set}.stdenv.hostPlatform.useLLVM) | ||||||||||||||||||
&& discardEvaluationErrors (pkgs.pkgsArocc.${set}.stdenv.hostPlatform.useArocc) | ||||||||||||||||||
&& discardEvaluationErrors (pkgs.pkgsZig.${set}.stdenv.hostPlatform.useZig) | ||||||||||||||||||
&& discardEvaluationErrors (pkgs.pkgsLinux.${set}.stdenv.buildPlatform.isLinux) | ||||||||||||||||||
&& discardEvaluationErrors (pkgs.pkgsMusl.${set}.stdenv.hostPlatform.isMusl) | ||||||||||||||||||
&& discardEvaluationErrors (pkgs.pkgsStatic.${set}.stdenv.hostPlatform.isStatic) | ||||||||||||||||||
&& discardEvaluationErrors (pkgs.pkgsi686Linux.${set}.stdenv.hostPlatform.isx86_32) | ||||||||||||||||||
&& discardEvaluationErrors (pkgs.pkgsx86_64Darwin.${set}.stdenv.hostPlatform.isx86_64); | ||||||||||||||||||
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"); | ||||||||||||||||||
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; | ||||||||||||||||||
assert lib.all (sys: isNoop [ "pkgsCross" sys ] "pkgsLLVM") allLLVMExamples; | ||||||||||||||||||
|
||||||||||||||||||
assert isComposable "pkgsExtraHardening"; | ||||||||||||||||||
assert isComposable "pkgsLLVM"; | ||||||||||||||||||
assert isComposable "pkgsArocc"; | ||||||||||||||||||
# TODO: unexpected argument 'bintools' - uncomment once https://github.com/NixOS/nixpkgs/pull/331011 is done | ||||||||||||||||||
# 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 |
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.
Extensive use of this makes the test less effective.
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.
Without those, I have errors like this quickly:
Those are the errors thrown in
pkgs/top-level/stage.nix
. Any idea how I could target those more specifically - without replicating the logic around those into the tests?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 went through the code again and I think
discardEvaluationErrors
does not necessarily make the test less effective. In fact it makes it more specific. The calls to this function are placed only around conditionals, so the evaluation errors can only come from evaluating those package sets.These tests are not meant to test the evaluation of each package set, but to test the composability of them, i.e. they are supposed to test the code in
stage.nix
, not further downstream. Ifstdenv
for a certain package set is broken, this is not the place to test it, imho.