Commit Graph

139 Commits

Author SHA1 Message Date
Silvan Mosberger
9da57b5bd3 check-by-name/run-local.sh: Make it usable for non-CI platforms
Since https://github.com/NixOS/nixpkgs/pull/281374, the
nixpkgs-check-by-name tooling is pinned to a specific /nix/store path to
avoid having to evaluate Nixpkgs in CI.

The same path is used for local runs, but that doesn't actually work
when you're trying to run it on a platform different from CI.

This commit makes it work by being clearer about platforms and making
local runs check out the correct Nixpkgs to evaluate the tool from.
2024-01-17 10:45:23 +01:00
Silvan Mosberger
2dd7f0e8b9 tests.nixpkgs-check-by-name: Use NIX_PATH for extra test files
This avoids the need for a bunch of Rust code, but also enables us to
fairly easily make all the Nixpkgs tests evaluatable within the
nix-shell
2024-01-17 10:43:12 +01:00
Silvan Mosberger
64ad8b6836 tests.nixpkgs-check-by-name: Limit source files
To prevent more rebuilds than necessary
2024-01-17 10:40:03 +01:00
Silvan Mosberger
a48d8eafc6
Merge pull request #281390 from tweag/by-name-alias-fix
tests.nixpkgs-check-by-name: Fix for aliases to packages in `pkgs/by-name` and better testing
2024-01-17 10:37:42 +01:00
Silvan Mosberger
6d5f575fd0 check-by-name: Remove legacy script
fetch-tool.sh was decommissioned in
https://github.com/NixOS/nixpkgs/pull/281374, see the removed comment
for why it can only be removed now
2024-01-16 21:50:34 +01:00
Silvan Mosberger
0f27917d9a tests.nixpkgs-check-by-name: Don't error for pkgs/by-name aliases
This was an oversight in https://github.com/NixOS/nixpkgs/pull/275539
not accounted for, which would've failed in CI
2024-01-16 21:18:37 +01:00
Silvan Mosberger
3ebd239cd5 tests.nixpkgs-check-by-name: Test on the current Nixpkgs
This test actually fails right now
2024-01-16 21:15:42 +01:00
Silvan Mosberger
91b754edff tests.nixpkgs-check-by-name: Minor Nix build refactor 2024-01-16 21:15:40 +01:00
Silvan Mosberger
cc422e321e workflows/check-by-name: Pin nixpkgs-check-by-name tool
Before this, the tool for CI would update when nixos-unstable updated,
which is kind of terrible because you don't know when it happens, and it
might break master.

In fact, the tooling _right now_ has a serious bug and shouldn't be used!

This PR addresses this by _pinning_ the tooling in Nixpkgs itself.

Updating the tooling now requires two PRs:
- The first PR to update the tooling source
- (wait for Hydra to build and publish it in nixos-unstable)
- The second PR to update the pinned tooling

In turn you know exactly when the changes are going to take effect.

This change however has additional benefits:
- It makes CI more reproducible, because it doesn't depend on the state
  of nixos-unstable anymore
- Updates to the tooling can be tested with the workflow itself,
  because PRs that update the pinned tool will be tested on the updated
  version
- CI gets a sizable speed boost, because there's no need to download and
  evaluate a channel anymore
- It makes it more realistic to move the source of the tool into a
  separate repository
- It removes the brittle branch-specific logic that was previously
  needed to ensure that release branches use their own version of the
  tooling.
2024-01-16 19:58:19 +01:00
Silvan Mosberger
aa7dd0b596 tests.nixpkgs-check-by-name: Improve lib path handling in tests
nix-build failed because the tests assume to run in a CWD equal to the
project root, which is not the case in the derivation build.

This commit fixes it by not using hacky `..` references to paths,
and instead uses NIX_PATH for all implicit Nix testing path
dependencies.

Also the root of the `lib` path gets passed in from the `default.nix`
file, so all the relative path handling is done by Nix during evaluation
already, and in the Nix store when possible.
2024-01-15 18:34:16 +01:00
Silvan Mosberger
be26d74840 tests.nixpkgs-check-by-name: Add test for alternate callPackage's
Tests that alternate callPackage's don't give an error, so pkgs/by-name
is only required for pkgs.callPackage itself
2024-01-10 19:55:24 +01:00
Silvan Mosberger
d659d5f8ac tests.nixpkgs-check-by-name: Use real lib for tests
This way we can also detect regressions caused by lib
2024-01-10 19:43:17 +01:00
Silvan Mosberger
cbff02834f 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.
2024-01-10 19:29:27 +01:00
Silvan Mosberger
57afdc545b tests.nixpkgs-check-by-name: Enforce pkgs/by-name for new packages 2024-01-10 19:29:26 +01:00
Silvan Mosberger
69fc71a82c tests.nixpkgs-check-by-name: Basic info for non-by-name attributes
In a future commit this will be extended
2024-01-10 19:28:19 +01:00
Silvan Mosberger
da3e72b915
Merge pull request #278805 from tweag/by-name-enforce-preparation
check-by-name: Refactor to prepare for enforcing `pkgs/by-name`, make `--base` required
2024-01-09 22:58:53 +01:00
Silvan Mosberger
a1db0cdf9b tests.nixpkgs-check-by-name: .context -> .with_context
Avoids allocation in the non-error case
2024-01-09 19:39:50 +01:00
Silvan Mosberger
4cd2e64db3 tests.nixpkgs-check-by-name: Minor improvements from feedback
- Typo
- Rename AttributeRatchet to ToNixpkgsProblem
- Make the compare trait method into a RatchetState method

Co-Authored-By: Philip Taron <philip.taron@gmail.com>
2024-01-09 19:35:11 +01:00
Silvan Mosberger
54b05324f4 tests.nixpkgs-check-by-name: Internal strip nixpkgs prefix
Strips the Nixpkgs prefix from the callPackage paths,
makes future error messages using this path be deterministic.
2024-01-05 02:01:55 +01:00
Silvan Mosberger
27c873af99 tests.nixpkgs-check-by-name: Deterministic ordering
Makes errors for attributes deterministic so it's easier to test (also,
reproducibility is always nice)
2024-01-05 02:01:55 +01:00
Silvan Mosberger
2a8f469348 tests.nixpkgs-check-by-name: Re-usable ratchet logic
This makes the attribute ratchet check logic more re-usable, which will
be used in a future commit.

It also renames the ratchet states to something more intuitive
2024-01-05 02:01:50 +01:00
Silvan Mosberger
ba6faf428f tests.nixpkgs-check-by-name: Make --base required
CI now passes the flag, so it doesn't have to be optional anymore
2024-01-05 01:05:50 +01:00
Silvan Mosberger
66f29590c0 tests.nixpkgs-check-by-name: Set evaluation system to x86_64-linux
This was previously a checking impurity that could produce different
results when run on different systems.
2024-01-05 01:05:44 +01:00
Silvan Mosberger
5b7ae79ef0 tests.nixpkgs-check-by-name: Refactor eval code and improve comments
Does a bunch of cleanups to the eval.{rs,nix} code to make future
changes easier, no functionality is changed.
2024-01-03 19:56:54 +01:00
Silvan Mosberger
e130ee33a1 pkgs/test/nixpkgs-check-by-name/scripts: Various improvements
- trace function, avoids littering `echo >&2` all throughout
- Avoid `eval`, remove unneeded shellcheck

Co-Authored-By: Victor Engmark <victor@engmark.name>
2023-12-22 00:04:16 +01:00
Silvan Mosberger
1968beeabd check-by-name: Pass --base in CI and local running script
This enables the ratchet checks for pkgs/by-name, allowing gradual
migrations!
2023-12-20 17:38:06 +01:00
Silvan Mosberger
9e03178865 tests.nixpkgs-check-by-name: Add documentation for scripts 2023-12-20 17:38:05 +01:00
Silvan Mosberger
92238ac52d tests.nixpkgs-check-by-name: Create script to run locally
Due to the check soon depending on the base branch (see `--base`),
the CI check can't reasonably share all code with a local check.
We can still make a script to run it locally, just not sharing all code.
2023-12-20 17:38:03 +01:00
Silvan Mosberger
3869ba4127 workflows/check-by-name: Move tool fetching into script
This part of the CI can also be reproduced locally
2023-12-19 23:15:01 +01:00
Silvan Mosberger
fc2d26939d tests.nixpkgs-check-by-name: Improve check clarity 2023-12-15 17:27:26 +01:00
Silvan Mosberger
74e8b38dbe tests.nixpkgs-check-by-name: Move interface description into code
This would be duplicated otherwise
2023-12-15 02:28:55 +01:00
Silvan Mosberger
79618ff8cb tests.nixpkgs-check-by-name: Improve docs, introduce "ratchet" term 2023-12-15 02:14:48 +01:00
Silvan Mosberger
413dd9c03e tests.nixpkgs-check-by-name: Minor improvements from review 2023-12-15 01:02:49 +01:00
Silvan Mosberger
53b43ce0e3 tests.nixpkgs-check-by-name: Fix and document behavior without --base
Previously, not passing `--base` would enforce the most strict checks.
While there's currently no actual violation of these stricter checks,
this does not match the previous behavior.

This won't matter once CI passes `--base`, the code handling the
optionality can be removed then.
2023-12-15 01:01:14 +01:00
Silvan Mosberger
bb08bfc2d3 tests.nixpkgs-check-by-name: Test for gradual transition
This implements the ability to test gradual transitions in check
strictness, and adds one such test for the empty non-auto-called
arguments check.
2023-12-14 04:05:03 +01:00
Silvan Mosberger
d487a975cc tests.nixpkgs-check-by-name: Gradual migration from base Nixpkgs
This implements the option for a gradual migration to stricter checks.
For now this is only done for the check against empty non-auto-called
callPackage arguments, but in the future this can be used to ensure all
new packages make use of `pkgs/by-name`.

This is implemented by adding a `--base <BASE_NIXPKGS>` flag, which then
compares the base nixpkgs against the main nixpkgs version, making sure
that there are no regressions.

The `--version` flag is removed. While it was implemented, it was never
used in CI, so this is fine.
2023-12-14 03:51:10 +01:00
Silvan Mosberger
a6ba4cae31 tests.nixpkgs-check-by-name: Intermediate refactor
This prepares the code base for the removal of the `--version` flag, to
be replaced with a flag that can specify a base version to compare the
main Nixpkgs against, in order to have gradual transitions to stricter
checks.

This refactoring does:
- Introduce the `version` module that can house the logic to increase
  strictness, with a `version::Nixpkgs` struct that contains the
  strictness conformity of a single Nixpkgs version
- Make the check return `version::Nixpkgs`
- Handle the behavior of the still-existing `--version` flag with `version::Nixpkgs`
- Introduce an intermediate `process` function to handle the top-level
  logic, especially useful in the next commit
2023-12-14 03:40:49 +01:00
Silvan Mosberger
e98d22851b tests.nixpkgs-check-by-name: Introduce result_map
Convenience function to run another validation over a successful validation result.

This will be usable in more locations in future commits, making the code
nicer.
2023-12-14 03:21:41 +01:00
Silvan Mosberger
b8e4d555b4 tests.nixpkgs-check-by-name: Minor refactor, allow more simultaneous problems
This makes it such that these two errors can both be thrown for a single
package:
- The attribute value not being a derivation
- The attribute not being a proper callPackage

The tests had to be adjusted to only throw the error they were testing
for
2023-12-14 03:13:36 +01:00
Silvan Mosberger
6361b22370
Merge pull request #267048 from narang99/hariom/257748/check-by-name-msg
fix long error messages in nix-instantiate
2023-11-21 01:35:11 +01:00
Hariom Narang
ca97497bfd made EXPR_PATH point to local instead of store
- we need this behavior in dev shell
- the main build still uses the store file
2023-11-21 01:11:06 +05:30
Silvan Mosberger
def5df923f tests.nixpkgs-check-by-name: More reliable .envrc reloading
See also https://github.com/nix-community/nix-direnv/issues/408 and https://github.com/nix-community/nix-direnv/pull/407
2023-11-18 04:54:05 +01:00
Hariom Narang
437b2054f4 pass eval.nix as a file instead of expression
- passing it as expression gives large error messages
  which are not very readable
- this commits puts the file in nix-store
  and patches the final program to have access to
  the path to the file as env.
- We simply pass this file to nix-instantiate
2023-11-14 15:05:45 +05:30
Silvan Mosberger
7753969628 tests.nixpkgs-check-by-name: Remove PackageContext helper
Was not really necessary anymore
2023-10-24 20:02:15 +02:00
Silvan Mosberger
82e708c192 tests.nixpkgs-check-by-name: Custom Validation type and improvements
Co-authored-by: Wanja Hentze
2023-10-24 19:58:52 +02:00
Silvan Mosberger
03c58ad1d6 tests.nixpkgs-check-by-name: Minor doc updates 2023-10-24 01:18:46 +02:00
Silvan Mosberger
8be41ace99 tests.nixpkgs-check-by-name: Separate file for all problems
And introduce a function for some smaller indentation
2023-10-24 01:18:46 +02:00
Silvan Mosberger
eac0b69063 tests.nixpkgs-check-by-name: Redesign and document check_result functions 2023-10-24 01:18:44 +02:00
Silvan Mosberger
3d60440799 tests.nixpkgs-check-by-name: Remove error writer 2023-10-24 01:18:13 +02:00
Silvan Mosberger
e58bc75444 tests.nixpkgs-check-by-name: Remove Nixpkgs struct
Isn't necessary anymore with the refactoring
2023-10-24 01:18:13 +02:00
Silvan Mosberger
d65f3ddb89 tests.nixpkgs-check-by-name: Make reference check part of structural check 2023-10-24 01:18:13 +02:00
Silvan Mosberger
0475238ec0 tests.nixpkgs-check-by-name: Make structural check a global function 2023-10-24 01:18:12 +02:00
Silvan Mosberger
83b887504c tests.nixpkgs-check-by-name: Support for combining check results 2023-10-24 01:18:09 +02:00
Silvan Mosberger
bb89ca72df tests.nixpkgs-check-by-name: Refactor 2023-10-24 01:15:58 +02:00
Silvan Mosberger
571eaed155 tests.nixpkgs-check-by-name: Intermediate ShardNonDir error 2023-10-24 01:15:58 +02:00
Silvan Mosberger
b7ace0198c tests.nixpkgs-check-by-name: Intermediate InvalidShardName error 2023-10-24 01:15:58 +02:00
Silvan Mosberger
143e267ad2 tests.nixpkgs-check-by-name: Intermediate PackageNonDir error 2023-10-24 01:15:58 +02:00
Silvan Mosberger
935f82267a tests.nixpkgs-check-by-name: Intermediate CaseSensitiveDuplicate error 2023-10-24 01:15:58 +02:00
Silvan Mosberger
e7d9cc96ed tests.nixpkgs-check-by-name: Intermediate InvalidPackageName error 2023-10-24 01:15:57 +02:00
Silvan Mosberger
b011d53bda tests.nixpkgs-check-by-name: Intermediate IncorrectShard error 2023-10-24 01:15:57 +02:00
Silvan Mosberger
64f5eb616e tests.nixpkgs-check-by-name: Intermediate PackageNixNonExistent error 2023-10-24 01:15:57 +02:00
Silvan Mosberger
e3979d14cd tests.nixpkgs-check-by-name: Intermediate PackageNixDir error 2023-10-24 01:15:57 +02:00
Silvan Mosberger
4f17b9367d tests.nixpkgs-check-by-name: Intermediate UndefinedAttr error 2023-10-24 01:15:57 +02:00
Silvan Mosberger
b688da8189 tests.nixpkgs-check-by-name: Intermediate WrongCallPackage error 2023-10-24 01:15:57 +02:00
Silvan Mosberger
9a0ef88623 tests.nixpkgs-check-by-name: Intermediate NonDerivation error 2023-10-24 01:15:57 +02:00
Silvan Mosberger
4897b63ae6 tests.nixpkgs-check-by-name: Intermediate Symlink errors 2023-10-24 01:15:57 +02:00
Silvan Mosberger
9a3abc4383 tests.nixpkgs-check-by-name: Intermediate CouldNotParseNix error 2023-10-24 01:15:57 +02:00
Silvan Mosberger
96f6a350fa tests.nixpkgs-check-by-name: Intermediate PathInterpolation error 2023-10-24 01:15:56 +02:00
Silvan Mosberger
a755aa7d02 tests.nixpkgs-check-by-name: Intermediate SearchPath error 2023-10-24 01:15:56 +02:00
Silvan Mosberger
ed56d74c08 tests.nixpkgs-check-by-name: Intermediate path reference errors 2023-10-24 01:15:56 +02:00
Silvan Mosberger
37f8f6681c tests.nixpkgs-check-by-name: Intermediate error type refactoring prep
Currently the tool prints problems right as it is checking the code
without an intermediate error representation. However for various reasons
it would be beneficial to have an intermediate error type:
- It makes the code cleaner, having all errors in one place
- It allows printing the error in different ways, e.g. for a future
  --json mode

This commit prepares for an incremental refactoring for an intermediate
error/problem representation. Most notable is that we want to be able to collect
multiple errors/problems and not just exit on the first one.

We introduce the type alias CheckResult and CheckError (later renamed to
NixpkgsProblem), where CheckError allows collecting multiple
CheckErrors using the utility function flatten_check_results (later
renamed to check_result::sequence)

The write_check_result function is only temporarily introduced to help
refactoring, it's removed again in later commits.
2023-10-24 01:11:57 +02:00
Silvan Mosberger
d3bf6133e8 tests.nixpkgs-check-by-name: Disallow empty all-packages.nix overrides
Only enabled with `--version v1`
2023-10-12 02:28:34 +02:00
Silvan Mosberger
23541bed72 tests.nixpkgs-check-by-name: Introduce --version 2023-10-12 02:28:09 +02:00
Silvan Mosberger
fcaa408d00 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.
2023-10-12 02:27:55 +02:00
Silvan Mosberger
f394f738fa tests.nixpkgs-check-by-name: Improve an error message 2023-10-12 02:27:13 +02:00
Silvan Mosberger
26cec0dbe3 tests.nixpkgs-check-by-name: Add custom argument test 2023-10-12 02:27:05 +02:00
Silvan Mosberger
6710bc250a tests.nixpkgs-check-by-name: Minor refactor
Allows a smaller diff for future changes
2023-10-12 02:27:02 +02:00
Silvan Mosberger
21d520fbf2 tests.nixpkgs-check-by-name: Minor Nix refactor 2023-10-12 02:24:54 +02:00
Silvan Mosberger
85d77bc124
Merge pull request #256913 from xfix/make-nixpkgs-check-by-name-tests-thread-safe
tests.nixpkgs-check-by-name: Make tests thread safe
2023-09-23 23:31:49 +02:00
Konrad Borowski
9efc0c0991 tests.nixpkgs-check-by-name: make tests thread safe
This uses a mutex to make sure that functions that read environment
don't read incorrect values.
2023-09-23 21:24:44 +02:00
figsoda
6728e7a9ca tests.nixpkgs-check-by-name: remove unused dependency
looks like we are not using rowan directly
2023-09-23 10:12:21 -04:00
Silvan Mosberger
1fe58cb050 tests.nixpkgs-check-by-name: Fix non-reproducible test failures
This was an oversight in https://github.com/NixOS/nixpkgs/pull/254435
2023-09-23 00:09:26 +02:00
Silvan Mosberger
9c9a7e0082 tests.nixpkgs-check-by-name: Fix with parallel tests
We seem to have enough tests to run into this now:

    error: creating symlink from '/private/tmp/nix-build-nixpkgs-check-by-name.drv-0/source/test-tmp/var/nix/gcroots/profiles' to '/private/tmp/nix-build-nixpkgs-check-by-name.drv-0/source/test-tmp/var/nix/profiles': File exists
2023-09-12 01:07:47 +02:00
Silvan Mosberger
d518eb94ee tests.nixpkgs-check-by-name: Fix for symlinked tempdirs
On Darwin, /tmp is sometimes a symlink to /private/tmp, which couldn't
be handled before:

    error: access to canonical path '/private/var/folders/xp/9_ry6h9x6l9gh_g32qspz0_40000gp/T/.tmpFbcNO0' is forbidden in restricted mode

This both fixes that and adds a test to make sure it can't happen again
2023-09-12 01:07:44 +02:00
Silvan Mosberger
ad61076624
Merge pull request #237439 from tweag/spp-1
[RFC 140] Simple package paths, part 1b: Enabling the directory structure
2023-09-05 16:25:27 +02:00
Silvan Mosberger
f6467c3574 pkgs/by-name: Introduce
This introduces the `pkgs/by-name` directory as proposed by RFC 140.
Included are:
- The implementation to add packages defined in that directory to the
  top-level package scope
- Contributer documentation on how to add packages to it
- A GitHub Actions workflow to check the structure of it on all PRs
2023-09-05 16:10:50 +02:00
Silvan Mosberger
d42ae665dc tests.nixpkgs-check-by-name: Cleaner testing
- Better filesystem case-sensitivity heuristic
  We shouldn't assume that Linux is always case-sensitive.
- Don't include case-sensitive filename in tree
  Was used for tests, but this broke channel updates because there's a
  check to make sure there's no case-sensitive files!

  https://hydra.nixos.org/build/233371356/nixlog/1
2023-08-29 23:36:47 +02:00
Silvan Mosberger
34c8b0a8e5 nixos/release-combined.nix: Build pkgs/by-name tester 2023-08-29 16:35:07 +02:00
Silvan Mosberger
271eb02995 pkgs/test/nixpkgs-check-by-name: init
Adds an internal CLI tool to verify Nixpkgs to conform to RFC 140.
See pkgs/test/nixpkgs-check-by-name/README.md for more information.
2023-08-29 16:17:54 +02:00