about summary refs log tree commit diff
path: root/pkgs/test
diff options
context:
space:
mode:
authorSilvan Mosberger <silvan.mosberger@tweag.io>2023-10-12 01:00:37 +0200
committerSilvan Mosberger <silvan.mosberger@tweag.io>2023-10-12 02:27:55 +0200
commitfcaa408d005743b34aed8b7e2992ef885b4ce027 (patch)
tree1d9318fb80532640e0a405fa8dfd0bfce45f241f /pkgs/test
parentf394f738faaee2a749eae7c507dccb1830dd440a (diff)
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.
Diffstat (limited to 'pkgs/test')
-rw-r--r--pkgs/test/nixpkgs-check-by-name/src/eval.nix17
-rw-r--r--pkgs/test/nixpkgs-check-by-name/src/eval.rs7
-rw-r--r--pkgs/test/nixpkgs-check-by-name/tests/mock-nixpkgs.nix11
3 files changed, 31 insertions, 4 deletions
diff --git a/pkgs/test/nixpkgs-check-by-name/src/eval.nix b/pkgs/test/nixpkgs-check-by-name/src/eval.nix
index 087b0a519c719..2fa0c5a9709c1 100644
--- a/pkgs/test/nixpkgs-check-by-name/src/eval.nix
+++ b/pkgs/test/nixpkgs-check-by-name/src/eval.nix
@@ -35,6 +35,23 @@ let
       else
         # It's very rare that callPackage doesn't return an attribute set, but it can occur.
         variantInfo;
+
+    _internalCallByNamePackageFile = file:
+      let
+        result = super._internalCallByNamePackageFile file;
+        variantInfo._attributeVariant = {
+          # This name is used by the deserializer on the Rust side
+          AutoCalled = null;
+        };
+      in
+      if builtins.isAttrs result then
+        # If this was the last overlay to be applied, we could just only return the `_callPackagePath`,
+        # but that's not the case because stdenv has another overlays on top of user-provided ones.
+        # So to not break the stdenv build we need to return the mostly proper result here
+        result // variantInfo
+      else
+        # It's very rare that callPackage doesn't return an attribute set, but it can occur.
+        variantInfo;
   };
 
   pkgs = import nixpkgsPath {
diff --git a/pkgs/test/nixpkgs-check-by-name/src/eval.rs b/pkgs/test/nixpkgs-check-by-name/src/eval.rs
index 53a813045eee8..b1c1a44f8c080 100644
--- a/pkgs/test/nixpkgs-check-by-name/src/eval.rs
+++ b/pkgs/test/nixpkgs-check-by-name/src/eval.rs
@@ -19,7 +19,11 @@ struct AttributeInfo {
 
 #[derive(Deserialize)]
 enum AttributeVariant {
-    /// The attribute is defined as a pkgs.callPackage <path>
+    /// The attribute is auto-called as pkgs.callPackage using pkgs/by-name,
+    /// and it is not overridden by a definition in all-packages.nix
+    AutoCalled,
+    /// The attribute is defined as a pkgs.callPackage <path>,
+    /// and overridden by all-packages.nix
     /// The path is None when the <path> argument isn't a path
     CallPackage { path: Option<PathBuf> },
     /// The attribute is not defined as pkgs.callPackage
@@ -107,6 +111,7 @@ pub fn check_values<W: io::Write>(
 
         if let Some(attribute_info) = actual_files.get(package_name) {
             let valid = match &attribute_info.variant {
+                AttributeVariant::AutoCalled => true,
                 AttributeVariant::CallPackage { path } => {
                     if let Some(call_package_path) = path {
                         absolute_package_file == *call_package_path
diff --git a/pkgs/test/nixpkgs-check-by-name/tests/mock-nixpkgs.nix b/pkgs/test/nixpkgs-check-by-name/tests/mock-nixpkgs.nix
index 50ad67617542d..01bb27a480388 100644
--- a/pkgs/test/nixpkgs-check-by-name/tests/mock-nixpkgs.nix
+++ b/pkgs/test/nixpkgs-check-by-name/tests/mock-nixpkgs.nix
@@ -75,9 +75,14 @@ let
 
   # Turns autoCalledPackageFiles into an overlay that `callPackage`'s all of them
   autoCalledPackages = self: super:
-    builtins.mapAttrs (name: file:
-      self.callPackage file { }
-    ) autoCalledPackageFiles;
+    {
+      # Needed to be able to detect empty arguments in all-packages.nix
+      # See a more detailed description in pkgs/top-level/by-name-overlay.nix
+      _internalCallByNamePackageFile = file: self.callPackage file { };
+    }
+    // builtins.mapAttrs
+      (name: self._internalCallByNamePackageFile)
+      autoCalledPackageFiles;
 
   # A list optionally containing the `all-packages.nix` file from the test case as an overlay
   optionalAllPackagesOverlay =