nixpkgs/nixos/lib/test-driver
Maximilian Bosch e538e00404
test-driver: support testing user units
It is quite complicated to test services using the test-driver when
declaring user services with `systemd.user.services` such as many
X11-based services like `xautolock.service`.

This change adds an optional `$user` parameter to each systemd-related
function in the test-driver and runs `systemctl --user` commands using
`su -l $user -c ...` and sets the `XDG_RUNTIME_DIR` variable
accordingly and a new function named `systemctl` which is able to run a
systemd command with or without a specified user.

The change can be confirmed with a simple VM declaration like this:

```
import ./nixos/tests/make-test.nix ({ pkgs, lib }:

with lib;

{
  name = "systemd-user-test";

  nodes.machine = {
    imports = [ ./nixos/tests/common/user-account.nix ];

    services.xserver.enable = true;
    services.xserver.displayManager.auto.enable = true;
    services.xserver.displayManager.auto.user = "bob";
    services.xserver.xautolock.enable = true;
  };

  testScript = ''
    $machine->start;
    $machine->waitForX;

    $machine->waitForUnit("xautolock.service", "bob");
    $machine->stopJob("xautolock.service", "bob");
    $machine->startJob("xautolock.service", "bob");
    $machine->systemctl("list-jobs --no-pager", "bob");
    $machine->systemctl("show 'xautolock.service' --no-pager", "bob");
  '';
})
```
2018-01-02 20:14:27 +01:00
..
log2html.xsl nixos/test-reports: use local copy of jquery 2014-09-07 15:47:59 +02:00
logfile.css Move all of NixOS to nixos/ in preparation of the repository merge 2013-10-10 13:28:20 +02:00
Logger.pm nixos/test-driver/Logger: Replace invalid UTF-8 2016-05-26 14:24:33 +02:00
Machine.pm test-driver: support testing user units 2018-01-02 20:14:27 +01:00
test-driver.pl NixOS VM tests: Don't create a setgid group in vde_switch 2017-06-07 11:57:36 +02:00
treebits.js Move all of NixOS to nixos/ in preparation of the repository merge 2013-10-10 13:28:20 +02:00