diff --git a/ci/gha/tests/default.nix b/ci/gha/tests/default.nix new file mode 100644 index 000000000..39d1502df --- /dev/null +++ b/ci/gha/tests/default.nix @@ -0,0 +1,89 @@ +{ + nixFlake ? builtins.getFlake ("git+file://" + toString ../../..), + system ? builtins.currentSystem, + pkgs ? nixFlake.inputs.nixpkgs.legacyPackages.${system}, + getStdenv ? p: p.stdenv, + componentTestsPrefix ? "", + withSanitizers ? false, +}: + +let + inherit (pkgs) lib; + hydraJobs = nixFlake.hydraJobs; + packages' = nixFlake.packages.${system}; +in + +{ + /** + Top-level tests for the flake outputs, as they would be built by hydra. + These tests generally can't be overridden to run with sanitizers. + */ + topLevel = { + installerScriptForGHA = hydraJobs.installerScriptForGHA.${system}; + installTests = hydraJobs.installTests.${system}; + nixpkgsLibTests = hydraJobs.tests.nixpkgsLibTests.${system}; + rl-next = pkgs.buildPackages.runCommand "test-rl-next-release-notes" { } '' + LANG=C.UTF-8 ${pkgs.changelog-d}/bin/changelog-d ${../../../doc/manual/rl-next} >$out + ''; + repl-completion = pkgs.callPackage ../../../tests/repl-completion.nix { inherit (packages') nix; }; + + /** + Checks for our packaging expressions. + This shouldn't build anything significant; just check that things + (including derivations) are _set up_ correctly. + */ + packaging-overriding = + let + nix = packages'.nix; + in + assert (nix.appendPatches [ pkgs.emptyFile ]).libs.nix-util.src.patches == [ pkgs.emptyFile ]; + if pkgs.stdenv.buildPlatform.isDarwin then + lib.warn "packaging-overriding check currently disabled because of a permissions issue on macOS" pkgs.emptyFile + else + # If this fails, something might be wrong with how we've wired the scope, + # or something could be broken in Nixpkgs. + pkgs.testers.testEqualContents { + assertion = "trivial patch does not change source contents"; + expected = "${../../..}"; + actual = + # Same for all components; nix-util is an arbitrary pick + (nix.appendPatches [ pkgs.emptyFile ]).libs.nix-util.src; + }; + }; + + componentTests = + let + nixComponents = + (nixFlake.lib.makeComponents { + inherit pkgs; + inherit getStdenv; + }).overrideScope + ( + _: _: { + mesonComponentOverrides = finalAttrs: prevAttrs: { + mesonFlags = + (prevAttrs.mesonFlags or [ ]) + ++ lib.optionals withSanitizers [ + # Run all tests with UBSAN enabled. Running both with ubsan and + # without doesn't seem to have much immediate benefit for doubling + # the GHA CI workaround. + # + # TODO: Work toward enabling "address,undefined" if it seems feasible. + # This would maybe require dropping Boost coroutines and ignoring intentional + # memory leaks with detect_leaks=0. + (lib.mesonOption "b_sanitize" "undefined") + ]; + }; + } + ); + in + (lib.concatMapAttrs ( + pkgName: pkg: + lib.concatMapAttrs (testName: test: { + "${componentTestsPrefix}${pkgName}-${testName}" = test; + }) (pkg.tests or { }) + ) nixComponents) + // lib.optionalAttrs (pkgs.stdenv.hostPlatform == pkgs.stdenv.buildPlatform) { + "${componentTestsPrefix}nix-functional-tests" = nixComponents.nix-functional-tests; + }; +} diff --git a/flake.nix b/flake.nix index 2b93429e9..03d77e055 100644 --- a/flake.nix +++ b/flake.nix @@ -320,43 +320,11 @@ checks = forAllSystems ( system: - { - installerScriptForGHA = self.hydraJobs.installerScriptForGHA.${system}; - installTests = self.hydraJobs.installTests.${system}; - nixpkgsLibTests = self.hydraJobs.tests.nixpkgsLibTests.${system}; - rl-next = - let - pkgs = nixpkgsFor.${system}.native; - in - pkgs.buildPackages.runCommand "test-rl-next-release-notes" { } '' - LANG=C.UTF-8 ${pkgs.changelog-d}/bin/changelog-d ${./doc/manual/rl-next} >$out - ''; - repl-completion = nixpkgsFor.${system}.native.callPackage ./tests/repl-completion.nix { }; - - /** - Checks for our packaging expressions. - This shouldn't build anything significant; just check that things - (including derivations) are _set up_ correctly. - */ - packaging-overriding = - let - pkgs = nixpkgsFor.${system}.native; - nix = self.packages.${system}.nix; - in - assert (nix.appendPatches [ pkgs.emptyFile ]).libs.nix-util.src.patches == [ pkgs.emptyFile ]; - if pkgs.stdenv.buildPlatform.isDarwin then - lib.warn "packaging-overriding check currently disabled because of a permissions issue on macOS" pkgs.emptyFile - else - # If this fails, something might be wrong with how we've wired the scope, - # or something could be broken in Nixpkgs. - pkgs.testers.testEqualContents { - assertion = "trivial patch does not change source contents"; - expected = "${./.}"; - actual = - # Same for all components; nix-util is an arbitrary pick - (nix.appendPatches [ pkgs.emptyFile ]).libs.nix-util.src; - }; - } + (import ./ci/gha/tests { + inherit system; + pkgs = nixpkgsFor.${system}.native; + nixFlake = self; + }).topLevel // (lib.optionalAttrs (builtins.elem system linux64BitSystems)) { dockerImage = self.hydraJobs.dockerImage.${system}; } @@ -371,28 +339,8 @@ flatMapAttrs ( { - # Run all tests with UBSAN enabled. Running both with ubsan and - # without doesn't seem to have much immediate benefit for doubling - # the GHA CI workaround. - # - # TODO: Work toward enabling "address,undefined" if it seems feasible. - # This would maybe require dropping Boost coroutines and ignoring intentional - # memory leaks with detect_leaks=0. - "" = rec { - nixpkgs = nixpkgsFor.${system}.native; - nixComponents = nixpkgs.nixComponents2.overrideScope ( - nixCompFinal: nixCompPrev: { - mesonComponentOverrides = _finalAttrs: prevAttrs: { - mesonFlags = - (prevAttrs.mesonFlags or [ ]) - # TODO: Macos builds instrumented with ubsan take very long - # to run functional tests. - ++ lib.optionals (!nixpkgs.stdenv.hostPlatform.isDarwin) [ - (lib.mesonOption "b_sanitize" "undefined") - ]; - }; - } - ); + "" = { + pkgs = nixpkgsFor.${system}.native; }; } // lib.optionalAttrs (!nixpkgsFor.${system}.native.stdenv.hostPlatform.isDarwin) { @@ -400,27 +348,23 @@ # https://github.com/NixOS/nixpkgs/issues/320448 # TODO: disabled to speed up GHA CI. # "static-" = { - # nixpkgs = nixpkgsFor.${system}.native.pkgsStatic; + # pkgs = nixpkgsFor.${system}.native.pkgsStatic; # }; + "sanitized-" = { + pkgs = nixpkgsFor.${system}.native; + withSanitizers = true; + }; } ) ( - nixpkgsPrefix: - { - nixpkgs, - nixComponents ? nixpkgs.nixComponents2, - }: - flatMapAttrs nixComponents ( - pkgName: pkg: - flatMapAttrs pkg.tests or { } ( - testName: test: { - "${nixpkgsPrefix}${pkgName}-${testName}" = test; - } - ) - ) - // lib.optionalAttrs (nixpkgs.stdenv.hostPlatform == nixpkgs.stdenv.buildPlatform) { - "${nixpkgsPrefix}nix-functional-tests" = nixComponents.nix-functional-tests; - } + nixpkgsPrefix: args: + (import ./ci/gha/tests ( + args + // { + nixFlake = self; + componentTestsPrefix = nixpkgsPrefix; + } + )).componentTests ) // devFlake.checks.${system} or { } );