Interactively connecting to NixOS prometheus exporter tests

I managed to solve my problems on my own but ended up having written this post in the process. So I thought I would leave it here for posterity. If this is a bad place to post it and I should just get myself a blog I’ll take it down.

The NixOS manual describes how one goes about interactively running the login test:

$ nix-build nixos/tests/login.nix -A driver
$ ./result/bin/nixos-test-driver

And that works fine on my machine, both the nix-build invocation and running nixos-test-driver. Doing the same for prometheus-exporters.nix does not work:

$ nix-build  nixos/tests/prometheus-exporters.nix -A driver
error: attribute 'driver' in selection path 'driver' not found

The suggests running nix repl followed by driver.outPath:

$ nix repl  nixos/tests/prometheus-exporters.nix
> driver.outPath
error: undefined variable 'driver' at (string):1:1

Again the driver attribute seems to be missing. But this got me thinking “Perhaps each test inside this file has a separate driver” and wouldn’t you know it, such was the case:

> slurm.driver.outPath

And in that folder I could find bin/nixos-test-driver. Running it I could then run things like print(slurm.succeed("ls -l /")) to inspect the contents of the VM.

I hope this can become useful for someone in the future.


Thanks a lot for posting it here! Instead of a blog the NixOS wiki is probably the best place for that information :slight_smile: It’s where others will find it the easiest way