Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testVersion: automatically detect package #190577

Open
davidak opened this issue Sep 9, 2022 · 3 comments
Open

testVersion: automatically detect package #190577

davidak opened this issue Sep 9, 2022 · 3 comments
Labels
0.kind: enhancement Add something new

Comments

@davidak
Copy link
Member

davidak commented Sep 9, 2022

Issue description

Currently the package name has to be set manually every time.

It would be great if testVersion can detect it somehow, so you don't have to repeat it (DRY).

Then a minimal config. looks like this:

 passthru.tests.version = testers.testVersion {}; 

There are some packages in nixpkgs that use some form where they don't have to write the package name, but my naive approach to just copy it to testVersions code does not work.

passthru.tests.version = testers.testVersion { inherit package; };

passthru.tests.version = testers.testVersion {
package = finalAttrs.finalPackage;
command = "${xvfb-run}/bin/xvfb-run swaync --version";
};

As described in https://nixos.org/manual/nixpkgs/stable/#var-meta-tests.

passthru.tests.version = testers.testVersion {
package = self;
version = "v${version}";
};

cc @raboof @roberth @0x4A6F @Artturin

Is there any chance this is possible with Nix?

@davidak davidak added the 0.kind: enhancement Add something new label Sep 9, 2022
@roberth
Copy link
Member

roberth commented Sep 10, 2022

passthru.tests.version = testers.testVersion {};

The purpose of passthru is to humbly set attributes on the package attrset, so unless we change it to do something it wasn't designed to do, it shouldn't work, because the expression testers.testVersion {} has no reference to the package.

I can imagine a module-system-like module that can express your intent even more concisely, but for now we don't have such a feature in mkDerivation.

@davidak
Copy link
Member Author

davidak commented Sep 10, 2022

Thanks for the response.

because the expression testers.testVersion {} has no reference to the package.

When thinking naively without knowing anything about Nix internals, i think Nix can be able to know for which package a test is when you run them with nix build .#vapoursynth.tests.version. Also, the code is in the same file and even code block as the package. I think it should be possible somehow technically, but maybe not with the current architecture.

The architecture should enable us to write readable, elegant and short code and not limit us in that goal.

@roberth
Copy link
Member

roberth commented Sep 11, 2022

I agree with the ambition that it should be simple to specify a test, but by removing the need for inherit finalPackage, you move the complexity from the package, where it can be easily understood, into the interface, where it is magical.

This is why I brought up module style composition, as a different kind of interface that better supports the kind of logic you want.

The architecture should enable us to write readable, elegant and short code and not limit us in that goal.

Decent goals that need to be balanced by the same goals at the other side of the interface.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.kind: enhancement Add something new
Projects
None yet
Development

No branches or pull requests

2 participants