nixpkgs-suyu/nixos/lib
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
..
test-driver test-driver: support testing user units 2018-01-02 20:14:27 +01:00
build-vms.nix Use only one build of qemu in VM tests 2016-12-20 10:52:46 +01:00
eval-config.nix eval-config.nix: configuration->configuration.nix 2017-01-04 19:15:47 +01:00
from-env.nix
make-channel.nix Unify NixOS and Nixpkgs channel structure 2015-08-05 17:37:11 +02:00
make-disk-image.nix build-support/vm: Use devtmpfs, not static device nodes 2017-12-12 14:31:50 +02:00
make-ext4-fs.nix make-ext4-fs: Fix modification timestamps in image 2017-07-29 22:03:43 +03:00
make-iso9660-image.nix Combine ISO generation steps 2016-03-15 14:15:12 +01:00
make-iso9660-image.sh Combine ISO generation steps 2016-03-15 14:15:12 +01:00
make-squashfs.nix make-squashfs.nix: Improve invalid path check messages 2017-12-15 19:57:40 +02:00
make-system-tarball.nix
make-system-tarball.sh make-system-tarball.sh: use numeric uids 2017-01-01 06:03:05 +01:00
qemu-flags.nix
testing.nix nixos/testing: fix after --set ceased to evaluate the value 2017-11-19 14:15:19 +00:00
utils.nix nixos: generalize copy-paste from stage-1 and zfs to utils 2016-08-23 18:14:06 +00:00