From cbff02834f3c0a1daa3502566fcf19433f9ca214 Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Wed, 10 Jan 2024 19:21:07 +0100 Subject: [PATCH] tests.nixpkgs-check-by-name: Sort the eval validation results Not that important, but nice. Also adds a nice test case show-casing the two current ratchet checks at once. --- pkgs/test/nixpkgs-check-by-name/src/eval.nix | 51 ++++++++++--------- .../tests/sorted-order/all-packages.nix | 6 +++ .../tests/sorted-order/default.nix | 1 + .../tests/sorted-order/expected | 4 ++ .../sorted-order/pkgs/by-name/a/a/package.nix | 1 + .../sorted-order/pkgs/by-name/c/c/package.nix | 1 + 6 files changed, 40 insertions(+), 24 deletions(-) create mode 100644 pkgs/test/nixpkgs-check-by-name/tests/sorted-order/all-packages.nix create mode 100644 pkgs/test/nixpkgs-check-by-name/tests/sorted-order/default.nix create mode 100644 pkgs/test/nixpkgs-check-by-name/tests/sorted-order/expected create mode 100644 pkgs/test/nixpkgs-check-by-name/tests/sorted-order/pkgs/by-name/a/a/package.nix create mode 100644 pkgs/test/nixpkgs-check-by-name/tests/sorted-order/pkgs/by-name/c/c/package.nix diff --git a/pkgs/test/nixpkgs-check-by-name/src/eval.nix b/pkgs/test/nixpkgs-check-by-name/src/eval.nix index f13dbd167a00..87c54b6444ee 100644 --- a/pkgs/test/nixpkgs-check-by-name/src/eval.nix +++ b/pkgs/test/nixpkgs-check-by-name/src/eval.nix @@ -79,34 +79,37 @@ let }; }; - byNameAttrs = map (name: [ - name - { - ByName = - if ! pkgs ? ${name} then - { Missing = null; } - else - { Existing = attrInfo name pkgs.${name}; }; - } - ]) attrs; + byNameAttrs = builtins.listToAttrs (map (name: { + inherit name; + value.ByName = + if ! pkgs ? ${name} then + { Missing = null; } + else + { Existing = attrInfo name pkgs.${name}; }; + }) attrs); # Information on all attributes that exist but are not in pkgs/by-name. # We need this to enforce pkgs/by-name for new packages - nonByNameAttrs = map (name: + nonByNameAttrs = builtins.mapAttrs (name: value: let - output = attrInfo name pkgs.${name}; + output = attrInfo name value; result = builtins.tryEval (builtins.deepSeq output null); in - [ - name - { - NonByName = - if result.success then - { EvalSuccess = output; } - else - { EvalFailure = null; }; - } - ] - ) (builtins.attrNames (builtins.removeAttrs pkgs attrs)); + { + NonByName = + if result.success then + { EvalSuccess = output; } + else + { EvalFailure = null; }; + } + ) (builtins.removeAttrs pkgs attrs); + + # All attributes + attributes = byNameAttrs // nonByNameAttrs; in -byNameAttrs ++ nonByNameAttrs +# We output them in the form [ [ ] ]` such that the Rust side +# doesn't need to sort them again to get deterministic behavior (good for testing) +map (name: [ + name + attributes.${name} +]) (builtins.attrNames attributes) diff --git a/pkgs/test/nixpkgs-check-by-name/tests/sorted-order/all-packages.nix b/pkgs/test/nixpkgs-check-by-name/tests/sorted-order/all-packages.nix new file mode 100644 index 000000000000..688f52b9358f --- /dev/null +++ b/pkgs/test/nixpkgs-check-by-name/tests/sorted-order/all-packages.nix @@ -0,0 +1,6 @@ +self: super: { + a = self.callPackage ./pkgs/by-name/a/a/package.nix { }; + b = self.callPackage ({ someDrv }: someDrv) { }; + c = self.callPackage ./pkgs/by-name/c/c/package.nix { }; + d = self.callPackage ({ someDrv }: someDrv) { }; +} diff --git a/pkgs/test/nixpkgs-check-by-name/tests/sorted-order/default.nix b/pkgs/test/nixpkgs-check-by-name/tests/sorted-order/default.nix new file mode 100644 index 000000000000..af25d1450122 --- /dev/null +++ b/pkgs/test/nixpkgs-check-by-name/tests/sorted-order/default.nix @@ -0,0 +1 @@ +import ../mock-nixpkgs.nix { root = ./.; } diff --git a/pkgs/test/nixpkgs-check-by-name/tests/sorted-order/expected b/pkgs/test/nixpkgs-check-by-name/tests/sorted-order/expected new file mode 100644 index 000000000000..349e9ad47c41 --- /dev/null +++ b/pkgs/test/nixpkgs-check-by-name/tests/sorted-order/expected @@ -0,0 +1,4 @@ +pkgs.a: This attribute is manually defined (most likely in pkgs/top-level/all-packages.nix), which is only allowed if the definition is of the form `pkgs.callPackage pkgs/by-name/a/a/package.nix { ... }` with a non-empty second argument. +pkgs.b: This is a new top-level package of the form `callPackage ... { }`. Please define it in pkgs/by-name/b/b/package.nix instead. See `pkgs/by-name/README.md` for more details. Since the second `callPackage` argument is `{ }`, no manual `callPackage` (e.g. in `pkgs/top-level/all-packages.nix`) is needed anymore. +pkgs.c: This attribute is manually defined (most likely in pkgs/top-level/all-packages.nix), which is only allowed if the definition is of the form `pkgs.callPackage pkgs/by-name/c/c/package.nix { ... }` with a non-empty second argument. +pkgs.d: This is a new top-level package of the form `callPackage ... { }`. Please define it in pkgs/by-name/d/d/package.nix instead. See `pkgs/by-name/README.md` for more details. Since the second `callPackage` argument is `{ }`, no manual `callPackage` (e.g. in `pkgs/top-level/all-packages.nix`) is needed anymore. diff --git a/pkgs/test/nixpkgs-check-by-name/tests/sorted-order/pkgs/by-name/a/a/package.nix b/pkgs/test/nixpkgs-check-by-name/tests/sorted-order/pkgs/by-name/a/a/package.nix new file mode 100644 index 000000000000..a1b92efbbadb --- /dev/null +++ b/pkgs/test/nixpkgs-check-by-name/tests/sorted-order/pkgs/by-name/a/a/package.nix @@ -0,0 +1 @@ +{ someDrv }: someDrv diff --git a/pkgs/test/nixpkgs-check-by-name/tests/sorted-order/pkgs/by-name/c/c/package.nix b/pkgs/test/nixpkgs-check-by-name/tests/sorted-order/pkgs/by-name/c/c/package.nix new file mode 100644 index 000000000000..a1b92efbbadb --- /dev/null +++ b/pkgs/test/nixpkgs-check-by-name/tests/sorted-order/pkgs/by-name/c/c/package.nix @@ -0,0 +1 @@ +{ someDrv }: someDrv