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.
···35 else
36 # It's very rare that callPackage doesn't return an attribute set, but it can occur.
37 variantInfo;
0000000000000000038 };
3940 pkgs = import nixpkgsPath {
···35 else
36 # It's very rare that callPackage doesn't return an attribute set, but it can occur.
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;
55 };
5657 pkgs = import nixpkgsPath {
+6-1
pkgs/test/nixpkgs-check-by-name/src/eval.rs
···1920#[derive(Deserialize)]
21enum AttributeVariant {
22- /// The attribute is defined as a pkgs.callPackage <path>
000023 /// The path is None when the <path> argument isn't a path
24 CallPackage { path: Option<PathBuf> },
25 /// The attribute is not defined as pkgs.callPackage
···107108 if let Some(attribute_info) = actual_files.get(package_name) {
109 let valid = match &attribute_info.variant {
0110 AttributeVariant::CallPackage { path } => {
111 if let Some(call_package_path) = path {
112 absolute_package_file == *call_package_path
···1920#[derive(Deserialize)]
21enum AttributeVariant {
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
27 /// The path is None when the <path> argument isn't a path
28 CallPackage { path: Option<PathBuf> },
29 /// The attribute is not defined as pkgs.callPackage
···111112 if let Some(attribute_info) = actual_files.get(package_name) {
113 let valid = match &attribute_info.variant {
114+ AttributeVariant::AutoCalled => true,
115 AttributeVariant::CallPackage { path } => {
116 if let Some(call_package_path) = path {
117 absolute_package_file == *call_package_path
···7576 # Turns autoCalledPackageFiles into an overlay that `callPackage`'s all of them
77 autoCalledPackages = self: super:
78- builtins.mapAttrs (name: file:
79- self.callPackage file { }
80- ) autoCalledPackageFiles;
000008182 # A list optionally containing the `all-packages.nix` file from the test case as an overlay
83 optionalAllPackagesOverlay =
···7576 # Turns autoCalledPackageFiles into an overlay that `callPackage`'s all of them
77 autoCalledPackages = self: super:
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;
8687 # A list optionally containing the `all-packages.nix` file from the test case as an overlay
88 optionalAllPackagesOverlay =
+12-3
pkgs/top-level/by-name-overlay.nix
···45# Currently this would be hard to measure until we have more packages
46# and ideally https://github.com/NixOS/nix/pull/8895
47self: super:
48-mapAttrs (name: file:
49- self.callPackage file { }
50-) packageFiles
000000000
···45# Currently this would be hard to measure until we have more packages
46# and ideally https://github.com/NixOS/nix/pull/8895
47self: super:
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