nixpkgs/nixos
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
..
doc/manual nixos/logstash: Listen on 127.0.0.1 instead of 0.0.0.0 2017-12-09 11:32:14 +01:00
lib test-driver: support testing user units 2018-01-02 20:14:27 +01:00
maintainers amazon-image: make derivation name configurable 2017-10-23 16:22:24 -04:00
modules Merge pull request #32578 from michaelpj/imp/plymouth-theme-defaut 2017-12-15 20:20:24 +00:00
tests Merge pull request #32637 from makefu/pkgs/openstack/nuke 2017-12-15 10:06:23 -08:00
COPYING
default.nix Remove nixFallback 2017-03-06 15:54:50 +01:00
README
release-combined.nix Merge pull request #31805 from gleber/make-switch-to-configuration-pure 2017-11-19 19:03:52 +00:00
release-small.nix php: pcre test blocks -small channels as well 2017-11-12 11:03:54 +01:00
release.nix glance: rip 2017-12-15 16:08:10 +01:00

*** NixOS ***

NixOS is a Linux distribution based on the purely functional package
management system Nix.  More information can be found at
http://nixos.org/nixos and in the manual in doc/manual.