[Nix-dev] How to access makeTest function from nixpkgs/nixos/lib/testing.nix?

Maarten Hoogendoorn maarten at moretea.nl
Thu Jun 23 02:39:44 CEST 2016


Cool.

For development environments, it is recommended to use the nix-shell
program.

A good example is nixops (nixos/nixops on github).

PS, I've added the list again.
Op 23 jun. 2016 02:34 schreef "Tomasz Czyż" <tomasz.czyz at gmail.com>:

> Maarten,
>
> thank you for showing this, I definitely omitted this part, now I see how
> you set NIX_PATH in test.sh.
>
> I think this approach is fine, and I'll use that solution if I won't
> figure out better way.
>
> I have tree like that:
> ./nixpkgs.nix  # this stuff is importing specific nixpkgs commit
> ./app1
> ./app2
> ./app3
> ./tests
>
> each app is importing "../nixpkgs.nix" separately and tests are importing
> it as well so all separately are using same nix version "internally".
>
> By avoiding wrapper I can go to every directory and run nix-build and it
> will work and app will be bound to specific nixpkgs version.
>
> Another solution would be, as you pointed, setting -I / NIX_PATH, but this
> is another manual step that needs to be done. You have to add this to
> .profile (but this is not project specific :[) or you have to set this in
> every terminal you are working in, or figure out other way to set up this.
> I'll go this route if I have no other options.
>
> Right now with small workaround I described in previous post all stuff is
> working without any other setup.
>
> 1. Clone the repo
> 2. nix-build in every directory you want
>
> 2016-06-23 1:23 GMT+01:00 Maarten Hoogendoorn <maarten at moretea.nl>:
>
>> You could set the nixpkgs path with the -I option, or as I do, with a
>> shell variable.
>> Point it to your fork of nixpkgs, and you're done.
>>
>> Alternatively, there is some overridePackage(s?) function that might
>> interest you. (I myself should look at in detail as well ;))
>> Op 23 jun. 2016 02:19 schreef "Tomasz Czyż" <tomasz.czyz at gmail.com>:
>>
>> Maarten,
>>>
>>> thank you for sharing your work.
>>>
>>> I think you are using approach with "import <nixpkgs>" and not overriden
>>> pkgs inside testing config/machine - which I prefer to avoid, because I
>>> want to have bound nixpkgs version, I don't want to use "system" version.
>>> (maybe I'm missing some piece, in that case please point it out).
>>>
>>> In the meantime I found, that I can pass/override pinned pkgs inside
>>> config/machine description with a little trick.
>>>
>>>   import <nixpkgs/nixos/tests/make-test.nix> ({
>>>     machine = {config,pkgs,...}: {
>>>       _module.args.pkgs = my-nixpkgs;  # this trick overrides pkgs
>>> argument for all modules
>>>       imports = [
>>>           ... my modules...
>>>       ];
>>>
>>>     };
>>>     testScript=''
>>>         ...
>>>     '';
>>>   })
>>>
>>>
>>> I would prefer to not use this method as probably "pkgs" argument can
>>> "leak" in some places (the other version of nixpkgs can be used and I will
>>> not detect this easily). But that's the best I have so far.
>>>
>>>
>>>
>>> 2016-06-23 1:10 GMT+01:00 Maarten Hoogendoorn <maarten at moretea.nl>:
>>>
>>>> Hi Tomasz,
>>>>
>>>> Some weeks ago, I looked into this to run zfs integration tests for a
>>>> rust binding to libzfs.
>>>>
>>>> The GitHub repository [1] is set up to run a qemu vm on Travis, so that
>>>> my tests can run with a kernel that supports zfs. It also provides some
>>>> isolation during development. I'd rather not destroy my main pool by
>>>> accident ;)
>>>>
>>>> Good luck, and let me know if this helps you out :)
>>>> Maarten
>>>>
>>>> [1] https://github.com/moretea/rust-zfs
>>>>
>>>> 2016-06-23 1:23 GMT+02:00 Tomasz Czyż <tomasz.czyz at gmail.com>:
>>>>
>>>>> Hello,
>>>>>
>>>>> I found makeTest function from nixos useful and I would like to use it
>>>>> in my projects for building integration testing environments.
>>>>>
>>>>> The only method I found by now, how to access it is:
>>>>>
>>>>> (import <nixpkgs/nixos/lib/testing.nix>).makeTest
>>>>>
>>>>> The problem is: in the script I'm running, the fixed nixpkgs version
>>>>> is passed as "pkgs" argument. The script must test programs against that
>>>>> specific nixpkgs version.
>>>>>
>>>>> I see two options:
>>>>> 1. grab makeTest command from pinned nixpkgs
>>>>> 2. grab makeTest from <nixpkgs> and pass pinned nixpkgs as argument to
>>>>> makeTest (and further to machine/nodes).
>>>>>
>>>>> 1. I couldn't find the attribute which is pointing to that function or
>>>>> file, if looks like I can access it only using path syntax like
>>>>> <nixpkgs/nixos/lib/testing.nix>. Is there any way to get path for current
>>>>> "pkgs" set? Or are there any other ways how I can access this file/function?
>>>>>
>>>>> 2. I didn't find any way to pass pkgs argument down the stack, looks
>>>>> like other funtions inside makeTest are just importing pkgs from "local"
>>>>> files so probably this way won't work.
>>>>>
>>>>> 3. I could copy the files and bind them to attributes but I prefer to
>>>>> avoid that if possible.
>>>>>
>>>>> If anyone have some suggestions please let me know.
>>>>>
>>>>> Tom
>>>>>
>>>>> --
>>>>> Tomasz Czyż
>>>>>
>>>>> _______________________________________________
>>>>> nix-dev mailing list
>>>>> nix-dev at lists.science.uu.nl
>>>>> http://lists.science.uu.nl/mailman/listinfo/nix-dev
>>>>>
>>>>>
>>>>
>>>
>>>
>>> --
>>> Tomasz Czyż
>>>
>>
>
>
> --
> Tomasz Czyż
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.science.uu.nl/pipermail/nix-dev/attachments/20160623/2d3d4280/attachment.html>


More information about the nix-dev mailing list