Allows detecting whether attributes are overridden in all-packages.nix. In a future commit we'll use this to detect empty arguments being set in all-packages.nix and complain about that.
···3535 else
3636 # It's very rare that callPackage doesn't return an attribute set, but it can occur.
3737 variantInfo;
3838+3939+ _internalCallByNamePackageFile = file:
4040+ let
4141+ result = super._internalCallByNamePackageFile file;
4242+ variantInfo._attributeVariant = {
4343+ # This name is used by the deserializer on the Rust side
4444+ AutoCalled = null;
4545+ };
4646+ in
4747+ if builtins.isAttrs result then
4848+ # If this was the last overlay to be applied, we could just only return the `_callPackagePath`,
4949+ # but that's not the case because stdenv has another overlays on top of user-provided ones.
5050+ # So to not break the stdenv build we need to return the mostly proper result here
5151+ result // variantInfo
5252+ else
5353+ # It's very rare that callPackage doesn't return an attribute set, but it can occur.
5454+ variantInfo;
3855 };
39564057 pkgs = import nixpkgsPath {
+6-1
pkgs/test/nixpkgs-check-by-name/src/eval.rs
···19192020#[derive(Deserialize)]
2121enum AttributeVariant {
2222- /// The attribute is defined as a pkgs.callPackage <path>
2222+ /// The attribute is auto-called as pkgs.callPackage using pkgs/by-name,
2323+ /// and it is not overridden by a definition in all-packages.nix
2424+ AutoCalled,
2525+ /// The attribute is defined as a pkgs.callPackage <path>,
2626+ /// and overridden by all-packages.nix
2327 /// The path is None when the <path> argument isn't a path
2428 CallPackage { path: Option<PathBuf> },
2529 /// The attribute is not defined as pkgs.callPackage
···107111108112 if let Some(attribute_info) = actual_files.get(package_name) {
109113 let valid = match &attribute_info.variant {
114114+ AttributeVariant::AutoCalled => true,
110115 AttributeVariant::CallPackage { path } => {
111116 if let Some(call_package_path) = path {
112117 absolute_package_file == *call_package_path
···75757676 # Turns autoCalledPackageFiles into an overlay that `callPackage`'s all of them
7777 autoCalledPackages = self: super:
7878- builtins.mapAttrs (name: file:
7979- self.callPackage file { }
8080- ) autoCalledPackageFiles;
7878+ {
7979+ # Needed to be able to detect empty arguments in all-packages.nix
8080+ # See a more detailed description in pkgs/top-level/by-name-overlay.nix
8181+ _internalCallByNamePackageFile = file: self.callPackage file { };
8282+ }
8383+ // builtins.mapAttrs
8484+ (name: self._internalCallByNamePackageFile)
8585+ autoCalledPackageFiles;
81868287 # A list optionally containing the `all-packages.nix` file from the test case as an overlay
8388 optionalAllPackagesOverlay =
+12-3
pkgs/top-level/by-name-overlay.nix
···4545# Currently this would be hard to measure until we have more packages
4646# and ideally https://github.com/NixOS/nix/pull/8895
4747self: super:
4848-mapAttrs (name: file:
4949- self.callPackage file { }
5050-) packageFiles
4848+{
4949+ # This attribute is necessary to allow CI to ensure that all packages defined in `pkgs/by-name`
5050+ # don't have an overriding definition in `all-packages.nix` with an empty (`{ }`) second `callPackage` argument.
5151+ # It achieves that with an overlay that modifies both `callPackage` and this attribute to signal whether `callPackage` is used
5252+ # and whether it's defined by this file here or `all-packages.nix`.
5353+ # TODO: This can be removed once `pkgs/by-name` can handle custom `callPackage` arguments without `all-packages.nix` (or any other way of achieving the same result).
5454+ # Because at that point the code in ./stage.nix can be changed to not allow definitions in `all-packages.nix` to override ones from `pkgs/by-name` anymore and throw an error if that happens instead.
5555+ _internalCallByNamePackageFile = file: self.callPackage file { };
5656+}
5757+// mapAttrs
5858+ (name: self._internalCallByNamePackageFile)
5959+ packageFiles