[prev in list] [next in list] [prev in thread] [next in thread] 

List:       nix-dev
Subject:    Re: [Nix-dev] How to access makeTest function from nixpkgs/nixos/lib/testing.nix?
From:       Tomasz Czyż <tomasz.czyz () gmail ! com>
Date:       2016-06-23 0:43:16
Message-ID: CAO1Hmo7mS5kpAg=hnFoPBfiekGmftHUe4KwEUpw3GWArW7P-NA () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


2016-06-23 1:39 GMT+01:00 Maarten Hoogendoorn <maarten@moretea.nl>:

> Cool.
>
> For development environments, it is recommended to use the nix-shell
> program.
>
+1, I'm constantly forgetting about it.

> A good example is nixops (nixos/nixops on github).
>
> PS, I've added the list again.
>
Cheers :-)

Tom

> Op 23 jun. 2016 02:34 schreef "Tomasz Czyż" <tomasz.czyz@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@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@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@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@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@lists.science.uu.nl
>>>>>> http://lists.science.uu.nl/mailman/listinfo/nix-dev
>>>>>>
>>>>>>
>>>>>
>>>>
>>>>
>>>> --
>>>> Tomasz Czyż
>>>>
>>>
>>
>>
>> --
>> Tomasz Czyż
>>
>


-- 
Tomasz Czyż

[Attachment #5 (text/html)]

<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">2016-06-23 \
1:39 GMT+01:00 Maarten Hoogendoorn <span dir="ltr">&lt;<a \
href="mailto:maarten@moretea.nl" \
target="_blank">maarten@moretea.nl</a>&gt;</span>:<br><blockquote class="gmail_quote" \
style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p \
dir="ltr">Cool.</p> <p dir="ltr">For development environments, it is recommended to \
use the nix-shell program.</p></blockquote><div>+1, I&#39;m constantly forgetting \
about it.  </div><blockquote class="gmail_quote" style="margin:0 0 0 \
.8ex;border-left:1px #ccc solid;padding-left:1ex"> <p dir="ltr">A good example is \
nixops (nixos/nixops on github).</p> <p dir="ltr">PS, I&#39;ve added the list \
again.</p></blockquote><div>Cheers :-)</div><div><br></div><div>Tom  \
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex"> <div class="gmail_quote">Op 23 jun. 2016 02:34 schreef \
&quot;Tomasz Czyż&quot; &lt;<a href="mailto:tomasz.czyz@gmail.com" \
target="_blank">tomasz.czyz@gmail.com</a>&gt;:<div><div class="h5"><br \
type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 \
.8ex;border-left:1px #ccc solid;padding-left:1ex"><div \
dir="ltr">Maarten,<div><br></div><div>thank you for showing this, I definitely \
omitted this part, now I see how you set NIX_PATH in \
test.sh.</div><div><br></div><div>I think this approach is fine, and I&#39;ll use \
that solution if I won&#39;t figure out better way.</div><div><br></div><div>I have \
tree like that:</div><div>./nixpkgs.nix   # this stuff is importing specific nixpkgs \
commit</div><div>./app1</div><div>./app2</div><div>./app3</div><div>./tests</div><div><br></div><div>each \
app is importing &quot;../nixpkgs.nix&quot; separately and tests are importing it as \
well so all separately are using same nix version \
&quot;internally&quot;.</div><div><br></div><div>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.  </div><div><br></div><div>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&#39;ll go this route if I have no other \
options.</div><div><br></div><div>Right now with small workaround I described in \
previous post all stuff is working without any other \
setup.</div><div><br></div><div>1. Clone the repo</div><div>2. nix-build in every \
directory you want</div></div><div class="gmail_extra"><br><div \
class="gmail_quote">2016-06-23 1:23 GMT+01:00 Maarten Hoogendoorn <span \
dir="ltr">&lt;<a href="mailto:maarten@moretea.nl" \
target="_blank">maarten@moretea.nl</a>&gt;</span>:<br><blockquote class="gmail_quote" \
style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p \
dir="ltr">You could set the nixpkgs path with the -I option, or as I do, with a shell \
variable.<br> Point it to your fork of nixpkgs, and you&#39;re done.</p>
<p dir="ltr">Alternatively, there is some overridePackage(s?) function that might \
interest you. (I myself should look at in detail as well ;))</p> <div \
class="gmail_quote">Op 23 jun. 2016 02:19 schreef &quot;Tomasz Czyż&quot; &lt;<a \
href="mailto:tomasz.czyz@gmail.com" \
target="_blank">tomasz.czyz@gmail.com</a>&gt;:<div><div><br \
type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 \
.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Maarten,  \
<div><br></div><div>thank you for sharing your work.</div><div><br></div><div>I think \
you are using approach with &quot;import &lt;nixpkgs&gt;&quot; and not overriden pkgs \
inside testing config/machine - which I prefer to avoid, because I want to have bound \
nixpkgs version, I don&#39;t want to use &quot;system&quot; version. (maybe I&#39;m \
missing some piece, in that case please point it out).</div><div><br></div><div>In \
the meantime I found, that I can pass/override pinned pkgs inside config/machine \
description with a little trick.</div><div><br></div><div><div>   import \
&lt;nixpkgs/nixos/tests/make-test.nix&gt; ({</div><div>      machine = \
{config,pkgs,...}: {</div><div>         _module.args.pkgs = my-nixpkgs;   # this \
trick overrides pkgs argument for all modules</div><div>         imports = \
[</div><div>               ... my modules...</div><div>         \
];</div><div><br></div><div>      };</div><div>      testScript=&#39;&#39;</div><div> \
...</div><div>      &#39;&#39;;</div><div>   \
})</div></div><div><br></div><div><br></div><div>I would prefer to not use this \
method as probably &quot;pkgs&quot; argument can &quot;leak&quot; in some places (the \
other version of nixpkgs can be used and I will not detect this easily). But \
that&#39;s the best I have so far.</div><div><br></div><div><br></div></div><div \
class="gmail_extra"><br><div class="gmail_quote">2016-06-23 1:10 GMT+01:00 Maarten \
Hoogendoorn <span dir="ltr">&lt;<a href="mailto:maarten@moretea.nl" \
target="_blank">maarten@moretea.nl</a>&gt;</span>:<br><blockquote class="gmail_quote" \
style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div \
dir="ltr">Hi Tomasz,<div><br></div><div>Some weeks ago, I looked into this to run zfs \
integration tests for a rust binding to libzfs.</div><div><br></div><div>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&#39;d \
rather not destroy my main pool by accident ;)</div><div><br></div><div>Good luck, \
and let me know if this helps you out \
:)</div><div>Maarten</div><div><br></div><div>[1] <a \
href="https://github.com/moretea/rust-zfs" \
target="_blank">https://github.com/moretea/rust-zfs</a></div></div><div \
class="gmail_extra"><br><div class="gmail_quote"><div><div>2016-06-23 1:23 GMT+02:00 \
Tomasz Czyż <span dir="ltr">&lt;<a href="mailto:tomasz.czyz@gmail.com" \
target="_blank">tomasz.czyz@gmail.com</a>&gt;</span>:<br></div></div><blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex"><div><div><div dir="ltr">Hello,<div><br></div><div>I found \
makeTest function from nixos useful and I would like to use it in my projects for \
building integration testing environments.</div><div><br></div><div>The only method I \
found by now, how to access it is:</div><div><br></div><div>(import \
&lt;nixpkgs/nixos/lib/testing.nix&gt;).makeTest</div><div><br></div><div>The problem \
is: in the script I&#39;m running, the fixed nixpkgs version is passed as \
&quot;pkgs&quot; argument. The script must test programs against that specific \
nixpkgs version.</div><div><br></div><div>I see two options:</div><div>1. grab \
makeTest command from pinned nixpkgs</div><div>2. grab makeTest from &lt;nixpkgs&gt; \
and pass pinned nixpkgs as argument to makeTest (and further to \
machine/nodes).</div><div><br></div><div>1. I couldn&#39;t find the attribute which \
is pointing to that function or file, if looks like I can access it only using path \
syntax like &lt;nixpkgs/nixos/lib/testing.nix&gt;. Is there any way to get path for \
current &quot;pkgs&quot; set? Or are there any other ways how I can access this \
file/function?</div><div><br></div><div>2. I didn&#39;t find any way to pass pkgs \
argument down the stack, looks like other funtions inside makeTest are just importing \
pkgs from &quot;local&quot; files so probably this way won&#39;t \
work.</div><div><br></div><div>3. I could copy the files and bind them to attributes \
but I prefer to avoid that if possible.</div><div><br></div><div>If anyone have some \
suggestions please let me know.</div><div><br></div><div>Tom</div><span><font \
color="#888888"><div><div><br></div>-- <br><div \
data-smartmail="gmail_signature">Tomasz Czyż</div> </div></font></span></div>
<br></div></div>_______________________________________________<br>
nix-dev mailing list<br>
<a href="mailto:nix-dev@lists.science.uu.nl" \
target="_blank">nix-dev@lists.science.uu.nl</a><br> <a \
href="http://lists.science.uu.nl/mailman/listinfo/nix-dev" rel="noreferrer" \
target="_blank">http://lists.science.uu.nl/mailman/listinfo/nix-dev</a><br> \
<br></blockquote></div><br></div> </blockquote></div><br><br \
clear="all"><div><br></div>-- <br><div data-smartmail="gmail_signature">Tomasz \
Czyż</div> </div>
</blockquote></div></div></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div \
data-smartmail="gmail_signature">Tomasz Czyż</div> </div>
</blockquote></div></div></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div \
class="gmail_signature" data-smartmail="gmail_signature">Tomasz Czyż</div> \
</div></div>



_______________________________________________
nix-dev mailing list
nix-dev@lists.science.uu.nl
http://lists.science.uu.nl/mailman/listinfo/nix-dev


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic