tests.nixpkgs-check-by-name: auto-calling differentiation

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.

+43 -7
+17
pkgs/test/nixpkgs-check-by-name/src/eval.nix
··· 35 35 else 36 36 # It's very rare that callPackage doesn't return an attribute set, but it can occur. 37 37 variantInfo; 38 + 39 + _internalCallByNamePackageFile = file: 40 + let 41 + result = super._internalCallByNamePackageFile file; 42 + variantInfo._attributeVariant = { 43 + # This name is used by the deserializer on the Rust side 44 + AutoCalled = null; 45 + }; 46 + in 47 + if builtins.isAttrs result then 48 + # If this was the last overlay to be applied, we could just only return the `_callPackagePath`, 49 + # but that's not the case because stdenv has another overlays on top of user-provided ones. 50 + # So to not break the stdenv build we need to return the mostly proper result here 51 + result // variantInfo 52 + else 53 + # It's very rare that callPackage doesn't return an attribute set, but it can occur. 54 + variantInfo; 38 55 }; 39 56 40 57 pkgs = import nixpkgsPath {
+6 -1
pkgs/test/nixpkgs-check-by-name/src/eval.rs
··· 19 19 20 20 #[derive(Deserialize)] 21 21 enum AttributeVariant { 22 - /// The attribute is defined as a pkgs.callPackage <path> 22 + /// The attribute is auto-called as pkgs.callPackage using pkgs/by-name, 23 + /// and it is not overridden by a definition in all-packages.nix 24 + AutoCalled, 25 + /// The attribute is defined as a pkgs.callPackage <path>, 26 + /// and overridden by all-packages.nix 23 27 /// The path is None when the <path> argument isn't a path 24 28 CallPackage { path: Option<PathBuf> }, 25 29 /// The attribute is not defined as pkgs.callPackage ··· 107 111 108 112 if let Some(attribute_info) = actual_files.get(package_name) { 109 113 let valid = match &attribute_info.variant { 114 + AttributeVariant::AutoCalled => true, 110 115 AttributeVariant::CallPackage { path } => { 111 116 if let Some(call_package_path) = path { 112 117 absolute_package_file == *call_package_path
+8 -3
pkgs/test/nixpkgs-check-by-name/tests/mock-nixpkgs.nix
··· 75 75 76 76 # Turns autoCalledPackageFiles into an overlay that `callPackage`'s all of them 77 77 autoCalledPackages = self: super: 78 - builtins.mapAttrs (name: file: 79 - self.callPackage file { } 80 - ) autoCalledPackageFiles; 78 + { 79 + # Needed to be able to detect empty arguments in all-packages.nix 80 + # See a more detailed description in pkgs/top-level/by-name-overlay.nix 81 + _internalCallByNamePackageFile = file: self.callPackage file { }; 82 + } 83 + // builtins.mapAttrs 84 + (name: self._internalCallByNamePackageFile) 85 + autoCalledPackageFiles; 81 86 82 87 # A list optionally containing the `all-packages.nix` file from the test case as an overlay 83 88 optionalAllPackagesOverlay =
+12 -3
pkgs/top-level/by-name-overlay.nix
··· 45 45 # Currently this would be hard to measure until we have more packages 46 46 # and ideally https://github.com/NixOS/nix/pull/8895 47 47 self: super: 48 - mapAttrs (name: file: 49 - self.callPackage file { } 50 - ) packageFiles 48 + { 49 + # This attribute is necessary to allow CI to ensure that all packages defined in `pkgs/by-name` 50 + # don't have an overriding definition in `all-packages.nix` with an empty (`{ }`) second `callPackage` argument. 51 + # It achieves that with an overlay that modifies both `callPackage` and this attribute to signal whether `callPackage` is used 52 + # and whether it's defined by this file here or `all-packages.nix`. 53 + # 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). 54 + # 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. 55 + _internalCallByNamePackageFile = file: self.callPackage file { }; 56 + } 57 + // mapAttrs 58 + (name: self._internalCallByNamePackageFile) 59 + packageFiles