diff --git a/pkgs/tools/package-management/nix/2_26/componentized.nix b/pkgs/tools/package-management/nix/2_26/componentized.nix index 48f2d052d36f9..d22741427faf3 100644 --- a/pkgs/tools/package-management/nix/2_26/componentized.nix +++ b/pkgs/tools/package-management/nix/2_26/componentized.nix @@ -25,7 +25,7 @@ let { otherSplices = generateSplicesForMkScope "nixComponents"; f = import ./packaging/components.nix { - inherit lib officialRelease src; + inherit lib officialRelease pkgs src stdenv; }; }; @@ -42,8 +42,7 @@ let f = import ./dependencies.nix { inherit pkgs; inherit stdenv; - inherit src; }; }; in -nixComponents.nix-everything +(nixComponents.overrideSource src).nix-everything diff --git a/pkgs/tools/package-management/nix/2_26/dependencies.nix b/pkgs/tools/package-management/nix/2_26/dependencies.nix index 73739e2edcc5b..0e874d990188c 100644 --- a/pkgs/tools/package-management/nix/2_26/dependencies.nix +++ b/pkgs/tools/package-management/nix/2_26/dependencies.nix @@ -1,8 +1,6 @@ # These overrides are applied to the dependencies of the Nix components. { - src, - # The raw Nixpkgs, not affected by this scope pkgs, @@ -14,10 +12,6 @@ let in let - inherit (pkgs) lib; - - root = ./.; - stdenv = if prevStdenv.isDarwin && prevStdenv.isx86_64 then darwinStdenv else prevStdenv; # Fix the following error with the default x86_64-darwin SDK: @@ -28,113 +22,6 @@ let # allocation function Clang uses with this setting actually works # all the way back to 10.6. darwinStdenv = pkgs.overrideSDK prevStdenv { darwinMinVersion = "10.13"; }; - - resolveRelPath = p: lib.path.removePrefix root p; - resolvePath = p: src + "/${resolveRelPath p}"; - - # Indirection for Nixpkgs to override when package.nix files are vendored - # fileset filtering is not possible without IFD on src, so we ignore the fileset - # and produce a path containing _more_, but the extra files generally won't be - # accessed. - # The Nix flake uses fileset.toSource for this. - filesetToSource = { root, fileset }: resolvePath root; - - /** - Given a set of layers, create a mkDerivation-like function - */ - mkPackageBuilder = - exts: userFn: stdenv.mkDerivation (lib.extends (lib.composeManyExtensions exts) userFn); - - localSourceLayer = - finalAttrs: prevAttrs: - let - workDirPath = - # Ideally we'd pick finalAttrs.workDir, but for now `mkDerivation` has - # the requirement that everything except passthru and meta must be - # serialized by mkDerivation, which doesn't work for this. - prevAttrs.workDir; - - workDirSubpath = resolveRelPath workDirPath; - # sources = assert prevAttrs.fileset._type == "fileset"; prevAttrs.fileset; - # src = lib.fileset.toSource { fileset = sources; inherit root; }; - - in - { - sourceRoot = "${src.name}/" + workDirSubpath; - inherit src; - - # Clear what `derivation` can't/shouldn't serialize; see prevAttrs.workDir. - fileset = null; - workDir = null; - }; - - mesonLayer = finalAttrs: prevAttrs: { - # NOTE: - # As of https://github.com/NixOS/nixpkgs/blob/8baf8241cea0c7b30e0b8ae73474cb3de83c1a30/pkgs/by-name/me/meson/setup-hook.sh#L26, - # `mesonBuildType` defaults to `plain` if not specified. We want our Nix-built binaries to be optimized by default. - # More on build types here: https://mesonbuild.com/Builtin-options.html#details-for-buildtype. - mesonBuildType = "release"; - # NOTE: - # Users who are debugging Nix builds are expected to set the environment variable `mesonBuildType`, per the - # guidance in https://github.com/NixOS/nix/blob/8a3fc27f1b63a08ac983ee46435a56cf49ebaf4a/doc/manual/source/development/debugging.md?plain=1#L10. - # For this reason, we don't want to refer to `finalAttrs.mesonBuildType` here, but rather use the environment variable. - preConfigure = - prevAttrs.preConfigure or "" - + - lib.optionalString - ( - !stdenv.hostPlatform.isWindows - # build failure - && !stdenv.hostPlatform.isStatic - # LTO breaks exception handling on x86-64-darwin. - && stdenv.system != "x86_64-darwin" - ) - '' - case "$mesonBuildType" in - release|minsize) appendToVar mesonFlags "-Db_lto=true" ;; - *) appendToVar mesonFlags "-Db_lto=false" ;; - esac - ''; - nativeBuildInputs = [ - pkgs.buildPackages.meson - pkgs.buildPackages.ninja - ] ++ prevAttrs.nativeBuildInputs or [ ]; - mesonCheckFlags = prevAttrs.mesonCheckFlags or [ ] ++ [ - "--print-errorlogs" - ]; - }; - - mesonBuildLayer = finalAttrs: prevAttrs: { - nativeBuildInputs = prevAttrs.nativeBuildInputs or [ ] ++ [ - pkgs.buildPackages.pkg-config - ]; - separateDebugInfo = !stdenv.hostPlatform.isStatic; - hardeningDisable = lib.optional stdenv.hostPlatform.isStatic "pie"; - env = - prevAttrs.env or { } - // lib.optionalAttrs ( - stdenv.isLinux - && !(stdenv.hostPlatform.isStatic && stdenv.system == "aarch64-linux") - && !(stdenv.hostPlatform.useLLVM or false) - ) { LDFLAGS = "-fuse-ld=gold"; }; - }; - - mesonLibraryLayer = finalAttrs: prevAttrs: { - outputs = prevAttrs.outputs or [ "out" ] ++ [ "dev" ]; - }; - - # Work around weird `--as-needed` linker behavior with BSD, see - # https://github.com/mesonbuild/meson/issues/3593 - bsdNoLinkAsNeeded = - finalAttrs: prevAttrs: - lib.optionalAttrs stdenv.hostPlatform.isBSD { - mesonFlags = [ (lib.mesonBool "b_asneeded" false) ] ++ prevAttrs.mesonFlags or [ ]; - }; - - miscGoodPractice = finalAttrs: prevAttrs: { - strictDeps = prevAttrs.strictDeps or true; - enableParallelBuilding = true; - }; in scope: { inherit stdenv; @@ -156,27 +43,4 @@ scope: { boehmgc = pkgs.boehmgc.override { enableLargeConfig = true; }; - - inherit resolvePath filesetToSource; - - mkMesonDerivation = mkPackageBuilder [ - miscGoodPractice - localSourceLayer - mesonLayer - ]; - mkMesonExecutable = mkPackageBuilder [ - miscGoodPractice - bsdNoLinkAsNeeded - localSourceLayer - mesonLayer - mesonBuildLayer - ]; - mkMesonLibrary = mkPackageBuilder [ - miscGoodPractice - bsdNoLinkAsNeeded - localSourceLayer - mesonLayer - mesonBuildLayer - mesonLibraryLayer - ]; } diff --git a/pkgs/tools/package-management/nix/2_26/packaging/components.nix b/pkgs/tools/package-management/nix/2_26/packaging/components.nix index 57932617f827e..8b027591e6ed8 100644 --- a/pkgs/tools/package-management/nix/2_26/packaging/components.nix +++ b/pkgs/tools/package-management/nix/2_26/packaging/components.nix @@ -1,13 +1,22 @@ { lib, + pkgs, src, + stdenv, officialRelease, }: scope: let - inherit (scope) callPackage; + inherit (scope) + callPackage + ; + inherit (pkgs.buildPackages) + meson + ninja + pkg-config + ; baseVersion = lib.fileContents ../.version; @@ -20,6 +29,165 @@ let }_${src.shortRev or "dirty"}"; fineVersion = baseVersion + fineVersionSuffix; + + root = ../.; + + # Indirection for Nixpkgs to override when package.nix files are vendored + filesetToSource = lib.fileset.toSource; + + /** + Given a set of layers, create a mkDerivation-like function + */ + mkPackageBuilder = + exts: userFn: stdenv.mkDerivation (lib.extends (lib.composeManyExtensions exts) userFn); + + setVersionLayer = finalAttrs: prevAttrs: { + preConfigure = + prevAttrs.prevAttrs or "" + + + # Update the repo-global .version file. + # Symlink ./.version points there, but by default only workDir is writable. + '' + chmod u+w ./.version + echo ${finalAttrs.version} > ./.version + ''; + }; + + localSourceLayer = + finalAttrs: prevAttrs: + let + workDirPath = + # Ideally we'd pick finalAttrs.workDir, but for now `mkDerivation` has + # the requirement that everything except passthru and meta must be + # serialized by mkDerivation, which doesn't work for this. + prevAttrs.workDir; + + workDirSubpath = lib.path.removePrefix root workDirPath; + sources = + assert prevAttrs.fileset._type == "fileset"; + prevAttrs.fileset; + src = lib.fileset.toSource { + fileset = sources; + inherit root; + }; + + in + { + sourceRoot = "${src.name}/" + workDirSubpath; + inherit src; + + # Clear what `derivation` can't/shouldn't serialize; see prevAttrs.workDir. + fileset = null; + workDir = null; + }; + + resolveRelPath = p: lib.path.removePrefix root p; + + makeFetchedSourceLayer = + finalScope: finalAttrs: prevAttrs: + let + workDirPath = + # Ideally we'd pick finalAttrs.workDir, but for now `mkDerivation` has + # the requirement that everything except passthru and meta must be + # serialized by mkDerivation, which doesn't work for this. + prevAttrs.workDir; + + workDirSubpath = resolveRelPath workDirPath; + + in + { + sourceRoot = "${finalScope.patchedSrc.name}/" + workDirSubpath; + src = finalScope.patchedSrc; + version = + let + n = lib.length finalScope.patches; + in + if n == 0 then prevAttrs.version else prevAttrs.version + "+${toString n}"; + + # Clear what `derivation` can't/shouldn't serialize; see prevAttrs.workDir. + fileset = null; + workDir = null; + }; + + mesonLayer = finalAttrs: prevAttrs: { + # NOTE: + # As of https://github.com/NixOS/nixpkgs/blob/8baf8241cea0c7b30e0b8ae73474cb3de83c1a30/pkgs/by-name/me/meson/setup-hook.sh#L26, + # `mesonBuildType` defaults to `plain` if not specified. We want our Nix-built binaries to be optimized by default. + # More on build types here: https://mesonbuild.com/Builtin-options.html#details-for-buildtype. + mesonBuildType = "release"; + # NOTE: + # Users who are debugging Nix builds are expected to set the environment variable `mesonBuildType`, per the + # guidance in https://github.com/NixOS/nix/blob/8a3fc27f1b63a08ac983ee46435a56cf49ebaf4a/doc/manual/source/development/debugging.md?plain=1#L10. + # For this reason, we don't want to refer to `finalAttrs.mesonBuildType` here, but rather use the environment variable. + preConfigure = + prevAttrs.preConfigure or "" + + + lib.optionalString + ( + !stdenv.hostPlatform.isWindows + # build failure + && !stdenv.hostPlatform.isStatic + # LTO breaks exception handling on x86-64-darwin. + && stdenv.system != "x86_64-darwin" + ) + '' + case "$mesonBuildType" in + release|minsize) appendToVar mesonFlags "-Db_lto=true" ;; + *) appendToVar mesonFlags "-Db_lto=false" ;; + esac + ''; + nativeBuildInputs = [ + meson + ninja + ] ++ prevAttrs.nativeBuildInputs or [ ]; + mesonCheckFlags = prevAttrs.mesonCheckFlags or [ ] ++ [ + "--print-errorlogs" + ]; + }; + + mesonBuildLayer = finalAttrs: prevAttrs: { + nativeBuildInputs = prevAttrs.nativeBuildInputs or [ ] ++ [ + pkg-config + ]; + separateDebugInfo = !stdenv.hostPlatform.isStatic; + hardeningDisable = lib.optional stdenv.hostPlatform.isStatic "pie"; + env = + prevAttrs.env or { } + // lib.optionalAttrs ( + stdenv.isLinux + && !(stdenv.hostPlatform.isStatic && stdenv.system == "aarch64-linux") + && !(stdenv.hostPlatform.useLLVM or false) + ) { LDFLAGS = "-fuse-ld=gold"; }; + }; + + mesonLibraryLayer = finalAttrs: prevAttrs: { + outputs = prevAttrs.outputs or [ "out" ] ++ [ "dev" ]; + }; + + # Work around weird `--as-needed` linker behavior with BSD, see + # https://github.com/mesonbuild/meson/issues/3593 + bsdNoLinkAsNeeded = + finalAttrs: prevAttrs: + lib.optionalAttrs stdenv.hostPlatform.isBSD { + mesonFlags = [ (lib.mesonBool "b_asneeded" false) ] ++ prevAttrs.mesonFlags or [ ]; + }; + + miscGoodPractice = finalAttrs: prevAttrs: { + strictDeps = prevAttrs.strictDeps or true; + enableParallelBuilding = true; + }; + + /** + Append patches to the source layer. + */ + appendPatches = + scope: patches: + scope.overrideScope ( + finalScope: prevScope: { + patches = prevScope.patches ++ patches; + } + ); + in # This becomes the pkgs.nixComponents attribute set @@ -27,6 +195,113 @@ in version = baseVersion + versionSuffix; inherit versionSuffix; + inherit filesetToSource; + + /** + A user-provided extension function to apply to each component derivation. + */ + mesonComponentOverrides = finalAttrs: prevAttrs: { }; + + /** + An overridable derivation layer for handling the sources. + */ + sourceLayer = localSourceLayer; + + /** + Resolve a path value to either itself or a path in the `src`, depending + whether `overrideSource` was called. + */ + resolvePath = p: p; + + /** + Apply an extension function (i.e. overlay-shaped) to all component derivations. + */ + overrideAllMesonComponents = + f: + scope.overrideScope ( + finalScope: prevScope: { + mesonComponentOverrides = lib.composeExtensions scope.mesonComponentOverrides f; + } + ); + + /** + Provide an alternate source. This allows the expressions to be vendored without copying the sources, + but it does make the build non-granular; all components will use a complete source. + + Packaging expressions will be ignored. + */ + overrideSource = + src: + scope.overrideScope ( + finalScope: prevScope: { + sourceLayer = makeFetchedSourceLayer finalScope; + /** + Unpatched source for the build of Nix. Packaging expressions will be ignored. + */ + src = src; + /** + Patches for the whole Nix source. Changes to packaging expressions will be ignored. + */ + patches = [ ]; + /** + Fetched and patched source to be used in component derivations. + */ + patchedSrc = + if finalScope.patches == [ ] then + src + else + pkgs.buildPackages.srcOnly ( + pkgs.buildPackages.stdenvNoCC.mkDerivation { + name = "${finalScope.src.name or "nix-source"}-patched"; + inherit (finalScope) src patches; + } + ); + + resolvePath = p: finalScope.patchedSrc + "/${resolveRelPath p}"; + filesetToSource = { root, fileset }: finalScope.resolvePath root; + + appendPatches = appendPatches finalScope; + } + ); + + /** + Append patches to be applied to the whole Nix source. + This affects all components. + + Changes to the packaging expressions will be ignored. + */ + appendPatches = + patches: + # switch to "fetched" source first, so that patches apply to the whole tree. + (scope.overrideSource "${./..}").appendPatches patches; + + mkMesonDerivation = mkPackageBuilder [ + miscGoodPractice + scope.sourceLayer + setVersionLayer + mesonLayer + scope.mesonComponentOverrides + ]; + mkMesonExecutable = mkPackageBuilder [ + miscGoodPractice + bsdNoLinkAsNeeded + scope.sourceLayer + setVersionLayer + mesonLayer + mesonBuildLayer + scope.mesonComponentOverrides + ]; + mkMesonLibrary = mkPackageBuilder [ + miscGoodPractice + bsdNoLinkAsNeeded + scope.sourceLayer + mesonLayer + setVersionLayer + mesonBuildLayer + mesonLibraryLayer + scope.mesonComponentOverrides + ]; + nix-util = callPackage ../src/libutil/package.nix { }; nix-util-c = callPackage ../src/libutil-c/package.nix { }; nix-util-test-support = callPackage ../src/libutil-test-support/package.nix { }; @@ -56,7 +331,9 @@ in nix-cli = callPackage ../src/nix/package.nix { version = fineVersion; }; - nix-functional-tests = callPackage ../tests/functional/package.nix { version = fineVersion; }; + nix-functional-tests = callPackage ../tests/functional/package.nix { + version = fineVersion; + }; nix-manual = callPackage ../doc/manual/package.nix { version = fineVersion; }; nix-internal-api-docs = callPackage ../src/internal-api-docs/package.nix { version = fineVersion; }; @@ -64,5 +341,33 @@ in nix-perl-bindings = callPackage ../src/perl/package.nix { }; - nix-everything = callPackage ../packaging/everything.nix { }; + nix-everything = callPackage ../packaging/everything.nix { } // { + # Note: no `passthru.overrideAllMesonComponents` + # This would propagate into `nix.overrideAttrs f`, but then discard + # `f` when `.overrideAllMesonComponents` is used. + # Both "methods" should be views on the same fixpoint overriding mechanism + # for that to work. For now, we intentionally don't support the broken + # two-fixpoint solution. + /** + Apply an extension function (i.e. overlay-shaped) to all component derivations, and return the nix package. + */ + overrideAllMesonComponents = f: (scope.overrideAllMesonComponents f).nix-everything; + + /** + Append patches to be applied to the whole Nix source. + This affects all components. + + Changes to the packaging expressions will be ignored. + */ + appendPatches = ps: (scope.appendPatches ps).nix-everything; + + /** + Provide an alternate source. This allows the expressions to be vendored without copying the sources, + but it does make the build non-granular; all components will use a complete source. + + Packaging expressions will be ignored. + */ + overrideSource = src: (scope.overrideSource src).nix-everything; + + }; } diff --git a/pkgs/tools/package-management/nix/2_26/packaging/everything.nix b/pkgs/tools/package-management/nix/2_26/packaging/everything.nix index 7ac7a156d2269..d8fc835f235d1 100644 --- a/pkgs/tools/package-management/nix/2_26/packaging/everything.nix +++ b/pkgs/tools/package-management/nix/2_26/packaging/everything.nix @@ -39,6 +39,8 @@ testers, runCommand, + + patchedSrc ? null, }: let @@ -68,52 +70,50 @@ let ; }; - dev = - nixAttrs: - stdenv.mkDerivation (finalAttrs: { - name = "nix-${nix-cli.version}-dev"; - pname = "nix"; - version = nix-cli.version; - dontUnpack = true; - dontBuild = true; - libs = map lib.getDev (lib.attrValues libs); - installPhase = '' - mkdir -p $out/nix-support - echo $libs >> $out/nix-support/propagated-build-inputs - echo ${nixAttrs.finalPackage} >> $out/nix-support/propagated-build-inputs - ''; - passthru = { - tests = { - # TODO: is this supposed to work for a dev output? - # pkg-config = testers.hasPkgConfigModules { - # package = finalAttrs.finalPackage; - # }; + dev = stdenv.mkDerivation (finalAttrs: { + name = "nix-${nix-cli.version}-dev"; + pname = "nix"; + version = nix-cli.version; + dontUnpack = true; + dontBuild = true; + libs = map lib.getDev (lib.attrValues libs); + nix = nix-cli; + installPhase = '' + mkdir -p $out/nix-support + echo $libs >> $out/nix-support/propagated-build-inputs + echo $nix >> $out/nix-support/propagated-build-inputs + ''; + passthru = { + tests = { + pkg-config = testers.hasPkgConfigModules { + package = finalAttrs.finalPackage; }; + }; - # If we were to fully emulate output selection here, we'd confuse the Nix CLIs, - # because they rely on `drvPath`. - dev = finalAttrs.finalPackage.out; - out = nixAttrs.finalPackage.out; + # If we were to fully emulate output selection here, we'd confuse the Nix CLIs, + # because they rely on `drvPath`. + dev = finalAttrs.finalPackage.out; - libs = throw "`nix.dev.libs` is not meant to be used; use `nix.libs` instead."; - }; - meta = { - pkgConfigModules = [ - "nix-cmd" - "nix-expr" - "nix-expr-c" - "nix-fetchers" - "nix-flake" - "nix-flake-c" - "nix-main" - "nix-main-c" - "nix-store" - "nix-store-c" - "nix-util" - "nix-util-c" - ]; - }; - }); + libs = throw "`nix.dev.libs` is not meant to be used; use `nix.libs` instead."; + }; + meta = { + mainProgram = "nix"; + pkgConfigModules = [ + "nix-cmd" + "nix-expr" + "nix-expr-c" + "nix-fetchers" + "nix-flake" + "nix-flake-c" + "nix-main" + "nix-main-c" + "nix-store" + "nix-store-c" + "nix-util" + "nix-util-c" + ]; + }; + }); devdoc = buildEnv { name = "nix-${nix-cli.version}-devdoc"; paths = [ @@ -122,87 +122,141 @@ let ]; }; + /** + Produce a set of derivation outputs that implement the multiple outputs interface. + + The multiple outputs interface was originally designed for derivations with + multiple outputs, but it can also be used for packages which do not correspond + 1:1 to a single derivation and whose outputs come from distinct derivations. + */ + makeOutputs = + { + outputs, + defaultOutput ? "out", + extraAttrs ? outputName: value: { }, + }: + + let + prepOutput = + outputName: value: + { + _type = "package"; + /** + For compatibility. The outputs of this package may not actually be implemented using a single derivation. + */ + type = "derivation"; + outputName = outputName; + outPath = value.outPath or value; + } + // extraAttrs outputName value; + + outputAttrs = lib.mapAttrs ( + outputName: value: { outputSpecified = true; } // prepOutput outputName value // commonAttrs + ) outputs; + + # This is without `outputSpecified`, but otherwise matches the `outputAttrs` above. + defaultOutputValue = prepOutput defaultOutput outputs.${defaultOutput} // commonAttrs; + + commonAttrs = { + outputs = builtins.attrNames outputs; + } // outputAttrs; + + in + defaultOutputValue; + in -(buildEnv { - name = "nix-${nix-cli.version}"; - paths = [ - nix-cli - nix-manual.man - ]; - - meta.mainProgram = "nix"; -}).overrideAttrs - ( - finalAttrs: prevAttrs: { - doCheck = true; - doInstallCheck = true; - - checkInputs = - [ - # Make sure the unit tests have passed - nix-util-tests.tests.run - nix-store-tests.tests.run - nix-expr-tests.tests.run - nix-fetchers-tests.tests.run - nix-flake-tests.tests.run - - # Make sure the functional tests have passed - nix-functional-tests - ] - ++ lib.optionals - (!stdenv.hostPlatform.isStatic && stdenv.buildPlatform.canExecute stdenv.hostPlatform) - [ - # Perl currently fails in static build - # TODO: Split out tests into a separate derivation? - nix-perl-bindings - ]; - passthru = prevAttrs.passthru // { - inherit (nix-cli) version; - - /** - These are the libraries that are part of the Nix project. They are used - by the Nix CLI and other tools. - - If you need to use these libraries in your project, we recommend to use - the `-c` C API libraries exclusively, if possible. - - We also recommend that you build the complete package to ensure that the unit tests pass. - You could do this in CI, or by passing it in an unused environment variable. e.g in a `mkDerivation` call: - - ```nix - buildInputs = [ nix.libs.nix-util-c nix.libs.nix-store-c ]; - # Make sure the nix libs we use are ok - unusedInputsForTests = [ nix ]; - disallowedReferences = nix.all; - ``` - */ - inherit libs; - - tests = prevAttrs.passthru.tests or { } // { - pkg-config = testers.hasPkgConfigModules { - package = finalAttrs.finalPackage; - }; - }; - /** - A derivation referencing the `dev` outputs of the Nix libraries. - */ - dev = dev finalAttrs; - inherit devdoc; - doc = nix-manual; - outputs = [ - "out" - "dev" - "devdoc" - "doc" +makeOutputs { + extraAttrs = outputName: drv: { + meta = drv.meta // { + description = "The Nix package manager"; + pkgConfigModules = dev.meta.pkgConfigModules; + outputsToInstall = [ + # man is symlinked + "out" + ]; + }; + internals = drv; + name = "nix"; + overrideAttrs = + _: + throw "The nix package does not support overrideAttrs, because it has been split into multiple derivations. Instead, you may call attributes such as overrideSource, appendPatches or overrideAllMesonComponents."; + inherit (nix-cli) version; + # Should not be required + inherit (drv) drvPath; + tests = drv.tests or {}; + src = patchedSrc; + }; + outputs = { + inherit dev devdoc; + doc = nix-manual; + out = + (buildEnv { + name = "nix-${nix-cli.version}"; + paths = [ + nix-cli + nix-manual.man ]; - all = lib.attrValues ( - lib.genAttrs finalAttrs.passthru.outputs (outName: finalAttrs.finalPackage.${outName}) + meta.mainProgram = "nix"; + }).overrideAttrs + ( + finalAttrs: prevAttrs: { + doCheck = true; + doInstallCheck = true; + + checkInputs = + [ + # Make sure the unit tests have passed + nix-util-tests.tests.run + nix-store-tests.tests.run + nix-expr-tests.tests.run + nix-fetchers-tests.tests.run + nix-flake-tests.tests.run + + # Make sure the functional tests have passed + nix-functional-tests + + # dev bundle is ok + # (checkInputs must be empty paths??) + (runCommand "check-pkg-config" { checked = dev.tests.pkg-config; } "mkdir $out") + ] + ++ lib.optionals + (!stdenv.hostPlatform.isStatic && stdenv.buildPlatform.canExecute stdenv.hostPlatform) + [ + # Perl currently fails in static build + # TODO: Split out tests into a separate derivation? + nix-perl-bindings + ]; + passthru = prevAttrs.passthru // { + inherit (nix-cli) version; + + /** + These are the libraries that are part of the Nix project. They are used + by the Nix CLI and other tools. + + If you need to use these libraries in your project, we recommend to use + the `-c` C API libraries exclusively, if possible. + + We also recommend that you build the complete package to ensure that the unit tests pass. + You could do this in CI, or by passing it in an unused environment variable. e.g in a `mkDerivation` call: + + ```nix + buildInputs = [ nix.libs.nix-util-c nix.libs.nix-store-c ]; + # Make sure the nix libs we use are ok + unusedInputsForTests = [ nix ]; + disallowedReferences = nix.all; + ``` + */ + inherit libs; + + tests = prevAttrs.passthru.tests or { } // { + # TODO: create a proper fixpoint and: + pkg-config = testers.hasPkgConfigModules { + package = finalAttrs.finalPackage; + }; + }; + }; + } ); - }; - meta = prevAttrs.meta // { - description = "The Nix package manager"; - pkgConfigModules = (dev finalAttrs).meta.pkgConfigModules; - }; - } - ) + }; +} diff --git a/pkgs/tools/package-management/nix/2_26/src/libcmd/package.nix b/pkgs/tools/package-management/nix/2_26/src/libcmd/package.nix index d155d9f1e620d..d459d1c20fb54 100644 --- a/pkgs/tools/package-management/nix/2_26/src/libcmd/package.nix +++ b/pkgs/tools/package-management/nix/2_26/src/libcmd/package.nix @@ -64,14 +64,6 @@ mkMesonLibrary (finalAttrs: { nlohmann_json ]; - preConfigure = - # "Inline" .version so it's not a symlink, and includes the suffix. - # Do the meson utils, without modification. - '' - chmod u+w ./.version - echo ${version} > ../../.version - ''; - mesonFlags = [ (lib.mesonEnable "markdown" enableMarkdown) (lib.mesonOption "readline-flavor" readlineFlavor) diff --git a/pkgs/tools/package-management/nix/2_26/src/libexpr-c/package.nix b/pkgs/tools/package-management/nix/2_26/src/libexpr-c/package.nix index ad1ea371c2d7c..694fbc1fe7893 100644 --- a/pkgs/tools/package-management/nix/2_26/src/libexpr-c/package.nix +++ b/pkgs/tools/package-management/nix/2_26/src/libexpr-c/package.nix @@ -36,14 +36,6 @@ mkMesonLibrary (finalAttrs: { nix-expr ]; - preConfigure = - # "Inline" .version so it's not a symlink, and includes the suffix. - # Do the meson utils, without modification. - '' - chmod u+w ./.version - echo ${version} > ../../.version - ''; - mesonFlags = [ ]; diff --git a/pkgs/tools/package-management/nix/2_26/src/libexpr-test-support/package.nix b/pkgs/tools/package-management/nix/2_26/src/libexpr-test-support/package.nix index 5628d606a4524..44b0ff3863137 100644 --- a/pkgs/tools/package-management/nix/2_26/src/libexpr-test-support/package.nix +++ b/pkgs/tools/package-management/nix/2_26/src/libexpr-test-support/package.nix @@ -40,14 +40,6 @@ mkMesonLibrary (finalAttrs: { rapidcheck ]; - preConfigure = - # "Inline" .version so it's not a symlink, and includes the suffix. - # Do the meson utils, without modification. - '' - chmod u+w ./.version - echo ${version} > ../../.version - ''; - mesonFlags = [ ]; diff --git a/pkgs/tools/package-management/nix/2_26/src/libexpr-tests/package.nix b/pkgs/tools/package-management/nix/2_26/src/libexpr-tests/package.nix index bb5acb7c873da..51d52e935bf5c 100644 --- a/pkgs/tools/package-management/nix/2_26/src/libexpr-tests/package.nix +++ b/pkgs/tools/package-management/nix/2_26/src/libexpr-tests/package.nix @@ -46,14 +46,6 @@ mkMesonExecutable (finalAttrs: { gtest ]; - preConfigure = - # "Inline" .version so it's not a symlink, and includes the suffix. - # Do the meson utils, without modification. - '' - chmod u+w ./.version - echo ${version} > ../../.version - ''; - mesonFlags = [ ]; diff --git a/pkgs/tools/package-management/nix/2_26/src/libexpr/package.nix b/pkgs/tools/package-management/nix/2_26/src/libexpr/package.nix index afd01c3846e94..533dae9f253c7 100644 --- a/pkgs/tools/package-management/nix/2_26/src/libexpr/package.nix +++ b/pkgs/tools/package-management/nix/2_26/src/libexpr/package.nix @@ -77,14 +77,6 @@ mkMesonLibrary (finalAttrs: { nlohmann_json ] ++ lib.optional enableGC boehmgc; - preConfigure = - # "Inline" .version so it's not a symlink, and includes the suffix. - # Do the meson utils, without modification. - '' - chmod u+w ./.version - echo ${version} > ../../.version - ''; - mesonFlags = [ (lib.mesonEnable "gc" enableGC) ]; diff --git a/pkgs/tools/package-management/nix/2_26/src/libfetchers-tests/package.nix b/pkgs/tools/package-management/nix/2_26/src/libfetchers-tests/package.nix index f2680e9b3c1f7..1e379fc5ade24 100644 --- a/pkgs/tools/package-management/nix/2_26/src/libfetchers-tests/package.nix +++ b/pkgs/tools/package-management/nix/2_26/src/libfetchers-tests/package.nix @@ -44,14 +44,6 @@ mkMesonExecutable (finalAttrs: { gtest ]; - preConfigure = - # "Inline" .version so it's not a symlink, and includes the suffix. - # Do the meson utils, without modification. - '' - chmod u+w ./.version - echo ${version} > ../../.version - ''; - mesonFlags = [ ]; diff --git a/pkgs/tools/package-management/nix/2_26/src/libfetchers/package.nix b/pkgs/tools/package-management/nix/2_26/src/libfetchers/package.nix index b0aecd04979e2..3f52e987800e3 100644 --- a/pkgs/tools/package-management/nix/2_26/src/libfetchers/package.nix +++ b/pkgs/tools/package-management/nix/2_26/src/libfetchers/package.nix @@ -41,14 +41,6 @@ mkMesonLibrary (finalAttrs: { nlohmann_json ]; - preConfigure = - # "Inline" .version so it's not a symlink, and includes the suffix. - # Do the meson utils, without modification. - '' - chmod u+w ./.version - echo ${version} > ../../.version - ''; - meta = { platforms = lib.platforms.unix ++ lib.platforms.windows; }; diff --git a/pkgs/tools/package-management/nix/2_26/src/libflake-c/package.nix b/pkgs/tools/package-management/nix/2_26/src/libflake-c/package.nix index f0615a42798ee..1149508523e9f 100644 --- a/pkgs/tools/package-management/nix/2_26/src/libflake-c/package.nix +++ b/pkgs/tools/package-management/nix/2_26/src/libflake-c/package.nix @@ -38,14 +38,6 @@ mkMesonLibrary (finalAttrs: { nix-flake ]; - preConfigure = - # "Inline" .version so it's not a symlink, and includes the suffix. - # Do the meson utils, without modification. - '' - chmod u+w ./.version - echo ${version} > ../../.version - ''; - mesonFlags = [ ]; diff --git a/pkgs/tools/package-management/nix/2_26/src/libflake-tests/package.nix b/pkgs/tools/package-management/nix/2_26/src/libflake-tests/package.nix index f9d9b0bc0c6bd..714f3791ad904 100644 --- a/pkgs/tools/package-management/nix/2_26/src/libflake-tests/package.nix +++ b/pkgs/tools/package-management/nix/2_26/src/libflake-tests/package.nix @@ -46,14 +46,6 @@ mkMesonExecutable (finalAttrs: { gtest ]; - preConfigure = - # "Inline" .version so it's not a symlink, and includes the suffix. - # Do the meson utils, without modification. - '' - chmod u+w ./.version - echo ${version} > ../../.version - ''; - mesonFlags = [ ]; diff --git a/pkgs/tools/package-management/nix/2_26/src/libflake/package.nix b/pkgs/tools/package-management/nix/2_26/src/libflake/package.nix index ebd38e140d302..5240ce5e39656 100644 --- a/pkgs/tools/package-management/nix/2_26/src/libflake/package.nix +++ b/pkgs/tools/package-management/nix/2_26/src/libflake/package.nix @@ -40,14 +40,6 @@ mkMesonLibrary (finalAttrs: { nlohmann_json ]; - preConfigure = - # "Inline" .version so it's not a symlink, and includes the suffix. - # Do the meson utils, without modification. - '' - chmod u+w ./.version - echo ${version} > ../../.version - ''; - meta = { platforms = lib.platforms.unix ++ lib.platforms.windows; }; diff --git a/pkgs/tools/package-management/nix/2_26/src/libmain-c/package.nix b/pkgs/tools/package-management/nix/2_26/src/libmain-c/package.nix index cf710e03b0d07..f019a917d360c 100644 --- a/pkgs/tools/package-management/nix/2_26/src/libmain-c/package.nix +++ b/pkgs/tools/package-management/nix/2_26/src/libmain-c/package.nix @@ -40,14 +40,6 @@ mkMesonLibrary (finalAttrs: { nix-main ]; - preConfigure = - # "Inline" .version so it's not a symlink, and includes the suffix. - # Do the meson utils, without modification. - '' - chmod u+w ./.version - echo ${version} > ../../.version - ''; - mesonFlags = [ ]; diff --git a/pkgs/tools/package-management/nix/2_26/src/libmain/package.nix b/pkgs/tools/package-management/nix/2_26/src/libmain/package.nix index 046b505dfd46d..c03697c48dab6 100644 --- a/pkgs/tools/package-management/nix/2_26/src/libmain/package.nix +++ b/pkgs/tools/package-management/nix/2_26/src/libmain/package.nix @@ -37,14 +37,6 @@ mkMesonLibrary (finalAttrs: { openssl ]; - preConfigure = - # "Inline" .version so it's not a symlink, and includes the suffix. - # Do the meson utils, without modification. - '' - chmod u+w ./.version - echo ${version} > ../../.version - ''; - meta = { platforms = lib.platforms.unix ++ lib.platforms.windows; }; diff --git a/pkgs/tools/package-management/nix/2_26/src/libstore-c/package.nix b/pkgs/tools/package-management/nix/2_26/src/libstore-c/package.nix index 89abeaab87063..fde17c78e0176 100644 --- a/pkgs/tools/package-management/nix/2_26/src/libstore-c/package.nix +++ b/pkgs/tools/package-management/nix/2_26/src/libstore-c/package.nix @@ -36,14 +36,6 @@ mkMesonLibrary (finalAttrs: { nix-store ]; - preConfigure = - # "Inline" .version so it's not a symlink, and includes the suffix. - # Do the meson utils, without modification. - '' - chmod u+w ./.version - echo ${version} > ../../.version - ''; - mesonFlags = [ ]; diff --git a/pkgs/tools/package-management/nix/2_26/src/libstore-test-support/package.nix b/pkgs/tools/package-management/nix/2_26/src/libstore-test-support/package.nix index 7cc29795c1903..ccac25ee16a21 100644 --- a/pkgs/tools/package-management/nix/2_26/src/libstore-test-support/package.nix +++ b/pkgs/tools/package-management/nix/2_26/src/libstore-test-support/package.nix @@ -40,14 +40,6 @@ mkMesonLibrary (finalAttrs: { rapidcheck ]; - preConfigure = - # "Inline" .version so it's not a symlink, and includes the suffix. - # Do the meson utils, without modification. - '' - chmod u+w ./.version - echo ${version} > ../../.version - ''; - mesonFlags = [ ]; diff --git a/pkgs/tools/package-management/nix/2_26/src/libstore-tests/package.nix b/pkgs/tools/package-management/nix/2_26/src/libstore-tests/package.nix index 670386c4a6ff3..b39ee7fa73c07 100644 --- a/pkgs/tools/package-management/nix/2_26/src/libstore-tests/package.nix +++ b/pkgs/tools/package-management/nix/2_26/src/libstore-tests/package.nix @@ -52,14 +52,6 @@ mkMesonExecutable (finalAttrs: { nix-store-test-support ]; - preConfigure = - # "Inline" .version so it's not a symlink, and includes the suffix. - # Do the meson utils, without modification. - '' - chmod u+w ./.version - echo ${version} > ../../.version - ''; - mesonFlags = [ ]; diff --git a/pkgs/tools/package-management/nix/2_26/src/libstore/package.nix b/pkgs/tools/package-management/nix/2_26/src/libstore/package.nix index c982b44f0b738..31867d331b92b 100644 --- a/pkgs/tools/package-management/nix/2_26/src/libstore/package.nix +++ b/pkgs/tools/package-management/nix/2_26/src/libstore/package.nix @@ -69,14 +69,6 @@ mkMesonLibrary (finalAttrs: { nlohmann_json ]; - preConfigure = - # "Inline" .version so it's not a symlink, and includes the suffix. - # Do the meson utils, without modification. - '' - chmod u+w ./.version - echo ${version} > ../../.version - ''; - mesonFlags = [ (lib.mesonEnable "seccomp-sandboxing" stdenv.hostPlatform.isLinux) diff --git a/pkgs/tools/package-management/nix/2_26/src/libutil-c/package.nix b/pkgs/tools/package-management/nix/2_26/src/libutil-c/package.nix index 72f57d6f9c62e..f26f57775d4f8 100644 --- a/pkgs/tools/package-management/nix/2_26/src/libutil-c/package.nix +++ b/pkgs/tools/package-management/nix/2_26/src/libutil-c/package.nix @@ -34,14 +34,6 @@ mkMesonLibrary (finalAttrs: { nix-util ]; - preConfigure = - # "Inline" .version so it's not a symlink, and includes the suffix. - # Do the meson utils, without modification. - '' - chmod u+w ./.version - echo ${version} > ../../.version - ''; - mesonFlags = [ ]; diff --git a/pkgs/tools/package-management/nix/2_26/src/libutil-test-support/package.nix b/pkgs/tools/package-management/nix/2_26/src/libutil-test-support/package.nix index 33cd5217defaf..fafd47c86c5e0 100644 --- a/pkgs/tools/package-management/nix/2_26/src/libutil-test-support/package.nix +++ b/pkgs/tools/package-management/nix/2_26/src/libutil-test-support/package.nix @@ -38,14 +38,6 @@ mkMesonLibrary (finalAttrs: { rapidcheck ]; - preConfigure = - # "Inline" .version so it's not a symlink, and includes the suffix. - # Do the meson utils, without modification. - '' - chmod u+w ./.version - echo ${version} > ../../.version - ''; - mesonFlags = [ ]; diff --git a/pkgs/tools/package-management/nix/2_26/src/libutil-tests/package.nix b/pkgs/tools/package-management/nix/2_26/src/libutil-tests/package.nix index d4eea3a8dc260..b8d54b76c42f5 100644 --- a/pkgs/tools/package-management/nix/2_26/src/libutil-tests/package.nix +++ b/pkgs/tools/package-management/nix/2_26/src/libutil-tests/package.nix @@ -46,14 +46,6 @@ mkMesonExecutable (finalAttrs: { gtest ]; - preConfigure = - # "Inline" .version so it's not a symlink, and includes the suffix. - # Do the meson utils, without modification. - '' - chmod u+w ./.version - echo ${version} > ../../.version - ''; - mesonFlags = [ ]; diff --git a/pkgs/tools/package-management/nix/2_26/src/libutil/package.nix b/pkgs/tools/package-management/nix/2_26/src/libutil/package.nix index 586119a6e5d5e..47dcb54a26f85 100644 --- a/pkgs/tools/package-management/nix/2_26/src/libutil/package.nix +++ b/pkgs/tools/package-management/nix/2_26/src/libutil/package.nix @@ -52,17 +52,6 @@ mkMesonLibrary (finalAttrs: { nlohmann_json ]; - preConfigure = - # "Inline" .version so it's not a symlink, and includes the suffix. - # Do the meson utils, without modification. - # - # TODO: change release process to add `pre` in `.version`, remove it - # before tagging, and restore after. - '' - chmod u+w ./.version - echo ${version} > ../../.version - ''; - mesonFlags = [ (lib.mesonEnable "cpuid" stdenv.hostPlatform.isx86_64) ]; diff --git a/pkgs/tools/package-management/nix/2_26/src/nix/package.nix b/pkgs/tools/package-management/nix/2_26/src/nix/package.nix index 89c52c3bb0506..40a2804378504 100644 --- a/pkgs/tools/package-management/nix/2_26/src/nix/package.nix +++ b/pkgs/tools/package-management/nix/2_26/src/nix/package.nix @@ -91,18 +91,11 @@ mkMesonExecutable (finalAttrs: { nix-cmd ]; - preConfigure = - # "Inline" .version so it's not a symlink, and includes the suffix. - # Do the meson utils, without modification. - '' - chmod u+w ./.version - echo ${version} > ../../../.version - ''; - mesonFlags = [ ]; meta = { + mainProgram = "nix"; platforms = lib.platforms.unix ++ lib.platforms.windows; }; diff --git a/pkgs/tools/package-management/nix/2_26/tests/functional/package.nix b/pkgs/tools/package-management/nix/2_26/tests/functional/package.nix index 74c034196fde7..c479d6ca38d3a 100644 --- a/pkgs/tools/package-management/nix/2_26/tests/functional/package.nix +++ b/pkgs/tools/package-management/nix/2_26/tests/functional/package.nix @@ -75,16 +75,10 @@ mkMesonDerivation ( ]; preConfigure = - # "Inline" .version so it's not a symlink, and includes the suffix. - # Do the meson utils, without modification. - '' - chmod u+w ./.version - echo ${version} > ../../../.version - '' # TEMP hack for Meson before make is gone, where # `src/nix-functional-tests` is during the transition a symlink and # not the actual directory directory. - + '' + '' cd $(readlink -e $PWD) echo $PWD | grep tests/functional ''; @@ -106,5 +100,6 @@ mkMesonDerivation ( } // lib.optionalAttrs (test-daemon != null) { NIX_DAEMON_PACKAGE = test-daemon; + _NIX_TEST_CLIENT_VERSION = nix-cli.version; } ) diff --git a/pkgs/tools/package-management/nix/default.nix b/pkgs/tools/package-management/nix/default.nix index 23b11f1c62857..38583c18eabee 100644 --- a/pkgs/tools/package-management/nix/default.nix +++ b/pkgs/tools/package-management/nix/default.nix @@ -137,6 +137,29 @@ let } pkg; + # (meson based packaging) + # Add passthru tests to the package, and re-expose package set overriding + # functions. This will not incorporate the tests into the package set. + # TODO (roberth): add package-set level overriding to the "everything" package. + addTests = selfAttributeName: pkg: + let + tests = + pkg.tests or {} + // import ./tests.nix { + inherit runCommand lib stdenv pkgs pkgsi686Linux pkgsStatic nixosTests; + inherit (pkg) version src; + nix = pkg; + self_attribute_name = selfAttributeName; + }; + in + # preserve old pkg, including overrideSource, etc + pkg // { + tests = pkg.tests or {} // tests; + passthru = pkg.passthru or {} // { + tests = lib.warn "nix.passthru.tests is deprecated. Use nix.tests instead." pkg.passthru.tests or {} // tests; + }; + }; + in lib.makeExtensible (self: ({ nix_2_3 = ((common { version = "2.3.18"; @@ -164,18 +187,7 @@ in lib.makeExtensible (self: ({ self_attribute_name = "nix_2_25"; }; - nix_2_26 = (callPackage ./2_26/componentized.nix { }).overrideAttrs (this: old: { - passthru = old.passthru or {} // { - tests = - old.passthru.tests or {} - // import ./tests.nix { - inherit runCommand lib stdenv pkgs pkgsi686Linux pkgsStatic nixosTests; - inherit (old) version src; - nix = this.finalPackage; - self_attribute_name = "nix_2_26"; - }; - }; - }); + nix_2_26 = addTests "nix_2_26" (callPackage ./2_26/componentized.nix { }); git = common rec { version = "2.25.0";